Bob's Game

4.2

4 votes
Arrays
Problem

Bob has n bowls numbered 1 to n in his room placed in straight line containing marbles.

He decided to play with them so he chose the bowl with number y and took out all the marbles. He then decided to put the marbles one at a time from left to right in boxes with numbers y+1, y+2, y+3 and so on. If he reaches the end of the line that is if he reaches the bowl numbered n and still has some marbles left he again starts with bowl numbered 1 then 2, 3 and so on till he is left with zero marbles.

Everytime he does this, he forgets which bowl he begin with but he remembers which bowl he ended up with. He also remembers the arrangement.

Help Bob to determine the original arrangement of marbles in the bowls before the game began.

NOTE: Finally all the bowls contain distinct number of marbles. Bob plays this game only once.

Input Format

First line contains integers n(the number of bowls) and p(the last bowl in which he added the marble). The next line contains n space seperated integers a1, a2, ..., an where each ai denotes the number of marbles in the bowl with number i after the game has ended.

Constraints

2 ≤ n ≤ 10^5, 1 ≤ p ≤ n

0 ≤ ai ≤ 10^9, ap ≠ 0

Output Format

Print n space seperated integers, where ith integer denotes the number of marbles in the bowl number i before the game begin.

Sample Input
6 2
10 8 7 4 11 16
Sample Output
5 3 3 28 6 11 
Time Limit: 1
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?