criptare
Zaharel and Bronzarel often have encryption challenges amongst themselves. This time, Zaharel encrypted a sequence of N non-negative integers a0, a1, ...,aN-1 as follows: he took a non-negative integer M and built the following sequence: bi = ai+a(i+1) mod N+a(i+2) mod N+...+a(i+M-1) mod N; then he asked Bronzarel if he can determine the initial sequence a0, a1, ..., aN-1 if he is given this new sequence as well as number M.
Task
Write a program that helps out Bronzarel.
Input Data
Line one of input file criptare.in contains the two positive integers, N M, separated by a single space. The next line contains N non-negative integers each separated by a single space, representing the sequence b0, b1, ..., bN-1.
Output Data
Output file criptare.out will contain a single line with N non-negative integers separated by a single space, representing the sequence a0, a1, ..., aN-1. Although there can be multiple solutions, Bronzarel knows that the sequence encrypted by Zaharel is the lexicographical minimum solution.
Restrictions
1 <= M, N <= 50000
0 <= bi <= 109
By a mod b we understand the
remainder of a's division to
b
The existence of at least one solution is guaranteed.
The sequence a0, a1,
..., aN-1 must contain non-negative integers (not
necessarily non-zero).
Examples
criptare.in |
criptare.out | criptare.in |
criptare.out |
3 2 3 5 4 |
1 2 3 | 6 4 8 13 11 13 17 10 |
2 5 0 1 7 3 |
Time limit: 0.1 seconds/test
Mircea Paşoi
University of Bucharest, Mathematics & IT Department
bogdanpasoi@yahoo.com