You have decided to implement a program that shuffles N cards. Each of the N cards contains one integer from 1 to N, without duplicates. Initially, the card with integer i (1 ≤ i ≤ N) is the i-th card from the top. That is, the card with 1 is at the top, the card with 2 is second from the top, ..., the card with N is at the bottom, and so on. N) are placed at the bottom of the stack. This time, the cards are shuffled in the following way The stacked cards are divided into sets of M cards from the top. However, if the bottom set has less than M cards, it remains less than M. The cards are divided into sets of M cards from the top. The cards are rearranged so that the i-th set from the top (1 ≤ i ≤ M) is the i-th set from the bottom. That is, after separating them into their respective sets, the top set is the bottom, the second set from the top is the second from the bottom, ..., and so on. The second set from the top is the second from the bottom, ..., and the bottom set is the top. This operation is called a single shuffle. To shuffle again, repeat the same operation from the previous shuffled state. Output the order of the cards after shuffling K times. Input example 1 is shown below. Since N = 9, there are 9 cards. M = 3, so the cards are divided into sets of 3 cards each. Rearrange each set in the manner described above. This time, K = 1, so the shuffling is complete. Input values Input is given in the following format N M K The number of cards is given as an integer N, the number of cards per set as an integer M, and the number of shuffles as an integer K, in this order, separated by spaces. The input is on a single line, with a single newline at the end. Expected output Output the cards after shuffling K times in the following format, from top to bottom c_1 c_2 .... c_N The expected output consists of N lines. Each i-th line (1 ≤ i ≤ N) should contain c_i, the number of the i-th card from the top after shuffling. All output must be integers. The last line of output must end with a newline and must not contain any extra characters or blank lines.
import sys def input(): return sys.stdin.readline().rstrip() def main(): n, m, k = map(int, input().split()) c =  for i in range(n): c.append(int(input())) for j in range(k): c = shuffle(c, n, m) for i in range(n): print(c[i]) def shuffle(c, n, m): k = n // m for i in range(m): c[i::m] = reversed(c[i::m]) return c if __name__ == '__main__': main()