#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAXN = 100005;
const int mod = 1e9 + 7;
typedef pair<int, int> pi;
int n, a[MAXN];
vector<int> l, r;
struct bit{
int tree[MAXN];
void add(int x, int v){
x++;
while(x <= n){
tree[x] += v;
x += x & -x;
}
}
int sum(int x){
x++;
int ret = 0;
while(x){
ret += tree[x];
x -= x & -x;
}
return ret;
}
}bl, br;
struct bit2{
lint tree[MAXN];
void add(int x, lint v){
x++;
while(x <= n){
tree[x] += v;
x += x & -x;
}
}
lint sum(int x){
x++;
lint ret = 0;
while(x){
ret += tree[x];
x -= x & -x;
}
return ret;
}
}ql, qr;
int it1, it2;
int trial(int i, int x){
int ans = 0;
it1 = upper_bound(l.begin(), l.end(), x - i) - l.begin();
ans += bl.sum(it1 - 1);
it2 = upper_bound(r.begin(), r.end(), x + i) - r.begin();
ans += br.sum(it2 - 1);
return ans;
}
lint solve(int i, int x){
lint ans = 0;
ans += (x - i) * bl.sum(it1 - 1) - ql.sum(it1 - 1);
ans += (ql.sum(n-1) - ql.sum(it1 - 1)) - (x - i) * (bl.sum(n-1) - bl.sum(it1 - 1));
ans += (x + i) * br.sum(it2 - 1) - qr.sum(it2 - 1);
ans += (qr.sum(n-1) - qr.sum(it2 - 1)) - (x + i) * (br.sum(n-1) - br.sum(it2 - 1));
return ans;
}
int main(){
scanf("%d",&n);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
}
for(int i=1; i<=n; i++){
l.push_back(a[i] - i);
r.push_back(a[i] + i);
}
sort(l.begin(), l.end());
sort(r.begin(), r.end());
l.resize(unique(l.begin(), l.end()) - l.begin());
r.resize(unique(r.begin(), r.end()) - r.begin());
for(int i=1; i<=n; i++){
auto pr = lower_bound(r.begin(), r.end(), a[i] + i) - r.begin();
br.add(pr, 1);
qr.add(pr, a[i] + i);
}
lint ans = 1e18;
for(int i=1; i<=n; i++){
auto pl = lower_bound(l.begin(), l.end(), a[i] - i) - l.begin();
auto pr = lower_bound(r.begin(), r.end(), a[i] + i) - r.begin();
bl.add(pl, 1);
br.add(pr, -1);
ql.add(pl, (a[i] - i));
qr.add(pr, -(a[i] + i));
int s = max(i, n + 1 - i), e = 1e9 + 1e6;
while(s != e){
int m = (s+e)/2;
if(trial(i, m) >= (n+1)/2) e = m;
else s = m+1;
}
ans = min(ans, solve(i, s));
}
cout << ans << endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxpbnQ7CmNvbnN0IGludCBNQVhOID0gMTAwMDA1Owpjb25zdCBpbnQgbW9kID0gMWU5ICsgNzsKdHlwZWRlZiBwYWlyPGludCwgaW50PiBwaTsKIAppbnQgbiwgYVtNQVhOXTsKdmVjdG9yPGludD4gbCwgcjsKIApzdHJ1Y3QgYml0ewogICAgaW50IHRyZWVbTUFYTl07CiAgICB2b2lkIGFkZChpbnQgeCwgaW50IHYpewogICAgICAgIHgrKzsKICAgICAgICB3aGlsZSh4IDw9IG4pewogICAgICAgICAgICB0cmVlW3hdICs9IHY7CiAgICAgICAgICAgIHggKz0geCAmIC14OwogICAgICAgIH0KICAgIH0KICAgIGludCBzdW0oaW50IHgpewogICAgICAgIHgrKzsKICAgICAgICBpbnQgcmV0ID0gMDsKICAgICAgICB3aGlsZSh4KXsKICAgICAgICAgICAgcmV0ICs9IHRyZWVbeF07CiAgICAgICAgICAgIHggLT0geCAmIC14OwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgfQp9YmwsIGJyOwogCnN0cnVjdCBiaXQyewogICAgbGludCB0cmVlW01BWE5dOwogICAgdm9pZCBhZGQoaW50IHgsIGxpbnQgdil7CiAgICAgICAgeCsrOwogICAgICAgIHdoaWxlKHggPD0gbil7CiAgICAgICAgICAgIHRyZWVbeF0gKz0gdjsKICAgICAgICAgICAgeCArPSB4ICYgLXg7CiAgICAgICAgfQogICAgfQogICAgbGludCBzdW0oaW50IHgpewogICAgICA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XSk7CiAgICB9CiAgICBmb3IoaW50IGk9MTsgaTw9bjsgaSsrKXsKICAgICAgICBsLnB1c2hfYmFjayhhW2ldIC0gaSk7CiAgICAgICAgci5wdXNoX2JhY2soYVtpXSArIGkpOwogICAgfQogICAgc29ydChsLmJlZ2luKCksIGwuZW5kKCkpOwogICAgc29ydChyLmJlZ2luKCksIHIuZW5kKCkpOwogICAgbC5yZXNpemUodW5pcXVlKGwuYmVnaW4oKSwgbC5lbmQoKSkgLSBsLmJlZ2luKCkpOwogICAgci5yZXNpemUodW5pcXVlKHIuYmVnaW4oKSwgci5lbmQoKSkgLSByLmJlZ2luKCkpOwogICAgZm9yKGludCBpPTE7IGk8PW47IGkrKyl7CiAgICAgICAgYXV0byBwciA9IGxvd2VyX2JvdW5kKHIuYmVnaW4oKSwgci5lbmQoKSwgYVtpXSArIGkpIC0gci5iZWdpbigpOwogICAgICAgIGJyLmFkZChwciwgMSk7CiAgICAgICAgcXIuYWRkKHByLCBhW2ldICsgaSk7CiAgICB9CiAgICBsaW50IGFucyA9IDFlMTg7CiAgICBmb3IoaW50IGk9MTsgaTw9bjsgaSsrKXsKICAgICAgICBhdXRvIHBsID0gbG93ZXJfYm91bmQobC5iZWdpbigpLCBsLmVuZCgpLCBhW2ldIC0gaSkgLSBsLmJlZ2luKCk7CiAgICAgICAgYXV0byBwciA9IGxvd2VyX2JvdW5kKHIuYmVnaW4oKSwgci5lbmQoKSwgYVtpXSArIGkpIC0gci5iZWdpbigpOwogICAgICAgIGJsLmFkZChwbCwgMSk7CiAgICAgICAgYnIuYWRkKHByLCAtMSk7CiAgICAgICAgcWwuYWRkKHBsLCAoYVtpXSAtIGkpKTsKICAgICAgICBxci5hZGQocHIsIC0oYVtpXSArIGkpKTsKICAgICAgICBpbnQgcyA9IG1heChpLCBuICsgMSAtIGkpLCBlID0gMWU5ICsgMWU2OwogICAgICAgIHdoaWxlKHMgIT0gZSl7CiAgICAgICAgICAgIGludCBtID0gKHMrZSkvMjsKICAgICAgICAgICAgaWYodHJpYWwoaSwgbSkgPj0gKG4rMSkvMikgZSA9IG07CiAgICAgICAgICAgIGVsc2UgcyA9IG0rMTsKICAgICAgICB9CiAgICAgICAgYW5zID0gbWluKGFucywgc29sdmUoaSwgcykpOwogICAgfQogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKfQ==