Page not loading? Try clicking here.
Placeholder

#1169

Roll a Die 1 1s 32MB

Problems

Given the number of times N that a die is rolled and the output format type, write a program that outputs results according to the value of type as follows.

  • type = 1 : Print all possible outcomes when rolling a die N times.

  • type = 2 : Print all possible outcomes when rolling a die N times, excluding duplicate cases.

  • type = 3 : Print all possible outcomes when rolling a die N times where all numbers are different.

Examples of duplicates

  • 1 1 2 is considered a duplicate of: 1 2 1, 2 1 1

  • 1 2 3 is considered a duplicate of: 1 3 2, 2 1 3, 2 3 1, 3 1 2


Input

The first line contains the number of die rolls N (2 ≤ N ≤ 5) and the output format type (1 ≤ type ≤ 3).


Output

Output the cases for rolling a die N times according to the specified type. Print in order starting from smaller numbers.


Example #1

3 1
1 1 1

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

6 6 6

Example #2

3 2
1 1 1

1 1 2

1 1 6
1 2 2

5 6 6
6 6 6

Example #3

3 3
1 2 3

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

6 5 3
6 5 4


Source

JUNGOL

You must sign in to write code.