Under construction

Still being built. Things may change

Inverted Josephus

Interview

Time limit1sMemory limit1024 MB

Summary
Simulate removing every K-th person from a circle of N, reversing direction after each block of M removals, and print the removal order.
Level

Medium4 of 10

Topics
Simulation, Array, Linked list, Implementation
Solved
No attempts yet

Problem

The Josephus problem goes as follows.

Person 22 sits to the right of person 11, person 33 sits to the right of person 22, and in the same way NN people sit in a circle. Person 11 sits to the right of person NN. First, person KK (≤N\leq N) is removed, and after that the KK-th person to the right of the person removed just before is removed repeatedly. When everyone has been removed, in what order are the people removed?

The answer to this problem is called the (N\boldsymbol{N}, K\boldsymbol{K})-Josephus permutation, and the (77, 33)-Josephus permutation is <3,6,2,7,5,1,4>\left<3, 6, 2, 7, 5, 1, 4\right>.

Going around in only one direction the whole time is too boring, though. So to make the Josephus problem more interesting, the direction of rotation reverses every time MM people have been removed. The answer to this newly defined problem is called the (N\boldsymbol{N}, K\boldsymbol{K}, M\boldsymbol{M})-inverted Josephus permutation, and the (77, 33, 44)-inverted Josephus permutation is <3,6,2,7,1,5,4>\left<3, 6, 2, 7, \mathbf{1}, \mathbf{5}, \mathbf{4}\right>.

Given NN, KK, and MM, compute the (NN, KK, MM)-inverted Josephus permutation.

Input

The first line gives the integers NN, KK, and MM. (1≤N≤5 0001 \leq N \leq 5\ 000, 1≤K,M≤N1 \leq K, M \leq N)

Output

Print the numbers of the (NN, KK, MM)-inverted Josephus permutation in order, one per line.

Examples1

  1. Example 1

    Input
    7 3 4
    
    Expected output
    3
    6
    2
    7
    1
    5
    4