Under construction

Still being built. Things may change

N and M (6)

Interview

Time limit1sMemory limit512 MB

Summary
Given N distinct natural numbers and M, print every ascending M-element subsequence in lexicographic order without repeats.
Level

Easy3 of 10

Topics
Backtracking, Sorting, Recursion, Brute force
Solved
No attempts yet

Problem

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

  • the sequence consists of MM numbers chosen from the given NN natural numbers
  • the chosen sequence is in ascending order

Input

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

The second line contains NN numbers. Every number given in the input is a natural number less than or equal to 10,000.

Output

Print one sequence that satisfies the conditions per line. Do not print the same sequence twice, and separate the elements of each sequence with a space.

Print the sequences in increasing lexicographic order.

Examples3

  1. Example 1

    Input
    3 1
    4 5 2
    
    Expected output
    2
    4
    5
    
  2. Example 2

    Input
    4 2
    9 8 7 1
    
    Expected output
    1 7
    1 8
    1 9
    7 8
    7 9
    8 9
    
  3. Example 3

    Input
    4 4
    1231 1232 1233 1234
    
    Expected output
    1231 1232 1233 1234