## TSOC '16 Contest 1 #5 - Max and Cards

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

Max is a magician whose job is to shuffle magic cards and confuse innocent bystanders. He uses a special deck with cards, labelled from to . Suddenly, he throws his hands up in the air and the cards fall back down in sorted order (from least to greatest). He then quickly swipes his hands over the cards and forms all possible permutations from lexicographically least to greatest ordered from to . For example, if then he would have made the permutations:

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

Afterwards, Max asks you questions in the form of what was the permutation that Max made. Since your tiny eyes were too slow to see Max's amazing trick, you try using your old Pentium 4 computer to recreate Max's magic, but can you do it fast enough?

#### Input Specification

The first line will contain .
The second line will contain .
The next lines will contain .

#### Output Specification

For each question, output the permutation on its own line.

#### Scoring

At least 50% of the test cases will have .

3
6
5
4
3
2
1
0

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