Buggy python submission (verdict: Time Limit Exceeded):
def abs(x):
    if x>0:
        return x
    else:
        return x * (-1)

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_mi = list(a[idx] - (idx + 1) for idx in range(len(a)))
    a_mi_sorted = sorted(a_mi)
    a_mi_sorted.append(a_mi_sorted[-1]+1)##bのrangeを取るため
    setAMI = sorted(list(set(a_mi_sorted)))

    ##print(a_mi_sorted)
    ans = float('inf')
    for i in range(n):
        #i番目までa[i]-bが0以下（absで負扱い）
        buf = sum(a_mi_sorted[:n]) - 2 * (sum(a_mi_sorted[:i+1]))
        for b in range(a_mi_sorted[i], setAMI[setAMI.index(a_mi_sorted[i])+1]):
            ans = min(ans, buf + (2 * (i + 1) - n) * b)
            ##print(i,b,ans)
    print(ans)

Fixed submission:
N = int(input())
A = map(int, input().split())
B = list(A_i - (i + 1) for i, A_i in enumerate(A))
B_sorted = sorted(B)

ans = []
##中央値のインデックスmを求める
if N % 2 == 1:
    ##Nが奇数: 中央値のインデックスを求める
    m = int((N - 1) / 2 + 1) - 1
    b = B_sorted[m]
    ans += [sum(abs(x - b) for x in B_sorted)]
else:
    ##Nが偶数: 中央値を計算する元になる2数のインデックスを求める
    for m in range(int(N / 2) - 1, int(N / 2) + 1):
        b = B_sorted[m]
        ans += [sum(abs(x - b) for x in B_sorted)]    
print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
def abs(x):
    if x>0:
        return x
    else:
        return x * (-1)

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_mi = list(a[idx] - (idx + 1) for idx in range(len(a)))
    a_mi_sorted = sorted(a_mi)
    a_mi_sorted.append(a_mi_sorted[-1]+1)##bのrangeを取るため
    setAMI = sorted(list(set(a_mi_sorted)))

    ##print(a_mi_sorted)
    ans = float('inf')
    for i in range(n):
        #i番目までa[i]-bが0以下（absで負扱い）
        for b in range(a_mi_sorted[i], setAMI[setAMI.index(a_mi_sorted[i])+1]):
            ans = min(ans, sum(a_mi_sorted[:n]) - 2 * (sum(a_mi_sorted[:i+1])) + (2 * (i + 1) - n) * b)
            ##print(i,b,ans)
    print(ans)

Fixed submission:
N = int(input())
A = map(int, input().split())
B = list(A_i - (i + 1) for i, A_i in enumerate(A))
B_sorted = sorted(B)

ans = []
##中央値のインデックスmを求める
if N % 2 == 1:
    ##Nが奇数: 中央値のインデックスを求める
    m = int((N - 1) / 2 + 1) - 1
    b = B_sorted[m]
    ans += [sum(abs(x - b) for x in B_sorted)]
else:
    ##Nが偶数: 中央値を計算する元になる2数のインデックスを求める
    for m in range(int(N / 2) - 1, int(N / 2) + 1):
        b = B_sorted[m]
        ans += [sum(abs(x - b) for x in B_sorted)]    
print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
def abs(x):
    if x>0:
        return x
    else:
        return x * (-1)

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_mi = list(a[idx] - idx for idx in range(len(a)))

    s = float('inf')
    for b in range(min(a_mi), max(a_mi) + 1):
        s = min(s, sum(abs(x - b) for x in a_mi))
    print(s)

Fixed submission:
N = int(input())
A = map(int, input().split())
B = list(A_i - (i + 1) for i, A_i in enumerate(A))
B_sorted = sorted(B)

ans = []
##中央値のインデックスmを求める
if N % 2 == 1:
    ##Nが奇数: 中央値のインデックスを求める
    m = int((N - 1) / 2 + 1) - 1
    b = B_sorted[m]
    ans += [sum(abs(x - b) for x in B_sorted)]
else:
    ##Nが偶数: 中央値を計算する元になる2数のインデックスを求める
    for m in range(int(N / 2) - 1, int(N / 2) + 1):
        b = B_sorted[m]
        ans += [sum(abs(x - b) for x in B_sorted)]    
print(min(ans))