Chat in Telegram

Find all combinations of given length

MEDIUM

Given a string of unique (non-repeating) numbers separated by a single space (elements).
The next line contains the number of elements in the combination (k).
1 ≤ k ≤ count of elements

Find all combinations of given length. Print it in any order.

Example #1

Input

1 2 3
2

Output

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

Solution