Page not loading? Try clicking here.
Placeholder

#2817

Lotto 1s 128MB

Problems

In Lotto, you must choose 6 numbers from the set {1, 2, 3, …, 48, 49}.

There are many strategies for choosing Lotto numbers, but here we assume that K numbers (6 < K < 13) have already been selected, and we want to generate all possible Lotto number sets that can be formed from these selected numbers.

For example, when K = 8 and the selected set is

S = {1, 2, 3, 5, 8, 13, 21, 34},

the possible Lotto combinations are:

[1, 2, 3, 5, 8, 13],

[1, 2, 3, 5, 8, 21],

[1, 2, 3, 5, 8, 34],

[1, 2, 3, 5, 13, 21],

[3, 5, 8, 13, 21, 34],

for a total of 28 combinations.

Write a program that, given K and the K selected numbers, prints all possible Lotto number combinations.


Input

A single line of integers is given.

The first number is K (6 < K < 13).

Following that, K natural numbers Sᵢ (1 ≤ Sᵢ ≤ 49) are given in ascending order.


Output

Print all possible Lotto number combinations that can be formed using the given K numbers.

Each combination must contain 6 numbers, and:

  • The 6 numbers within each line must be in ascending order.

  • The combinations themselves must also be printed in ascending order, one per line.


Example

7 1 2 3 4 5 6 7
1 2 3 4 5 6

1 2 3 4 5 7
1 2 3 4 6 7
1 2 3 5 6 7
1 2 4 5 6 7
1 3 4 5 6 7
2 3 4 5 6 7


Source

University of Ulm Local Contest 1996 F번

You must sign in to write code.