Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template #


N, K = mi()
strS = li()
S = [int(i) for i in strS]
S.append(0)
# S.insert(0, 1)
# print(S)

cnt = 0
lis0 = []
if S[0] == 1:
    listart = [0]
else:
    listart = []
liend = []
for i in range(1, N):
    if S[i] == 0:
        cnt += 1
    if S[i] == 0 and S[i + 1] == 1:
        listart.append(i + 1)
        lis0.append(i)
    if S[i-1] == 1 and S[i] == 0:
        liend.append(i-1)
if S[N-1] == 0:
    lis0.append(N)
if S[N-1] == 1:
    liend.append(N-1)
# lis.append(N)
# lis.insert(0, -1)
# print(lis0)
# print(listart)
# print(liend)
ma = max(liend[K - 1] + 1, N - listart[-K])
# print(ma)
if K >= len(lis0):
    print(N)
else:
    for i in range(len(listart) - K):
        ma = max(ma, liend[i+K]-listart[i]+1)
    print(ma)


Fixed submission:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template #


N, K = mi()
strS = li()
S = [int(i) for i in strS]
S.append(0)
# S.insert(0, 1)
# print(S)

cnt = 0
lis0 = []
if S[0] == 1:
    listart = [0]
    cnt += 1
else:
    listart = []
liend = []
for i in range(1, N):
    # if S[i] == 0:
    #     cnt += 1
    if S[i-1] == 0 and S[i] == 1:
        listart.append(i)
        lis0.append(i)
    if S[i-1] == 1 and S[i] == 0:
        liend.append(i-1)
# if S[N-1] == 0:
#     lis0.append(N)
if S[N-1] == 1:
    liend.append(N - 1)
    cnt += 1
# lis.append(N)
# lis.insert(0, -1)
len0 = len(listart) + 1 - cnt
# print(listart)
# print(liend)
# print(len0)
# print(ma)
if K >= len0:
    print(N)
else:
    ma = max(liend[K - 1] + 1, N - listart[-K])
    for i in range(len(listart) - K):
        ma = max(ma, liend[i+K]-listart[i]+1)
    print(ma)
Buggy python submission (verdict: Runtime Error):
a = []
for i in range(5):
    a.append(int(input()))

k = int(input())
if a[5] - a[0] > k:
    print(":(")
else:
    print("Yay!")

Fixed submission:
a = []
for i in range(5):
    a.append(int(input()))

k = int(input())
if a[4] - a[0] > k:
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
sublist = []
for i in range(max(X-K-1, 0), X):
    for j in range(max(Y - K - 1, 0), Y):
        sublist.append(A[i]+B[j])

sublist.sort()
subanslist = sublist[-K::1]
anslist = []

for i in subanslist:
    for j in range(max(Z - K - 1, 0), Z):
        anslist.append(i+C[j])

anslist.sort()
ans = anslist[:-K-1:-1]
for i in ans:
    print(i)

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
sublist = []
for i in range(max(X-K-1, 0), X):
    for j in range(max(Y - K - 1, 0), Y):
        if (X-i)*(Y-j) <= K:
            sublist.append(A[i]+B[j])

sublist.sort()
# print(sublist)
subanslist = sublist[-K::1]
sbsize = len(subanslist)
anslist = []
C.sort()

for num, i in enumerate(subanslist):
    for j in range(max(Z - K - 1, 0), Z):
        if (sbsize-num)*(Z-j) <= K:
            anslist.append(i+C[j])

anslist.sort()
ans = anslist[:-K-1:-1]
print(*ans, sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
sublist = []
for i in range(max(X-K-1, 0), X):
    for j in range(max(Y - K - 1, 0), Y):
        sublist.append(A[i]+B[j])

sublist.sort()
subanslist = sublist[-K::1]
anslist = []

for i in subanslist:
    for j in range(max(Z - K - 1, 0), Z):
        anslist.append(i+C[j])

anslist.sort()
for i in anslist[:-K-1:-1]:
    print(i)


Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
sublist = []
for i in range(max(X-K-1, 0), X):
    for j in range(max(Y - K - 1, 0), Y):
        if (X-i)*(Y-j) <= K:
            sublist.append(A[i]+B[j])

sublist.sort()
# print(sublist)
subanslist = sublist[-K::1]
sbsize = len(subanslist)
anslist = []
C.sort()

for num, i in enumerate(subanslist):
    for j in range(max(Z - K - 1, 0), Z):
        if (sbsize-num)*(Z-j) <= K:
            anslist.append(i+C[j])

anslist.sort()
ans = anslist[:-K-1:-1]
print(*ans, sep="\n")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
S = li()
Alist = []
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = mi()
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    if AClist[l[i] - 1] != AClist[l[i]]:
        print(AClist[r[i]] - AClist[l[i]])
    else:
        print(AClist[r[i]] - AClist[l[i]-1])


Fixed submission:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


b = input().rstrip()

if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
elif b == 'G':
    print('C')
Buggy python submission (verdict: Runtime Error):
N = int(input())
C = [int(input()) for _ in range(N)]
subC = [-2] * (2 * 10 ** 5)
cntC = [-1]*N
for num, i in enumerate(C):
    cntC[num] = subC[i]+1
    subC[i] = num

# print(cntC)

dp = [0] * (N + 10)
dp[0] = 1
for i in range(N):
    if cntC[i] == -1 or cntC[i] == i:
        dp[i + 1] = dp[i]
    else:
        dp[i + 1] = dp[i] + dp[cntC[i]]


print(dp[N])

Fixed submission:
N = int(input())
C = [int(input()) for _ in range(N)]
MOD = 10**9 + 7
subC = [-2] * (2 * 10 ** 5 + 10)
cntC = [-1]*N
for num, i in enumerate(C):
    cntC[num] = subC[i]+1
    subC[i] = num

# print(cntC)

dp = [0] * (N + 10)
dp[0] = 1
for i in range(N):
    if cntC[i] < 0 or cntC[i] == i:
        dp[i + 1] = dp[i] % MOD
    else:
        dp[i + 1] = (dp[i] + dp[cntC[i]]) % MOD


print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = [int(input()) for _ in range(N)]
strC = ''.join(map(str, C))
cntC = []
for num, i in enumerate(strC):
    try:
        cntC.append(strC[0:num].rindex(i) + 1)
    except ValueError:
        cntC.append(-1)
# print(cntC)

dp = [0] * (N + 10)
dp[0] = 1
for i in range(N):
    if cntC[i] == -1 or cntC[i] == i:
        dp[i + 1] = dp[i]
    else:
        dp[i + 1] = dp[i] + dp[cntC[i]]


print(dp[N])

Fixed submission:
N = int(input())
C = [int(input()) for _ in range(N)]
MOD = 10**9 + 7
subC = [-2] * (2 * 10 ** 5 + 10)
cntC = [-1]*N
for num, i in enumerate(C):
    cntC[num] = subC[i]+1
    subC[i] = num

# print(cntC)

dp = [0] * (N + 10)
dp[0] = 1
for i in range(N):
    if cntC[i] < 0 or cntC[i] == i:
        dp[i + 1] = dp[i] % MOD
    else:
        dp[i + 1] = (dp[i] + dp[cntC[i]]) % MOD


print(dp[N])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# BEGIN CUT HERE
class UnionFind():
    def __init__(self,n):
        self.data = [-1] * n
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.data[x] < self.data[y]:
            x, y = y, x  # swap
        self.data[x] += self.data[y]
        self.data[y] = x
    
    def find(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.find(self.data[x])
        return self.data[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.data[self.find(x)]
        
# END CUT HERE

def ABC120_D():
    n, m = mi()
    a = [0] * m
    b = [0] * m
    for i in range(m):
        a[i], b[i] = mi()
        
    uf = UnionFind(n)
    ans = [0] * (m + 1)
    ans[m] = n * (n - 1) // 2

    for i in range(m - 1, -1, -1):
        a[i] -= 1
        b[i] -= 1
        ans[i] = ans[i + 1]
        if uf.same(a[i], b[i]):
            continue
        
        x = uf.size(a[i])
        y = uf.size(b[i])
        ans[i] -= x * y
        
        uf.unite(a[i],b[i])
    
    for i in range(1, m + 1):
        print(ans[i])



if __name__ == '__main__':
    ABC120_D()


Fixed submission:
A,B,C = map(int,input().split())

if B>= A*C:
    print(C)
else:
    print(B//A)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# BEGIN CUT HERE
class UnionFind():
    def __init__(self,n):
        self.data = [-1] * n
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.data[x] < self.data[y]:
            x, y = y, x  # swap
        self.data[x] += self.data[y]
        self.data[y] = x
    
    def find(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.find(self.data[x])
        return self.data[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.data[self.find(x)]
        
# END CUT HERE

def ABC120_D():
    n, m = mi()
    a = [0] * m
    b = [0] * m
    for i in range(m):
        a[i], b[i] = mi()
        
    uf = UnionFind(n)
    ans = [0] * (m + 1)
    ans[m] = n * (n - 1) // 2

    for i in range(m - 1, -1, -1):
        a[i] -= 1
        b[i] -= 1
        ans[i] = ans[i + 1]
        if uf.same(a[i], b[i]):
            continue
        
        x = uf.size(a[i])
        y = uf.size(b[i])
        ans[i] -= x * y
        
        uf.unite(a[i],b[i])
    
    for i in range(1, m + 1):
        print(ans[i])



if __name__ == '__main__':
    ABC120_D()


Fixed submission:
from sys import stdin
class UnionFind:
    def __init__(self, n):
        # par[x]: x が根のときは x を含むグループのサイズ (の -1 倍)、そうでないときは親ノード
        self.par = [-1 for i in range(n + 1)]

    # 親ノードの検索
    def root(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    # 併合
    # x と y を同じグループにする, 計算量はならし O(α(n))
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x

    # x と y が同じグループにいるか, 計算量はならし O(α(n))
    def issame(self, x, y):
        return self.root(x) == self.root(y)

    # size(x): x を含むグループの所属メンバー数
    def size(self, x):
        return -self.par[self.root(x)]


if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    # print(Town.par)
    Island = UnionFind(N)
    A = [None]*M
    B = [None]*M
    cntlist = [0]*M
    cnt = N*(N-1)//2
    for i in range(M):
        A[i],B[i] = map(int,stdin.readline().rstrip('\n').split())
    # print(A,B)
    for i in range(M-1,0,-1):
        if Island.root(A[i]) == Island.root(B[i]):
            cntlist[i] = cnt
            continue
        else:
            cnt -= (Island.size(A[i]))*(Island.size(B[i]))
            Island.union(A[i],B[i])
        # for i in range(N+1):
        #     print(Island.size(i),end=',')
        # print()
        # print(cnt)
            cntlist[i] = cnt

    # print(Island.par)
    for i in range(1,M):
        print(cntlist[i])
    print(N*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
import bisect

f_inf = float('inf')


def cal(syurui, d, index):
    if d == 'e':
        return syurui[index]
    elif d == 'w':
        return syurui[index - 1]


A, B, Q = map(int, input().split())
s = [int(input()) for i in range(A)]
s.sort()
t = [int(input()) for i in range(B)]
t.sort()
ｓ.insert(0, -f_inf)
t.insert(0, -f_inf)
ｓ.append(f_inf)
t.append(f_inf)

for i in range(Q):
    x = int(input())
    s_index = bisect.bisect_left(s, x)
    t_index = bisect.bisect_left(t, x)
    print(min(max(abs(x-s[s_index]), abs(x-t[t_index])), max(abs(x-s[s_index-1]), abs(x-t[t_index-1])), 2*abs(x-s[s_index-1])+abs(x-t[t_index]), 2*abs(x-s[s_index])+abs(x-t[t_index-1]), abs(x-s[s_index-1])+2*abs(x-t[t_index]), abs(x-s[s_index])+2*abs(x-t[t_index-1])))


Fixed submission:
S = list(map(int, input().split('/')))

if 1 <= S[1] <= 4:
    print('Heisei')
elif S[1] == 4 and S[2] == 30:
    print('Heisei')
else:
    print('TBD')
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())

A = list(map(int,input().split()))
dp = [False for i in range(N+10)]
memo = [[] for i in range(N+10)]
taiou = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]
matchi = []
for i in range(1,10):
    if i in A:
        matchi.append(taiou[i-1])
matchi = sorted(matchi,key = lambda x:-x[0])
matchi = sorted(matchi,key = lambda x:x[1])
# for i in range(1,len(matchi)):
#     if matchi[i][1] == matchi[i-1][1]:

minma = matchi[0][1]
# print(matchi)
# print(minma)
# dp[0] = F
for i in range(len(matchi)):
    dp[matchi[i][1]] = True
    memo[matchi[i][1]].append(matchi[i][0])
for i in range(N):
    for j in range(len(matchi)):
        if dp[i-matchi[j][1]]:
            dp[i] = True
            memo[i] = memo[i] + memo[i-matchi[j][1]]
            memo[i].append(matchi[j][0])
            break
# print(dp)
# print(memo)
maxi = N
for i in range(N//minma,0,-1):
    if dp[N-i*minma]:
        maxi = i
        # print(maxi)
        break

ans = sorted([matchi[0][0]]*maxi + memo[N-maxi*minma],reverse = True)
for i in range(len(ans)):
    print(ans[i],sep='',end='')
print('')


Fixed submission:
A,B = map(int,input().split())
# N = int(input())
if B%A == 0:
    print(A+B)
else:
    print(B-A)

Buggy python submission (verdict: Runtime Error):
import bisect

f_inf = float('inf')


def cal(syurui, d, index):
    if d == 'e':
        return syurui[index]
    elif d == 'w':
        return syurui[index - 1]


A, B, Q = map(int, input().split())
s = [int(input()) for i in range(A)]
s.sort()
t = [int(input()) for i in range(B)]
t.sort()

for i in range(Q):
    x = int(input())
    s_index = bisect.bisect_left(s, x)
    t_index = bisect.bisect_left(t, x)
    if s_index == len(s) and t_index == len(t):
        print(max(abs(x-s[s_index-1]), abs(x-t[t_index-1])))
    elif s_index == len(s):
        ｓ.insert(0, -f_inf)
        t.insert(0, -f_inf)
        print(min(max(abs(x-s[s_index]), abs(x-t[t_index])),
                  2*abs(x-s[s_index])+abs(x-t[t_index+1]), abs(x-s[s_index])+2*abs(x-t[t_index+1])))
    elif t_index == len(t):
        ｓ.insert(0, -f_inf)
        t.insert(0, -f_inf)
        print(min(max(abs(x-s[s_index]), abs(x-t[t_index])), 2*abs(x-s[s_index+1])+abs(x-t[t_index]),
                  abs(x-s[s_index+1])+2*abs(x-t[t_index])))
    else:
        ｓ.insert(0, -f_inf)
        t.insert(0, -f_inf)
        print(min(max(abs(x-s[s_index]), abs(x-t[t_index])), max(
            abs(x-s[s_index+1]), abs(x-t[t_index+1])), 2*abs(x-s[s_index+1])+abs(x-t[t_index]), 2*abs(x-s[s_index])+abs(x-t[t_index+1]), abs(x-s[s_index+1])+2*abs(x-t[t_index]), abs(x-s[s_index])+2*abs(x-t[t_index+1])))


Fixed submission:
A,B = map(int,input().split())
# N = int(input())
if B%A == 0:
    print(A+B)
else:
    print(B-A)
Buggy python submission (verdict: Runtime Error):
N = int(input())
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
numbers = list(map(int,input().split()))

print(gcd_list(numbers))

Fixed submission:
N = int(input())
import math
#ユークリッド互除法の関数の定義
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
x = list(map(int,input().split()))

if N==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if N==2:print(element)
    else:
        for i in range(2,N):
            element=gcd(element,x[i])
        print(element)

# print(gcd_list(numbers))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
# N = input()   # 単純な入力
# input = list(input()) # ひとかたまりの文字列をリスト化
# N = int(input())  # 整数一つ
# input = input().split()   # スペース区切りを文字としてリスト化
# X,Y = map(int,input().split())  # ２個や３個の整数をそれぞれ取得
# input = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sa = [A[i] - B[i] for i in range(len(A))]
sa.sort()
# print(sa)
insert_index = bisect.bisect_left(sa,0)
# print(insert_index)
Sum = sum(sa[0:insert_index])

for i in range(len(sa),insert_index-1,-1):
    # print(i)
    # print(sa[len(sa)-1:i-1:-1])
    if abs(Sum) <= sum(sa[N:i-1:-1]):
        print(insert_index - 1 + N - i + 1)
        exit()
print(-1)

Fixed submission:
import bisect
# N = input()   # 単純な入力
# input = list(input()) # ひとかたまりの文字列をリスト化
# N = int(input())  # 整数一つ
# input = input().split()   # スペース区切りを文字としてリスト化
# X,Y = map(int,input().split())  # ２個や３個の整数をそれぞれ取得
# input = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sa = [A[i] - B[i] for i in range(len(A))]
sa.sort()
# print(sa)
insert_index = bisect.bisect_left(sa,0)
# print(insert_index)
Sum = sum(sa[0:insert_index])
Sumlist = [0 for i in range(N)]
isum = 0

if Sum == 0:
    print(0)
    exit()

for i in range(len(sa),insert_index-1,-1):
    isum = isum + sa[i-1]
    if abs(Sum) <= isum:
        print(insert_index + N - i + 1)
        exit()
    elif sa[i-2] <= 0:
        print(-1)
        exit()
Buggy python submission (verdict: Runtime Error):
N = int(input())

if n == 3:
  print("YES")
elif n == 5:
  print("YES")
elif n == 7:
  print("YES")

Fixed submission:
N = int(input())

if N == 3:
    print("YES")
elif N == 5:
    print("YES")
elif N == 7:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
  N = int(input())
  minus_bit = ''
  if N == 0:
      minus_bit = '00'
  while N != 0:
      mod = N % 4
      if mod == 0:
          minus_bit = minus_bit + '00'
          N = N//4
      elif mod == 1:
          minus_bit = minus_bit + '10'
          N = (N-1)//4
      elif mod == 2:
          minus_bit = minus_bit + '01'
          N = (N+2)//4
      else:
          minus_bit = minus_bit + '11'
          N = (N+1)//4

  if minus_bit[-1] == '0':
      minus_bit = minus_bit[:-1]
  print(minus_bit[::-1])

Fixed submission:
N = int(input())
minus_bit = ''
if N == 0:
    minus_bit = '00'
while N != 0:
    mod = N % 4
    if mod == 0:
        minus_bit = minus_bit + '00'
        N = N//4
    elif mod == 1:
        minus_bit = minus_bit + '10'
        N = (N-1)//4
    elif mod == 2:
        minus_bit = minus_bit + '01'
        N = (N+2)//4
    else:
        minus_bit = minus_bit + '11'
        N = (N+1)//4

if minus_bit[-1] == '0':
    minus_bit = minus_bit[:-1]
print(minus_bit[::-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
Asort = sorted([A[i]-i-1 for i in range(N)])

if N%2 == 0:
    b_tmp = Asort[N//2]
else:
    b_tmp = (Asort[N//2] + Asort[N//2 + 1])// 2
# print(b_tmp)
minA = 10**9
for b in range(b_tmp-1,b_tmp+2):
    submin = [abs(A[i]-b-i-1) for i in range(N)]
    # print(submin)
    minA = min(sum(submin),minA)

print(minA)

Fixed submission:
from statistics import median

N = int(input())
A = list(map(int,input().split()))
Asort = sorted([A[i]-i-1 for i in range(N)])
# print(Asort)

b_tmp = int(median(Asort))

submin = [abs(A[i]-b_tmp-i-1) for i in range(N)]
# print(submin)
minA = sum(submin)

print(minA)

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

minA = 10**9

for b in range(min(A)-10,max(A)+N):
    submin = [abs(A[i]-b-i-1) for i in range(N)]
    # print(submin)
    minA = min(sum(submin),minA)

print(minA)

Fixed submission:
from statistics import median

N = int(input())
A = list(map(int,input().split()))
Asort = sorted([A[i]-i-1 for i in range(N)])
# print(Asort)

b_tmp = int(median(Asort))

submin = [abs(A[i]-b_tmp-i-1) for i in range(N)]
# print(submin)
minA = sum(submin)

print(minA)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())

dp = [10**7 for i in range(100000)]
dp[0] = 0

for i in range(1,N+1):
    dp[i] = min(dp[i-1]+1,min([dp[i-pow(6,j)]+1 for j in range(int(math.log(i,6)+1))]),min([dp[i-pow(9,j)]+1 for j in range(int(math.log(i,9))+1)]))

print(dp[N])

Fixed submission:
import math
N = int(input())

dp = [10**7 for i in range(100010)]
dp[0] = 0

for i in range(1,N+1):
    dp[i] = min(dp[i-1]+1,min([dp[i-pow(6,j)]+1 for j in range(int(math.log(i,6)+1))]),min([dp[i-pow(9,j)]+1 for j in range(int(math.log(i+10**(-10),9))+1)]))

print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
numS = [0 for i in range(N)]
for i in range(N):
    if S[i] == 'E':
        numS[i] = 0
    else:
        numS[i] = 1
# print(numS)
minS = N
for i in range(N):
    numT = [0 for j in range(i)] + [numS[i]] + [1 for j in range(i+1,N)]
    # print(numT)
    minS = min(minS,sum([abs(numT[i]-numS[i]) for i in range(N)]))

print(minS)

Fixed submission:
N = int(input())
S = list(input())
numS = [0 for i in range(N)]
sumS = [0 for i in range(N)]
for i in range(N):
    if S[i] == 'E':
        numS[i] = 0
    else:
        numS[i] = 1

for i in range(N):
    sumS[i] = sumS[i-1] + numS[i]
# print(sumS)
minS = (N-1) - (sumS[N-1]-sumS[0])
for i in range(1,N):
    minS = min(minS,sumS[i-1]+(N-i-1)-(sumS[N-1]-sumS[i]))
print(minS)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
if K > 50:
    print(0)
    exit()
sub = {s[i:j] for i in range(len(s)+1) for j in range(i+1,len(s)+1)}
sub = sorted(sub)
print(sub[K-1])

Fixed submission:
s = input()
K = int(input())
# if K > 50:
#     print(0)
#     exit()
sub = {s[i:j] for i in range(len(s)) for j in range(i+1,i+K+1)}
sub = sorted(sub)
print(sub[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())

sub = [i for i in range(A,B+1) if A<= i<= A+K-1 or B-K+1 <= i <= B]
for i in sub:
    print(i)

Fixed submission:
A,B,K = map(int,input().split())

sub1 = [i for i in range(A,A+K)]
sub2 = [i for i in range(B-K+1,B+1)]
sub = set(sub1) | set(sub2)
sub = sorted(sub)
for i in sub:
    if A<= i <= B:
        print(i)