CodeForces - 260C

Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.

Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting balls (one at a time) to the boxes with numbers i + 1, i + 2, i + 3 and so on. If Vasya puts a ball into the box number n, then the next ball goes to box 1, the next one goes to box 2 and so on. He did it until he had no balls left in his hands. It is possible that Vasya puts multiple balls to the same box, and it is also possible that one or more balls will go to the box number i. If i = n, Vasya puts the first ball into the box number 1, then the next ball goes to box 2 and so on.

For example, let's suppose that initially Vasya had four boxes, and the first box had 3 balls, the second one had 2, the third one had 5 and the fourth one had 4balls. Then, if i = 3, then Vasya will take all five balls out of the third box and put them in the boxes with numbers: 4, 1, 2, 3, 4. After all Vasya's actions the balls will lie in the boxes as follows: in the first box there are 4 balls, 3 in the second one, 1 in the third one and 6 in the fourth one.

At this point Vasya has completely forgotten the original arrangement of the balls in the boxes, but he knows how they are arranged now, and the number x — the number of the box, where he put the last of the taken out balls.

He asks you to help to find the initial arrangement of the balls in the boxes.

Input

The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents the number of balls in the box with index i after Vasya completes all the actions.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.

Examples

Input

4 4
4 3 1 6

Output

3 2 5 4 

Input

5 2
3 2 0 2 7

Output

2 1 4 1 6 

Input

3 3
2 3 1

Output

1 2 3 

思维题,逆推,讨论最小值,与结束点的位置关系,逆推回去即可。
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
#define LL long long
#define M 1000000007
LL a[maxn];
int main()
{
LL n,i,x,minn=0x7f7f7f7f,j,y;
cin>>n>>x;
for(i=1; i<=n; i++)
{
cin>>a[i];
if(a[i]<=minn)
{
if(a[i]==minn&&j<=x&&i>x)
continue;
else
minn=a[i],j=i;
}
}
if(x<j)
{
y=x+(n-j)+a[j]*n;
for(i=1; i<=n; i++)
{
if(i!=j)
a[i]=a[i]-a[j];
if(i<=x||i>j)
a[i]--;
if(i==j)
cout<<y<<' ';
else
cout<<a[i]<<' ';
}
}
else if(x==j)
{
y=a[j]*n;
for(i=1; i<=n; i++)
{
if(i!=j)
a[i]=a[i]-a[j];
if(i!=j)
cout<<a[i]<<' ';
else
cout<<y<<' ';
}
}
else
{
y=x-j+a[j]*n;
for(i=1; i<=n; i++)
{
if(i!=j)
a[i]=a[i]-a[j];
if(i>j&&i<=x)
a[i]--;
if(i==j)
cout<<y<<' ';
else
cout<<a[i]<<' ';
}
}
return 0;
}

最新文章

  1. 在cmd下编译一个简单的servlet时出现程序包javax.servlet不存在
  2. html5 canvas 笔记二(添加样式和颜色)
  3. 八大排序算法之二希尔排序(Shell Sort)
  4. cdev成员结构体file_operations文件操作结构的分析
  5. POJ1125 Stockbroker Grapevine(最短路)
  6. C语言刷新缓冲区(转载)
  7. SQL VS NoSQL
  8. [luogu]P1352 没有上司的舞会[树形DP]
  9. 实体框架(Entity Frmaework)简介
  10. eclipse远程调试Tomcat方法(测试成功并且说说遇到的坑)
  11. Java中的queue和deque对比详解
  12. 初窥RabbitMQ消息中间及SpringBoot整合
  13. LOJ500 ZQC的拼图 二分答案、DP
  14. C++:vector中的v.at(0)和v[0]的区别
  15. Azure 元数据服务:适用于 Windows VM 的计划事件(预览)
  16. WebJars are client-side web libraries (e.g. jQuery &amp; Bootstrap) packaged into JAR (Java Archive) files
  17. kafka深入研究(六)
  18. [JS&amp;Jquery]实现页面表格中相同内容的行或列合并
  19. js 去除空格回车换行
  20. PHP验证是否为图片格式文件

热门文章

  1. 计算机网络协议,TCP数据报的分析
  2. Linux基础篇,系统服务(service)的管理
  3. Swing组件中URL方法获取 图标
  4. Python 的while循环和for循环的使用
  5. git配置用户名
  6. 运输层--------运输层与网络层的关系、UDP、TCP
  7. Tcxgrid使用例子
  8. TcxGrid
  9. L11注意力机制和Seq2seq模型
  10. Java核心技术--接口与内部类