#include <stdio.h>
int main()
{
int n, x, i, me, idm;
long long at=0, c[100005];
for(i=1;i<=n;i++)
{
if(i==1)
{
idm=1;
me=c[i];
}
else if(c[i]<me || (c[i]==me && ((x-i>=0 && x-idm>=0 && x-i<x-idm) || (x-i<0 && x-idm<0 && i-x>idm-x) )))
{
idm=i;
me=c[i];
}
}
for(i=1;i<=n;i++)
{
if(idm<=x)
{
if(i<idm || i>x)
{
c[i] -= me;
at+=me;
}
else
{
c[i] -= me+1;
at+=me+1;
}
}
else
{
if(i<x || i>idm)
{
c[i] -= me+1;
at+=me+1;
}
else
{
c[i]-= me;
at += me;
}
}
}
c[idm] = at-1;
for(i=1;i<=n;i++)
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpCnsKICAgIGludCBuLCB4LCBpLCBtZSwgaWRtOwoJbG9uZyBsb25nIGF0PTAsIGNbMTAwMDA1XTsKCXNjYW5mKCIgJWQgJWQiLCAmbiwgJngpOwoJZm9yKGk9MTtpPD1uO2krKykKCXsKCQlzY2FuZigiICVsbGQiLCAmY1tpXSk7CgkJaWYoaT09MSkKCQl7CgkJCWlkbT0xOwoJCQltZT1jW2ldOwoJCX0KCQllbHNlIGlmKGNbaV08bWUgfHwgKGNbaV09PW1lICYmICgoeC1pPj0wICYmIHgtaWRtPj0wICYmIHgtaTx4LWlkbSkgfHwgKHgtaTwwICYmIHgtaWRtPDAgJiYgaS14PmlkbS14KSApKSkKCQl7CgkJCWlkbT1pOwoJCQltZT1jW2ldOwoJCX0KCX0KCWZvcihpPTE7aTw9bjtpKyspCgl7CgkJaWYoaWRtPD14KQoJCXsKCQkJaWYoaTxpZG0gfHwgaT54KQoJCQl7CgkJCQljW2ldIC09IG1lOwoJCQkJYXQrPW1lOwoJCQl9CgkJCWVsc2UKCQkJewoJCQkJY1tpXSAtPSBtZSsxOwoJCQkJYXQrPW1lKzE7CgkJCX0KCQl9CgkJZWxzZQoJCXsKCQkJaWYoaTx4IHx8IGk+aWRtK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