Under construction

Still being built. Things may change

Rotate and Shift

Time limit4sMemory limit1024 MB

Summary
Given N cows on a circle and K active positions that rotate their cows and then shift forward by one each minute, output the final cow order after T minutes.
Level

Medium7 of 10

Topics
Math, Array, Simulation
Solved
No attempts yet

Problem

To celebrate the start of spring, Farmer John's NN cows (1≤N≤2⋅1051 \leq N \leq 2 \cdot 10^5) have invented a new dance. The cows stand in a circle and reorder themselves in a predictable way.

There are NN positions around the circle, numbered from 00 to N−1N-1, with position 00 following position N−1N-1. Each position holds one cow, and the cows are also numbered from 00 to N−1N-1. Initially, cow ii is in position ii. A set of KK positions 0=A1<A2<…<AK<N0=A_1<A_2<\ldots<A_K<N is marked as active (1≤K≤N1 \leq K \leq N). The cows in the active positions move next.

Each minute, two things happen. First, the cows in the active positions rotate: the cow at A1A_1 moves to A2A_2, the cow at A2A_2 moves to A3A_3, and so on, and the cow at AKA_K moves to A1A_1. All KK moves happen at the same time, so every active position still holds exactly one cow afterward. Second, the active positions shift: A1A_1 becomes A1+1A_1+1, A2A_2 becomes A2+1A_2+1, and so on. If an active position is N−1N-1, it wraps around to 00.

Input

The first line contains three integers NN, KK, and TT.

The second line contains KK integers A1,A2,…,AKA_1, A_2, \ldots, A_K, the initial set of active positions. Recall that A1=0A_1 = 0 and that these are given in increasing order.

Output

Output the order of the cows after TT minutes, starting with the cow in position 00, separated by spaces.

Examples1

  1. Example 1

    Input
    5 3 4
    0 2 3
    
    Expected output
    1 2 3 4 0