Question
Magical Tile Permutations
Imagine nums as a set of magical tiles, each showing a unique number. You are given a number k, which tells you how long each sequence should be.
To create a sequence, you pick k tiles in order. Because the tiles are magical, you can use the same tile again and again if you want.
Your task is to list all possible sequences of length k that can be formed using the tiles in nums, with repetition allowed. The sequences can be in any order.
Input
The first line of input contains two integers: n and k.
The second line contains n space-separated integers representing the elements of the array nums.
The second line contains n space-separated integers representing the elements of the array nums.
Output
Print all permutations of length k using the elements from nums. Elements may be repeated.
Print each permutation on a new line.
Print each permutation on a new line.
Example
Input:
3 2
1 2 3
Output:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
3 2
1 2 3
Output:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3