#K79272. Lexicographical Permutations

    ID: 35272 Type: Default 1000ms 256MiB

Lexicographical Permutations

Lexicographical Permutations

Given two integers (n) and (m), generate and output all length-(m) sequences where each element is an integer between (1) and (n) (inclusive), with repetition allowed. The sequences should be printed in lexicographically sorted order. Each sequence is printed as space-separated numbers on a new line. This means that for any valid sequence (a_1, a_2, \dots, a_m), each (a_i) satisfies (1 \leq a_i \leq n), and all (n^m) possible sequences must be enumerated in increasing order when compared lexicographically.

inputFormat

The input consists of a single line containing two space-separated integers (n) and (m) ((1 \le n, m \le 10)).

outputFormat

Output all possible sequences of length (m) in lexicographically sorted order. Each sequence should be printed on a separate line with the numbers separated by a single space.## sample

3 2
1 1

1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3

</p>