N and M (12)

Given N numbers and a length M, list all non-decreasing length-M sequences drawn from the numbers with repetition, in lexicographic order.

Medium4BacktrackingSortingRecursionImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given NN natural numbers and a natural number MM. Write a program that finds every sequence of length MM satisfying all of the conditions below.

  • The sequence is made by choosing MM of the given NN numbers.
  • You may choose the same number more than once.
  • The sequence is non-decreasing. A sequence AA of length KK is non-decreasing when A1A2AK1AKA_1 \le A_2 \le \cdots \le A_{K-1} \le A_K holds.

Input

The first line contains NN and MM. (1MN81 \le M \le N \le 8)

The second line contains NN numbers. Every number given in the input is a natural number no greater than 10,000.

Output

Print one sequence that satisfies the conditions per line. Do not print the same sequence more than once, and separate the numbers of a sequence with a space.

Print the sequences in increasing lexicographic order.