Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
 
diff = []
for i, index in enumerate(a,1):
    diff.append(abs(i - index))
 
diff.sort()
if n % 2 == 1:
    b = diff[len(diff) // 2]
    for i in diff:
        ans1 += abs(i - b)
 
    print(ans1)
else:
    b1 = diff[len(diff) // 2 - 1]
    b2 = diff[len(diff) // 2]
    for i in diff:
        ans1 += abs(i -b1)
        ans2 += abs(i -b2)
    print(min(ans1.ans2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    b = diff[n // 2]
    tmp = map(lambda x: x - b, diff)
    print(sum( map(abs,tmp )))
else:
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    tmp1 = map(lambda x: x - b1, diff)
    tmp2 = map(lambda x: x - b2, diff)
    ans1 = sum( map(abs,tmp1 ))
    ans2 = sum( map(abs,tmp2 ))
    print(min(ans1,ans2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    ans = 0
    b = diff[n // 2]
    for i in diff:
        ans += abs(i - b)
    print(ans)
else:
    ans1,ans2 = 0
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    for i in diff:
        ans1 += abs(i -b1)
        ans2 += abs(i -b2)
    print(min(b1.b2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    b = diff[n // 2]
    tmp = map(lambda x: x - b, diff)
    print(sum( map(abs,tmp )))
else:
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    tmp1 = map(lambda x: x - b1, diff)
    tmp2 = map(lambda x: x - b2, diff)
    ans1 = sum( map(abs,tmp1 ))
    ans2 = sum( map(abs,tmp2 ))
    print(min(ans1,ans2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0

diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    b = diff[n // 2]
    for i in diff:
        ans1 += abs(i - b)
    print(ans1)
else:
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    for i in diff:
        ans1 += abs(i -b1)
        ans2 += abs(i -b2)
    print(min(b1.b2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    b = diff[n // 2]
    tmp = map(lambda x: x - b, diff)
    print(sum( map(abs,tmp )))
else:
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    tmp1 = map(lambda x: x - b1, diff)
    tmp2 = map(lambda x: x - b2, diff)
    ans1 = sum( map(abs,tmp1 ))
    ans2 = sum( map(abs,tmp2 ))
    print(min(ans1,ans2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0

diff = []
for i, index in enumerate(a,1):
    diff.append(abs(i - index))

diff.sort()
if n % 2 == 1:
    b = diff[len(diff) // 2]
    for i in diff:
        ans1 += abs(i - b)

    print(ans1)
else:
    b1 = diff[len(diff) // 2 - 1]
    b2 = diff[len(diff) // 2]
    for i in diff:
        ans1 += abs(i -b1)
        ans2 += abs(i -b2)
    print(min(b1.b2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    b = diff[n // 2]
    tmp = map(lambda x: x - b, diff)
    print(sum( map(abs,tmp )))
else:
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    tmp1 = map(lambda x: x - b1, diff)
    tmp2 = map(lambda x: x - b2, diff)
    ans1 = sum( map(abs,tmp1 ))
    ans2 = sum( map(abs,tmp2 ))
    print(min(ans1,ans2))