Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    res = 0
    while N:
        r = N%10
        N //= 10
        r_ = N%10
        if r < 5 or (r==5 and r_ < 5):
            res += r
        else:
            res += 10-r
            N += 1
    return str(res)

if __name__ == '__main__':
    print(solve())



Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N = input()[::-1]+'00'
    res = 0
    c = 0
    for i in range(len(N)-1):
        r = int(N[i])+c
        c = r//10
        r %= 10
        r_ = (int(N[i+1])+c)%10
        if r < 5 or (r==5 and r_ < 5):
            res += r
        else:
            res += 10-r
            c += 1
    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def solve():
    N =  int(input())
    E = [[] for _ in range(N+1)]
    D = {}
    L = [-1 for _ in range(N)]
    for i in range(1,N):
        a, b = map(int, input().split())
        E[a].append(b)
        E[b].append(a)
        D[(a,b)] = D[(b,a)] = i
    r = 1
    l = len(E[1])
    for i in range(2,N+1):
        k = len(E[i])
        if l < k:
            r, l = i, k
    d = l
    q = [(r,0)]
    z = []
    while q:
        v, c = q.pop()
        C = list(range(1,d+1))
        for u in E[v]:
            if L[D[(v,u)]] == -1:
                x = C.pop()
                if c == x:
                    x = C.pop()
                q.append((u,x))
                L[D[(v,u)]] = x
                z.append(u)
    L[0] = d
    res = '\n'.join(map(str, L))
    return str(res)

if __name__ == '__main__':
    print(solve())


Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N =  int(input())
    E = [[] for _ in range(N+1)]
    D = {}
    L = [-1 for _ in range(N)]
    for i in range(1,N):
        a, b = map(int, input().split())
        E[a].append(b)
        E[b].append(a)
        D[(a,b)] = i
    r = 1
    q = [(r,0)]
    d = 0
    while q:
        v, c = q.pop()
        d = max(d, len(E[v]))
        C = 0
        for u in E[v]:
            if L[D.get((v,u), D.get((u,v),-1))] == -1:
                C += 1
                x = C
                if c == x:
                    C += 1
                    x = C
                q.append((u,x))
                L[D.get((v,u), D.get((u,v),-1))] = x
    L[0] = d
    res = '\n'.join(map(str, L))
    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from math import ceil, sqrt, atan, degrees

def solve():
    a,b,x = map(int, input().split())
    if 1/2*a*a*b >= x:
        t = atan(2*x/a/b/b)
    else:
        t = atan(a*a*a/2/(a*a*b-x))

    return str(90-degrees(t))
        
if __name__ == '__main__':
    print(solve())


Fixed submission:
# -*- coding: utf-8 -*-
from math import ceil, sqrt, atan, degrees

def solve():
    a,b,x = map(int, input().split())
    if a*a*b == x:
        return '0'
    elif 1/2*a*a*b >= x:
        t = atan(2*x/a/b/b)
    else:
        t = atan(a*a*a/2/(a*a*b-x))

    return str(90-degrees(t))
        
if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N, M = map(int, input().split())
    dp = np.array([-1]*2**N, dtype=np.uint32)
    dp[0] = 0
    for i in range(M):
        a, b = map(int, input().split())
        d = sum(2**(c-1) for c in  map(int, input().split()))
        for j,e in enumerate(dp):
            if d|j == d:
                dp[j] = min(e,a)
            else:
                k = j-(j&d)
                dp[j] = min(e, dp[k]+a)

    res = dp[-1] if dp[-1] < np.uint32(-1) else -1
    return str(res)

if __name__ == '__main__':
    print(solve())


Fixed submission:
# -*- coding: utf-8 -*-

def solve():
    N, M = map(int, input().split())
    max_int = 2**32-1
    dp = [max_int]*2**N
    dp[0] = 0
    for i in range(M):
        a, b = map(int, input().split())
        d = sum(2**c for c in map(int, input().split()))>>1
        for j in range(2**N+1):
            if j|d == d:
                dp[j] = min(dp[j],a)
            elif j&d:
                dp[j] = min(dp[j], dp[j-(j&d)]+a)

    res = dp[-1] if dp[-1] < max_int else -1
    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    D = {}
    for j,a in enumerate(A):
        D[a] = D.get(a,[])+[j]

    t,k = 0,0
    T = [0]
    while True:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            T.append(A[t])
        t = (D[A[t]][k]+1)%N
        if t == 0:
            break

    T[0] = T.pop()
    t = D[T[K%len(T)]][0]+1
    S = []
    while t < N:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            S.append(A[t])
        t = D[A[t]][k]+1

    res = ' '.join(map(str,S))

    return str(res)

if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-

def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    D = {}
    for j,a in enumerate(A):
        D[a] = D.get(a,[])+[j]

    t,k = 0,0
    T = [0]
    while True:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            T.append(A[t])
        t = (D[A[t]][k]+1)%N
        if t == 0:
            break

    if T == [0]:
        return ''
    if K == 1 or (K-1)%len(T) == 0:
        t = 0
    else:
        t = D[T[(K-1)%len(T)]][0]+1
    S = []
    flag = False
    while t < N:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            S.append(A[t])
            t += 1
        else:
            t = D[A[t]][k]+1

    res = ' '.join(map(str,S))

    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    a = list(A)[0]
    if A[a] == 1:
        A.pop(a)
    else:
        A[a] -= 1

    for b in A:
        B = A.copy()
        c_, c = a, b
        while c in B:
            if B[c] == 1:
                B.pop(c)
            else:
                B[c] -= 1
            c_, c = c, c_^c
        if B == dict() and c == a:
            return 'Yes'
    return 'No'
if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    if N % 3:
        if 0 in A and A[0] == N:
            return 'Yes'
        else:
            return 'No'
    else:
        if 0 in A and A[0] == N:
            return 'Yes'
        elif 0 in A and A[0] == N//3:
            if len(A) == 2:
                return 'Yes'
            else:
                return 'No'
        elif len(A) == 3:
            if len(set(A.values())) == 1:
                a,b,c = A.keys()
                if c == a^b:
                    return 'Yes'
                else:
                    return 'No'
            else:
                return 'No'
        else:
            return 'No'

if __name__ == '__main__':
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0)+1
    a = min(A.keys())
    A[a] -= 1
    if A[a] == 0:
        del A[a]

    for b in A.keys():
        B = A.copy()
        c_, c = a, b
        while c in B.keys():
            B[c] -= 1
            if B[c] == 0:
                del B[c]
            c_, c = c, c_^c
        if B == dict() and c == a:
            return 'Yes'
    return 'No'
if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    if N % 3:
        if 0 in A and A[0] == N:
            return 'Yes'
        else:
            return 'No'
    else:
        if 0 in A and A[0] == N:
            return 'Yes'
        elif 0 in A and A[0] == N//3:
            if len(A) == 2:
                return 'Yes'
            else:
                return 'No'
        elif len(A) == 3:
            if len(set(A.values())) == 1:
                a,b,c = A.keys()
                if c == a^b:
                    return 'Yes'
                else:
                    return 'No'
            else:
                return 'No'
        else:
            return 'No'

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def solve():
    N, M = map(int, input().split())
    if M%2:
        return '-1'
    E = [set() for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, input().split())
        E[a].add(b)
        E[b].add(a)
    q = [(0,1,1)]
    v = set()
    T = [set() for _ in range(N+1)]
    L = []
    V = []
    while q:
        n_, n, d = q.pop()
        if n not in v:
            T[n].add(n_)
            T[n_].add(n)
            v.add(n)
            V.append((d,n))
            if E[n]-v:
                q.extend([(n,u, d+1) for u in E[n]-v])
            else:
                L.append(n)

    A = [0 for _ in range(N+1)]
    res = []
    c = set()
    for d, n in sorted(V, reverse=1):
        c.add(n)
        if (A[n]+len(E[n]))%2:
            res.extend([(u,n) for u in E[n]-c])
            for u in E[n]-c:
                A[u] += 1
                E[u] -= {n}
        else:
            res.extend([(n,u) for u in E[n]-c])
            for u in E[n]-c:
                A[n] += 1
                E[u] -= {n}
    if any(a%2 for a in A):
        return '-1'
    else:
        return '\n'.join(['{} {}'.format(*e,) for e in res])


if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-
def solve():
    N, M = map(int, input().split())
    if M%2:
        return '-1'
    E = [set() for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, input().split())
        E[a].add(b)
        E[b].add(a)
    q = [(0,1,1)]
    v = set()
    T = []
    while q:
        n_, n, d = q.pop()
        if n not in v:
            T.append((d,n_,n))
            E[n].discard(n_)
            E[n_].discard(n)
            v.add(n)
            if E[n]-v:
                q.extend([(n,u, d+1) for u in E[n]-v])

    A = [0 for _ in range(N+1)]
    res = []
    c = set()
    for d,a,b in sorted(T, reverse=1)[:-1]:
        F = E[b]-c
        if A[b]%2 == 0 or len(E[b])%2:
            res.extend([(u,b) for u in F])
            for u in F:
                A[u] += 1
                E[u] -= {b}
        else:
            res.extend([(b,u) for u in F])
            for u in F:
                A[b] += 1
                E[u] -= {b}

        E[a] -= {b}
        if A[b]%2:
            A[b] += 1
            res.extend([(b,a)]) 
        else:
            A[a] += 1
            res.extend([(a,b)])

    return '\n'.join(['{} {}'.format(*e) for e in res])


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Limit = dict()
    for i in range(N):
        A, B = map(int, input().split())
        New = not B in Limit.keys()
        Limit[B] = Limit.get(B,0) + A
        if Limit[B] > B:
            return 'No'
        else:
            tk = 0
            for k in Limit.keys():
                if New and k < B:
                    tk = max(tk, k)

                if k > B:
                    Limit[k] += A
                    if Limit[k] > k:
                        return 'No'
            Limit[B] += Limit.get(tk,0)
            if Limit[B] > B:
                return 'No'

    return 'Yes'

if __name__ == '__main__':
    print(solve())


Fixed submission:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

def solve():
    N = int(input())
    hq = []
    for i in range(N):
        A, B = map(int, input().split())
        heappush(hq, (B,A))

    time = 0
    cost = 0
    while hq:
        l, c = heappop(hq)
        if time == l:
            cost += c
        else:
            time = l
            cost += c
        if cost > time:
            return 'No'
    return 'Yes'
if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def PoAP_fnct(MOD):
    #MOD:素数
    fact_mod = [1,1]
    inv_mod = [0,1]
    inv_fact_mod = [1,1]
    i = len(fact_mod)
    i_ = len(inv_fact_mod)

    def PoAP(x,d,n):
        nonlocal i, i_
        if d == 0:
            return pow(x,n,MOD)

        while d >= i_:
            inv_mod[i_:i_] = [(-inv_mod[MOD%i_]*(MOD//i_))%MOD]
            inv_fact_mod[i_:i_] = [(inv_fact_mod[i_-1]*inv_mod[i_])%MOD]
            i_ += 1

        j = (-x*inv_mod[d])%MOD
        if j < n:
            return 0

        x = (x*inv_mod[d])%MOD

        while (x+n-1)%MOD >= i:
            fact_mod[i:i] = [(fact_mod[i-1]*i)%MOD]
            i += 1

        while x-1 >= i_:
            inv_mod[i_:i_] = [(-inv_mod[MOD%i_]*(MOD//i_))%MOD]
            inv_fact_mod[i_:i_] = [(inv_fact_mod[i_-1]*inv_mod[i_])%MOD]
            i_ += 1

        return fact_mod[(x+n-1)%MOD] * inv_fact_mod[x-1] * pow(d,n,MOD) % MOD
    return PoAP

def solve():
    Q = int(input())
    PoAP = PoAP_fnct(1000003)
    res = '\n'.join([str(PoAP(*map(int, input().split()))) for _ in range(Q)])
    return str(res)

if __name__ == '__main__':
    print(solve())



Fixed submission:
# -*- coding: utf-8 -*-
def PoAP_fnct(MOD):
    #MOD:素数
    fact_mod = [1,1]
    inv_mod = [0,1]
    inv_fact_mod = [1,1]
    i = len(fact_mod)
    i_ = len(inv_fact_mod)

    def PoAP(x,d,n):
        nonlocal i, i_
        if d == 0:
            return pow(x,n%(MOD-1),MOD)

        while d >= i_:
            inv_mod[i_:i_] = [(-inv_mod[MOD%i_]*(MOD//i_))%MOD]
            inv_fact_mod[i_:i_] = [(inv_fact_mod[i_-1]*inv_mod[i_])%MOD]
            i_ += 1

        j = (-x*inv_mod[d])%MOD
        if j < n:
            return 0

        x = (x*inv_mod[d])%MOD

        while (x+n-1)%MOD >= i:
            fact_mod[i:i] = [(fact_mod[i-1]*i)%MOD]
            i += 1

        while x-1 >= i_:
            inv_mod[i_:i_] = [(-inv_mod[MOD%i_]*(MOD//i_))%MOD]
            inv_fact_mod[i_:i_] = [(inv_fact_mod[i_-1]*inv_mod[i_])%MOD]
            i_ += 1

        return fact_mod[(x+n-1)%MOD] * inv_fact_mod[x-1] * pow(d,n%(MOD-1),MOD) % MOD
    return PoAP

def solve():
    Q = int(input())
    PoAP = PoAP_fnct(1000003)
    res = '\n'.join([str(PoAP(*map(int, input().split()))) for _ in range(Q)])
    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def solve():
    return str(int.__sub__(*map(int, input().split()),)+1)

if __name__ == '__main__':
    print(solve())


Fixed submission:
# -*- coding: utf-8 -*-

def solve():
  N, K = map(int, input().split())
  return str(N-K+1)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

from collections import defaultdict, deque

def solve():
    N, K = map(int, input().split())
    H = defaultdict(int)
    for _ in range(N):
        H[int(input())] += 1
    if K in H.values():
        res = 0
    else:
        H = sorted(list(H.items()))
        res = float('inf')
        for i in range(len(H)):
            h = H[i][0]
            k = H[i][1]
            while k < K:
                i += 1
                if i < len(H):
                    k += H[i][1]
                else:
                     break
            else:
                h = H[i][0] - h
                res = min(res, h)
    return str(res)

if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-

from collections import defaultdict, deque

def solve():
    N, K = map(int, input().split())
    H = defaultdict(int)
    for _ in range(N):
        H[int(input())] += 1
    if K in H.values():
        res = 0
    else:
        H = sorted(list(H.items()))
        res = float('inf')
        i = 0
        j = 0
        b = H[0][0]
        t = H[0][0]
        k = H[0][1]
        h = 0
        while j < len(H)-1:
            if k < K:
                j += 1 
                k += H[j][1]
                h += H[j][0] - t
                t = H[j][0]
            if k >= K:
                res = min(res, h)
                k -= H[i][1]
                i += 1
                h -= H[i][0] - b
                b = H[i][0]

    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
from operator import itemgetter
def solve():
    Z = sorted([tuple(map(int,input().split())) for _ in range(int(input()))], key=itemgetter(2) , reverse=True)
    x0, y0, h0 = Z[0]
    H = h0 + np.abs(np.arange(101, dtype=int).reshape(1,101)-x0) + np.abs(np.arange(101, dtype=int).reshape(101,1)-y0)
    return [' '.join(map(str, [i,j,h])) for (i,j),h in np.ndenumerate(H) if all(h == max(H[i,j]-abs(x-i)-abs(y-j),0) for x,y,h in Z)][0]

if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from operator import itemgetter
def solve():
    Z = sorted([tuple(map(int,input().split())) for _ in range(int(input()))], key=itemgetter(2,0,1) , reverse=True)
    x0, y0, h0 = Z[0]
    H = h0 + np.abs(np.arange(101, dtype=int).reshape(101,1)-x0) + np.abs(np.arange(101, dtype=int).reshape(1,101)-y0)
    for (i,j), h in np.ndenumerate(H):
        if all(h == max(H[i,j]-abs(x-i)-abs(y-j), 0) for x,y,h in Z):
            return ' '.join(map(str, [i,j,h]))

if __name__ == '__main__':
    print(solve())

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
from operator import itemgetter
def solve():
    Z = sorted([tuple(map(int,input().split())) for _ in range(int(input()))], key=itemgetter(2) , reverse=True)
    x0, y0, h0 = Z[0]
    H = h0 + np.abs(np.arange(101, dtype=int).reshape(1,101)-x0) + np.abs(np.arange(101, dtype=int).reshape(101,1)-y0)
    return [' '.join(map(str, [i,j,h])) for (i,j),h in np.ndenumerate(H) if all(h == max(H[i,j]-abs(x-i)-abs(y-j),0) for x,y,h in Z)][0]

if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from operator import itemgetter
def solve():
    Z = sorted([tuple(map(int,input().split())) for _ in range(int(input()))], key=itemgetter(2,0,1) , reverse=True)
    x0, y0, h0 = Z[0]
    H = h0 + np.abs(np.arange(101, dtype=int).reshape(101,1)-x0) + np.abs(np.arange(101, dtype=int).reshape(1,101)-y0)
    for (i,j), h in np.ndenumerate(H):
        if all(h == max(H[i,j]-abs(x-i)-abs(y-j), 0) for x,y,h in Z):
            return ' '.join(map(str, [i,j,h]))

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from collections import Counter
from operator import itemgetter
def solve():
    input()
    V = list(map(int, input().split()))
    l = sorted(Counter(V[::2]).items()+[(0,0)], key=itemgetter(1), reverse=True)
    u = sorted(Counter(V[1::2]).items()+[(0,0)], key=itemgetter(1), reverse=True)
    res = sum(map(itemgetter(1), l+u)) - (max(l[0][1]+u[1][1], l[1][1]+u[0][1]) if l[0][0]==u[0][0] else (l[0][1]+u[0][1]))
    return str(res)

if __name__ == '__main__':
    print(solve())



Fixed submission:
# -*- coding: utf-8 -*-
from collections import defaultdict
from operator import itemgetter
def solve():
    n = int(input())
    V = list(map(int, input().split()))
    l = defaultdict(int)
    u = defaultdict(int)
    for i in range(0,n,2):
        l[V[i]] += 1
        u[V[i+1]] += 1

    l = sorted(list(l.items()),key=itemgetter(1))[::-1]
    u = sorted(list(u.items()),key=itemgetter(1))[::-1]
    if len(l) == len(u) == 1:
        if l[0][0] != u[0][0]:
            res = 0
        else:
            res = min(l[0][1], u[0][1])
    else:
        if l[0][0] != u[0][0]:
            res = sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[1:]))
        elif len(u) == 1 or (len(l) > 1 and l[1][1]+u[0][1] > l[0][1]+u[1][1]):
            res = l[0][1] + sum(map(itemgetter(1), l[2:])) + sum(map(itemgetter(1), u[1:]))
        else:
            res = u[0][1] + sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[2:]))

    return str(res)

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N, K = map(int, input().split())
    C = np.array(list(map(int,input().split())))
    D = list()
    for i in range(N-K+1):
      c = C[i:i+K]
      l, r = min(min(c),0), max(max(c),0)
      d = -2*l + r if -l < r else  -l + 2*r
      D.append(d)
    return str(min(D))

if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N, K = map(int, input().split())
    C = np.array(list(map(int,input().split())))
    z = (C<0).sum()
    D = set()
    for i in range(N-K+1):
        l = -min(C[i],0)
        r = max(C[i+K-1],0)
        d = 2*l+r if l < r else 2*r+l
        D.add(d)
    return str(min(D))

if __name__ == '__main__':
    print(solve())

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N, K = map(int, input().split())
    C = np.array(list(map(int,input().split())))
    D = list()
    for i in range(N-K+1):
      c = C[i:i+K]
      l, r = max(c), min(c)
      d = -2*r + l if l > r else  -r + 2*l
      D.append(d)
    return str(min(D)

if __name__ == '__main__':
    print(solve())

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N, K = map(int, input().split())
    C = np.array(list(map(int,input().split())))
    z = (C<0).sum()
    D = set()
    for i in range(N-K+1):
        l = -min(C[i],0)
        r = max(C[i+K-1],0)
        d = 2*l+r if l < r else 2*r+l
        D.add(d)
    return str(min(D))

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())), dtype= int)
I = np.arange(1, N+1)
C = A - I
mincost = -1
for b in range(C.min(), C.max()+1):
    cost = np.abs(C - b).sum()
    mincost = cost if mincost < 0 else min(mincost, cost)
print(mincost)

Fixed submission:
import numpy as np
def _unique1d(ar, return_index=False, return_inverse=False,
              return_counts=False):
    """
    Find the unique elements of an array, ignoring shape.
    """
    ar = np.asanyarray(ar).flatten()

    optional_indices = return_index or return_inverse
    optional_returns = optional_indices or return_counts

    if ar.size == 0:
        if not optional_returns:
            ret = ar
        else:
            ret = (ar,)
            if return_index:
                ret += (np.empty(0, np.intp),)
            if return_inverse:
                ret += (np.empty(0, np.intp),)
            if return_counts:
                ret += (np.empty(0, np.intp),)
        return ret

    if optional_indices:
        perm = ar.argsort(kind='mergesort' if return_index else 'quicksort')
        aux = ar[perm]
    else:
        ar.sort()
        aux = ar
    flag = np.concatenate(([True], aux[1:] != aux[:-1]))

    if not optional_returns:
        ret = aux[flag]
    else:
        ret = (aux[flag],)
        if return_index:
            ret += (perm[flag],)
        if return_inverse:
            iflag = np.cumsum(flag) - 1
            inv_idx = np.empty(ar.shape, dtype=np.intp)
            inv_idx[perm] = iflag
            ret += (inv_idx,)
        if return_counts:
            idx = np.concatenate(np.nonzero(flag) + ([ar.size],))
            ret += (np.diff(idx),)
    return ret
N = int(input())
A = np.array(list(map(int, input().split())), dtype= int)
I = np.arange(1, N+1)
C = A - I
mincost = -1
P, M = _unique1d(C, return_counts=True)
n = -N
for p , m in zip(P, M):
    n1 = n + 2*m
    if n*n1<=0:
        b = p
        break
    n = n1
cost = np.abs(C - b).sum()
print(cost)