Two rows of numbers P83712


Statement
 

pdf   zip

You have 2n2n different numbers. Write a program to find all the ways to put the numbers in two rows x1xnx_1 \dots x_n and y1yny_1 \dots y_n so that:

  • x1<x2<<xn1<xnx_1 < x_2 < \dots < x_{n-1} < x_n ,

  • y1<y2<<yn1<yny_1 < y_2 < \dots < y_{n-1} < y_n ,

  • for every ii, it holds xi<yix_i < y_i.

Input

Input consists of nn, followed by 2n2n different integer numbers. Assume 1n111 \le n \le 11.

Output

Print all the ways to put the numbers fulfilling the required conditions. For every way, print three lines: two rows with xix_i and yiy_i separated by spaces, and an empty line. Print the solutions in lexicographical order: first, those with the smaller x1x_1, in case of a tie, those with the smaller x2x_2, …, in case of a tie, those with the smaller xnx_n, in case of a tie, those with the smaller y1y_1, …

Public test cases
  • Input

    3
    1 2 3 4 5 6
    

    Output

    1 2 3
    4 5 6
    
    1 2 4
    3 5 6
    
    1 2 5
    3 4 6
    
    1 3 4
    2 5 6
    
    1 3 5
    2 4 6
    
    
  • Input

    1
    0 -200
    

    Output

    -200
    0
    
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python