Result: Accepted
Time: 73ms
Memory: 3280kB
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define MAXN 100010
#define ll long long
int n;
long long a[MAXN],sum[MAXN];
long long cnt,ans;
int main()
{
scanf("%d",&n);
ans=1000000000000;
for(int i=1;i<=n;++i)
{
scanf("%d",&a[i]);
if(i<=(n+1)/2)
a[i]=a[i]-i+1;
else
a[i]=a[i]-n+i;
}
sort(a+1,a+n+1);
sum[0]=0;
for(int i=1;i<=n;++i)
sum[i]=sum[i-1]+a[i];
for(int i=1;i<=n;++i)
{
if(a[i+1]!=a[i])
{
cnt=i*a[i]-2*sum[i]+sum[n]-(n-i)*a[i];
ans=min(cnt,ans);
}
}
printf("%lld\n",ans);
}