Buggy python submission (verdict: Runtime Error):
from collections import Counter

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)
pl = count(mapdict(A2[N//2 +1],Adic))
mn = count(mapdict(A2[N//2 -1],Adic))


if pl<=res:
    tmp = pl
    tmpc = 1
    while tmp <= res:
        tmpc += 1
        if N//2 + tmpc > N-1:
            break
        res = tmp
        Adic = mapdict(A2[N//2 +tmpc], Adic)
        tmp = count(Adic)
        

elif mn<=res:
    tmp = mn
    tmpc = 1
    while tmp <= res:
        tmpc += 1
        if N//2 - tmpc < 0:
            break
        res = tmp
        Adic = mapdict(A2[N//2 -tmpc], Adic)
        tmp = count(Adic)

print(res)

Fixed submission:
from collections import Counter

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)

if N==1:
    print(0)

elif N==2:
    print(sum(map(abs,map(lambda x:x-min(A2),A2))))

else:
    pl = count(mapdict(A2[N//2 +1],Adic))
    mn = count(mapdict(A2[N//2 -1],Adic))
    if pl<=res:
        tmp = pl
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 + tmpc > N-1:
                break
            res = tmp
            Adic = mapdict(A2[N//2 +tmpc], Adic)
            tmp = count(Adic)
    elif mn<=res:
        tmp = mn
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 - tmpc < 0:
                break
            res = tmp
            Adic = mapdict(A2[N//2 -tmpc], Adic)
            tmp = count(Adic)

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)
pl = count(mapdict(1,Adic))
mn = count(mapdict(-1,Adic))


if pl<=res:
    tmp = res
    while tmp <= res:
        res = tmp
        Adic = mapdict(1, Adic)
        tmp = count(Adic)

elif mn<=res:
    tmp = res
    while tmp <= res:
        res = tmp
        Adic = mapdict(-1, Adic)
        tmp = count(Adic)

print(res)

Fixed submission:
from collections import Counter

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)

if N==1:
    print(0)

elif N==2:
    print(sum(map(abs,map(lambda x:x-min(A2),A2))))

else:
    pl = count(mapdict(A2[N//2 +1],Adic))
    mn = count(mapdict(A2[N//2 -1],Adic))
    if pl<=res:
        tmp = pl
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 + tmpc > N-1:
                break
            res = tmp
            Adic = mapdict(A2[N//2 +tmpc], Adic)
            tmp = count(Adic)
    elif mn<=res:
        tmp = mn
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 - tmpc < 0:
                break
            res = tmp
            Adic = mapdict(A2[N//2 -tmpc], Adic)
            tmp = count(Adic)

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def mapdict(itemfunc, dictionary):
    return dict(map(itemfunc, dictionary.items())) 

def minus(tup):
    return (tup[0]-1,tup[1]) 
def plus(tup):
    return (tup[0]+1,tup[1]) 

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = [A[i-1]-i for i in range(1,N+1)]
Adic = Counter(A2)
Ax  = Adic.most_common()[0][0]
Adic = mapdict(lambda t: (t[0]+Ax,t[1]), Adic)

res = count(Adic)
pl = count(mapdict(plus,Adic))
mn = count(mapdict(minus,Adic))


if pl<res:
    tmp = float("inf")
    while res <= tmp:
        tmp = res
        Adic = mapdict(plus, Adic)
        res = count(Adic)
    res = tmp

elif mn<res:
    tmp = float("inf")
    while res <= tmp:
        tmp = res
        Adic = mapdict(minus, Adic)
        res = count(Adic)
    res = tmp

print(res)

Fixed submission:
from collections import Counter

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)

if N==1:
    print(0)

elif N==2:
    print(sum(map(abs,map(lambda x:x-min(A2),A2))))

else:
    pl = count(mapdict(A2[N//2 +1],Adic))
    mn = count(mapdict(A2[N//2 -1],Adic))
    if pl<=res:
        tmp = pl
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 + tmpc > N-1:
                break
            res = tmp
            Adic = mapdict(A2[N//2 +tmpc], Adic)
            tmp = count(Adic)
    elif mn<=res:
        tmp = mn
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 - tmpc < 0:
                break
            res = tmp
            Adic = mapdict(A2[N//2 -tmpc], Adic)
            tmp = count(Adic)

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def mapdict(itemfunc, dictionary):
    return dict(map(itemfunc, dictionary.items())) 

def minus(tup):
    return (tup[0]-1,tup[1]) 
def plus(tup):
    return (tup[0]+1,tup[1]) 

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = [A[i-1]-i for i in range(1,N+1)]
Adic = Counter(A2)

res = count(Adic)
pl = count(mapdict(plus,Adic))
mn = count(mapdict(minus,Adic))

if pl<res:
    tmp = float("inf")
    while res <= tmp:
        tmp = res
        Adic = mapdict(plus, Adic)
        res = count(Adic)
    res = tmp

elif mn<res:
    tmp = float("inf")
    while res <= tmp:
        tmp = res
        Adic = mapdict(minus, Adic)
        res = count(Adic)
    res = tmp

print(res)



Fixed submission:
from collections import Counter

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

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

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)

if N==1:
    print(0)

elif N==2:
    print(sum(map(abs,map(lambda x:x-min(A2),A2))))

else:
    pl = count(mapdict(A2[N//2 +1],Adic))
    mn = count(mapdict(A2[N//2 -1],Adic))
    if pl<=res:
        tmp = pl
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 + tmpc > N-1:
                break
            res = tmp
            Adic = mapdict(A2[N//2 +tmpc], Adic)
            tmp = count(Adic)
    elif mn<=res:
        tmp = mn
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 - tmpc < 0:
                break
            res = tmp
            Adic = mapdict(A2[N//2 -tmpc], Adic)
            tmp = count(Adic)

    print(res)