Buggy python submission (verdict: Runtime Error):
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

m = N-1
if (m % 2 == 0):
    m = m//2
    cent = (An[m] + An[m + 1]) // 2
else:
    cent = An[(m+1)//2]

ans = 0
for n in range(N):
    ans += abs(An[n] - cent)

print(ans)

Fixed submission:
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

if (N-1) % 2 != 0:
    m = N//2 - 1
else:
    m = (N-1)//2

bf = -sum(An[0:m+1:]) + (m+1)*An[m]
af = sum(An[m+1::]) - (N-m-1)*An[m]
ans = bf + af
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

m = N-1
if (m % 2 == 0):
    cent = (An[m//2] + An[m//2 + 1]) // 2
else:
    cent = An[(m+1)//2]

ans = 0
for n in range(N):
    ans += abs(An[n] - cent)

print(ans)

Fixed submission:
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

if (N-1) % 2 != 0:
    m = N//2 - 1
else:
    m = (N-1)//2

bf = -sum(An[0:m+1:]) + (m+1)*An[m]
af = sum(An[m+1::]) - (N-m-1)*An[m]
ans = bf + af
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

m = N-1
if (m % 2 == 0):
    cent = (An[m/2] + An[m/2 + 1]) // 2
else:
    cent = An[(m+1)/2]

ans = 0
for n in range(N):
    ans += abs(An[n] - cent)

print(ans)



Fixed submission:
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

if (N-1) % 2 != 0:
    m = N//2 - 1
else:
    m = (N-1)//2

bf = -sum(An[0:m+1:]) + (m+1)*An[m]
af = sum(An[m+1::]) - (N-m-1)*An[m]
ans = bf + af
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
An = list(map(int, input().split()))
for n in range(N):
    An[n] -= (n+1)

An.sort()

m = N-1
if (m % 2 == 0):
    cent = (An[m//2] + An[m//2 + 1]) // 2
else:
    cent = An[(m+1)//2]

ans = 0
for n in range(N):
    ans += abs(An[n] - cent)

print(ans)



Fixed submission:
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

if (N-1) % 2 != 0:
    m = N//2 - 1
else:
    m = (N-1)//2

bf = -sum(An[0:m+1:]) + (m+1)*An[m]
af = sum(An[m+1::]) - (N-m-1)*An[m]
ans = bf + af
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
An = list(map(int, input().split()))
for n in range(N):
    An[n] -= (n+1)

An.sort()

m = N-1
if (m % 2 == 0):
    cent = (An[m//2] + An[m//2 + 1]) // 2
else:
    cent = An[(m+1)//2]

ans = sum(An) - N * cent

print(ans)



Fixed submission:
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

if (N-1) % 2 != 0:
    m = N//2 - 1
else:
    m = (N-1)//2

bf = -sum(An[0:m+1:]) + (m+1)*An[m]
af = sum(An[m+1::]) - (N-m-1)*An[m]
ans = bf + af
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
An = list(map(int, input().split()))

sum = 0
for n in range(N):
    sum += An[n] - (n+1)
    
a, b, c = sum//N, sum//N + 1

ans = [0]*3
for n in range(N):
    ans[0] += abs(An[n] - (a+n+1))
    ans[0] += abs(An[n] - (b+n+1))
    ans[1] += abs(An[n] - (c+n+1))

print(min(ans))


Fixed submission:
N = int(input())
An = list(map(int, input().split()))

for n in range(N):
    An[n] -= (n+1)

An.sort()

if (N-1) % 2 != 0:
    m = N//2 - 1
else:
    m = (N-1)//2

bf = -sum(An[0:m+1:]) + (m+1)*An[m]
af = sum(An[m+1::]) - (N-m-1)*An[m]
ans = bf + af
print(ans)