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

def sunuke(b):
    ret = 0
    sub = 1
    for a in A:
        ret += abs(a - (b+ sub))
        sub += 1
    return ret


B = []

sub = 1
for a in A:
    b = a - sub
    B.append(b)
    sub += 1

B.sort()
b1 = N // 2
b2 = b1 + 1

b1_s = sunuke(B[b1])
b2_s = sunuke(B[b2])
if b1_s < b2_s:
    print(b1_s)
else:
    print(b2_s)


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

def sunuke(b):
    ret = 0
    sub = 1
    for a in A:
        ret += abs(a - (b+ sub))
        sub += 1
    return ret


B = []

sub = 1
for a in A:
    b = a - sub
    B.append(b)
    sub += 1

B.sort()
b1 = N // 2
if N < 3:
    print(sunuke(B[b1]))
    exit()

b2 = b1 + 1
b1_s = sunuke(B[b1])
b2_s = sunuke(B[b2])
if b1_s < b2_s:
    print(b1_s)
else:
    print(b2_s)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))

def search_wb():
    sub = 1
    max_abs = abs(A[0] - sub)
    for a in A:
        if max_abs < abs(a - sub):
            max_abs = abs(a-sub)
        sub += 1
    return max_abs, -max_abs

@lru_cache(maxsize=None)
def sunuke(b):
    ret = 0
    sub = 1
    for a in A:
        ret += abs(a - (b+ sub))
        sub += 1
    return ret


maxb, minb= search_wb()

while abs(maxb - minb) > 1:
    mid = (maxb + minb) // 2
    #print("max{} min{} mid{}".format(maxb, minb, mid))
    if sunuke(mid) >  sunuke(mid + 1):
        minb = mid
    else:
        maxb = mid


mins = sunuke(minb)
maxs = sunuke(maxb)
if mins < maxs:
    print(mins)
else:
    print(maxs)



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

def sunuke(b):
    ret = 0
    sub = 1
    for a in A:
        ret += abs(a - (b+ sub))
        sub += 1
    return ret


B = []

sub = 1
for a in A:
    b = a - sub
    B.append(b)
    sub += 1

B.sort()
b1 = N // 2
if N < 3:
    print(sunuke(B[b1]))
    exit()

b2 = b1 + 1
b1_s = sunuke(B[b1])
b2_s = sunuke(B[b2])
if b1_s < b2_s:
    print(b1_s)
else:
    print(b2_s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

def search_wb():
    sub = 1
    max_abs = abs(A[0] - sub)
    for a in A:
        if max_abs < abs(a - sub):
            max_abs = abs(a-sub)
        sub += 1
    return max_abs, -max_abs

def sunuke(b):
    ret = 0
    sub = 1
    for a in A:
        ret += abs(a - (b+ sub))
        sub += 1
    return ret


maxb, minb= search_wb()

while abs(maxb - minb) > 1:
    mid = (maxb + minb) // 2
    #print("max{} min{} mid{}".format(maxb, minb, mid))
    if sunuke(mid) >  sunuke(mid + 1):
        minb = mid
    else:
        maxb = mid


mins = sunuke(minb)
maxs = sunuke(maxb)
if mins < maxs:
    print(mins)
else:
    print(maxs)



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

def sunuke(b):
    ret = 0
    sub = 1
    for a in A:
        ret += abs(a - (b+ sub))
        sub += 1
    return ret


B = []

sub = 1
for a in A:
    b = a - sub
    B.append(b)
    sub += 1

B.sort()
b1 = N // 2
if N < 3:
    print(sunuke(B[b1]))
    exit()

b2 = b1 + 1
b1_s = sunuke(B[b1])
b2_s = sunuke(B[b2])
if b1_s < b2_s:
    print(b1_s)
else:
    print(b2_s)