Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
H = list(map(int,input().split()))

d = []
for i in range(M):
    A,B = map(int,input().split())
    d.append((A-1,B-1))

cnt = 0
#res = {}
#for i in range(N):
#    res[i] = False
flag = {}
for i in range(N):
    flag[i] = True

for i in d:
    A = i[0]
    B = i[1]
    #print("H[A] > H[B]",H[A],H[B])
    if H[A] > H[B] and flag[A] == True:
        #res[A] = True
    else:
        flag[A] = False
        #res[A] = False
    #print("H[A] < H[B]",H[A],H[B])
    if H[B] > H[A] and flag[B] == True:
        #res[B] = True
    else:
        flag[B] = False
        #res[B] = False
print(list(flag.values()).count(True))

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

d = []
for i in range(M):
    A,B = map(int,input().split())
    d.append((A-1,B-1))

cnt = 0
res = {}
for i in range(N):
    res[i] = False
flag = {}
for i in range(N):
    flag[i] = True

for i in d:
    A = i[0]
    B = i[1]
    #print("H[A] > H[B]",H[A],H[B])
    if H[A] > H[B] and flag[A] == True:
        res[A] = True
    else:
        flag[A] = False
        res[A] = False
    #print("H[A] < H[B]",H[A],H[B])
    if H[B] > H[A] and flag[B] == True:
        res[B] = True
    else:
        flag[B] = False
        res[B] = False
print(list(flag.values()).count(True))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

for i in range(N):
    print(A.count(i+1))

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

res = [0]*N

for i in range(N-1):
    res[A[i]-1] += 1

for i in res:
    print(i)

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

for i in range(N):
    print(A.count(i+1))

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

res = [0]*N

for i in range(N-1):
    res[A[i]-1] += 1

for i in res:
    print(i)
Buggy python submission (verdict: Runtime Error):
min = 0
result = 100000000
for i in range(100):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    result = 0

print(min)

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

min = 1000000
result = 0
for i in range(100):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    result = 0

print(min)
Buggy python submission (verdict: Runtime Error):
def main():
    N,K = list(map(int,input().split()))
    H = list(map(int,input().split()))

    sorted_H = sorted(H,reverse=True)

    for i in range(K):
        sorted_H[i] = 0
    '''
    for _ in range(K):
        if(len(H) > 0):
            maximum = max(H)
            H.remove(maximum)
            '''

    print(sum(sorted_H))

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N,K = list(map(int,input().split()))
    H = list(map(int,input().split()))

    sorted_H = sorted(H,reverse=True)

    for i in range(K):
        if(i < len(sorted_H)):
            sorted_H[i] = 0

    '''
    for _ in range(K):
        if(len(H) > 0):
            maximum = max(H)
            H.remove(maximum)
            '''

    print(sum(sorted_H))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,K = list(map(int,input().split()))
    H = list(map(int,input().split()))

    for _ in range(K):
        if(len(H) > 0):
            maximum = max(H)
            H.remove(maximum)

    print(sum(H))

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N,K = list(map(int,input().split()))
    H = list(map(int,input().split()))

    sorted_H = sorted(H,reverse=True)

    for i in range(K):
        if(i < len(sorted_H)):
            sorted_H[i] = 0

    '''
    for _ in range(K):
        if(len(H) > 0):
            maximum = max(H)
            H.remove(maximum)
            '''

    print(sum(sorted_H))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    K,X = list(map(int,input().split()))
    if(500*k > X):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    K,X = list(map(int,input().split()))

    price = 500 * K
    if(price >= X):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
A = list(input() for _ in range(Q))
points = [K for _ in range(N)]

for i in A:
    points = list(map(lambda x:x-1,points))
    points[int(i)-1] += 1

for i in points:
    if(i > 0):
        print('Yes')
    else:
        print('No')


Fixed submission:
N,K,Q = map(int,input().split())
A = list(input() for _ in range(Q))
points = [K for _ in range(N)]

points = list(map(lambda x:x-Q,points))

for i in A:
    points[int(i)-1] += 1

for i in points:
    if(i > 0):
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int,input().split()))

maximum = 0
cnt = 0

for i in range(len(H)):
    k = H[i]
    res = H[i+1:]
    for j in res:
        if(j <= k):
            cnt += 1
            k = j
        else:
            break
        maximum = max(maximum,cnt)
        #if(max < cnt):
        #    max = cnt
    cnt = 0

print(maximum)

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

ans = 0
tmp = 0

for i in range(N-1):
    if(H[i] < H[i+1]):
        #ans = max(ans,tmp)
        tmp = 0
    else:
        tmp += 1
    ans = max(ans,tmp)

print(ans)

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

max = 0
cnt = 0

for i in range(len(H)):
    k = H[i]
    res = H[i+1:]
    for j in res:
        if(j <= k):
            cnt += 1
            k = j
        else:
            break
        if(max < cnt):
            max = cnt
    cnt = 0

print(max)


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

ans = 0
tmp = 0

for i in range(N-1):
    if(H[i] < H[i+1]):
        #ans = max(ans,tmp)
        tmp = 0
    else:
        tmp += 1
    ans = max(ans,tmp)

print(ans)

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

max = 0
cnt = 0

for i in range(len(H)):
    k = H[i]
    res = H[i+1:]
    for j in res:
        if(j <= k):
            cnt += 1
            k = j
        else:
            break
        if(max < cnt):
            max = cnt
    cnt = 0

print(max)


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

ans = 0
tmp = 0

for i in range(N-1):
    if(H[i] < H[i+1]):
        #ans = max(ans,tmp)
        tmp = 0
    else:
        tmp += 1
    ans = max(ans,tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if(l[i] == l[j]):
            cnt += 1
print(cnt)

Fixed submission:
d,a = {},0
for i in range(int(input())):
    k = ''.join(sorted(input()))
    d[k] = d.get(k,-1)+1
    a+= d[k]
print(a)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(N):
    for j in range(i+1,N:
        if(l[i] == l[j]):
            cnt += 1
print(cnt)


Fixed submission:
d,a = {},0
for i in range(int(input())):
    k = ''.join(sorted(input()))
    d[k] = d.get(k,-1)+1
    a+= d[k]
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(len(l)):
    for j in range(i+1,len(l)):
        #if(i != j):
            if(l[i] == l[j]):
                cnt += 1
print(cnt)

Fixed submission:
d,a = {},0
for i in range(int(input())):
    k = ''.join(sorted(input()))
    d[k] = d.get(k,-1)+1
    a+= d[k]
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(len(l)):
    for j in range(i,len(l)):
        if(i != j):
            #print(i,",",j)
            if(l[i] == l[j]):
                cnt += 1
print(cnt)

Fixed submission:
d,a = {},0
for i in range(int(input())):
    k = ''.join(sorted(input()))
    d[k] = d.get(k,-1)+1
    a+= d[k]
print(a)
Buggy python submission (verdict: Runtime Error):
result = 0
if(0<N<=pow(10,5)):
    if len(str(N)) % 2 == 0:
        loop = ((len(str(N)) - 1) -1) //2 + 1
        for i in range(loop):
            result += 9 * pow(10,2*i)
    else:
        for i in range(len(str(N)) - 2):
            result += 9 * pow(10,i)
        result += N - pow(10,len(str(N)) - 1) + 1

print(result)

Fixed submission:
N = int(input())

print(sum(len(str(i)) % 2 for i in range(1,N+1)))

Buggy python submission (verdict: Runtime Error):
N = int(input())

result = 0
if(0<N<=pow(10,5))
    if len(str(N)) % 2 == 0:
        loop = ((len(str(N)) - 1) -1) //2 + 1
        for i in range(loop):
            result += 9 * pow(10,2*i)
    else:
        for i in range(len(str(N)) - 2):
            result += 9 * pow(10,i)
        result += N - pow(10,len(str(N)) - 1) + 1

print(result)

Fixed submission:
N = int(input())

print(sum(len(str(i)) % 2 for i in range(1,N+1)))
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    tmp = A[i]
    A[i] = -1
    print(sorted(A,reverse=True)[0])
    A[i] = tmp

Fixed submission:
import copy

N = int(input())
A = [int(input()) for _ in range(N)]

res = sorted(A,reverse=True)
for i in range(N):
    if A[i] == res[0]:
        print(res[1])
    else:
        print(res[0])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    tmp = A[i]
    A[i] = -1
    print(max(A))
    A[i] = tmp

Fixed submission:
import copy

N = int(input())
A = [int(input()) for _ in range(N)]

res = sorted(A,reverse=True)
for i in range(N):
    if A[i] == res[0]:
        print(res[1])
    else:
        print(res[0])

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    tmp = copy.copy(A)
    tmp.remove(A[i])
    print(max(tmp))

Fixed submission:
import copy

N = int(input())
A = [int(input()) for _ in range(N)]

res = sorted(A,reverse=True)
for i in range(N):
    if A[i] == res[0]:
        print(res[1])
    else:
        print(res[0])

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    tmp = copy.deepcopy(A)
    tmp.remove(A[i])
    print(max(tmp))    


Fixed submission:
import copy

N = int(input())
A = [int(input()) for _ in range(N)]

res = sorted(A,reverse=True)
for i in range(N):
    if A[i] == res[0]:
        print(res[1])
    else:
        print(res[0])
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())

res = []
for i in range(L,R):
    for j in range(L+1,R+1):
        res.append((i*j)%2019)
print(min(res))

Fixed submission:
L,R = map(int,input().split())
m = R - L
if(m >= 2019):
    print(0)
else:
    res = []
    for i in range(L,R):
        for j in range(L+1,R+1):
            res.append((i*j)%2019)
    print(min(res))
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D = map(int,input().split())

cnt = 0
for i in range(A,B+1):
    if(i%C != 0 and i%D != 0):
        cnt += 1
print(cnt)

Fixed submission:
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a

def multiple(a, b):
    return a*b // euclid(a, b)

A,B,C,D = map(int,input().split())

all = B - A + 1
x = B//C - (A-1)//C
y = B//D - (A-1)//D
lcm = multiple(C,D)
z = B//lcm - (A-1)//lcm

print(all - x - y + z)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]

MOD = 1000000007

d = [0] * (N+1)
NG = [FALSE]*N
d[0] = 1
if(1 in a):
    d[1] = 0
else:
    d[1] = 1

for i in range(M):
    NG[i] = True


for i in range(2,N+1):
    if(NG[i-1] == False):
        d[i] = d[i-1] + d[i-2]
        d[i] %= MOD
    '''
    if(i in a):
        d[i] = 0
    else:
        d[i] = d[i-1] + d[i-2]
    d[i] %= MOD
    '''

print(d[-1])

Fixed submission:
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]

MOD = 1000000007

d = [0] * (N+1)
OK = [True]*(N+1)
d[0] = 1

for i in range(M):
    OK[a[i]] = False

#print(OK)

if(OK[1]):
    d[1] = 1
else:
    d[1] = 0

for i in range(2,N+1):
    if(OK[i-1]):
        d[i] += d[i-1]
    if(OK[i-2]):
        d[i] += d[i-2]
    d[i] %= MOD
    '''
    if(i in a):
        d[i] = 0
    else:
        d[i] = d[i-1] + d[i-2]
    d[i] %= MOD
    '''

print(d[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]


MOD = 1000000007

d = [0] * (N+1)
d[0] = 1
if(1 in a):
    d[1] = 0
else:
    d[1] = 1

for i in range(2,N+1):
    if(i in a):
        d[i] = 0
    else:
        d[i] = d[i-1] + d[i-2]
    d[i] %= MOD

print(d[-1])


Fixed submission:
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]

MOD = 1000000007

d = [0] * (N+1)
OK = [True]*(N+1)
d[0] = 1

for i in range(M):
    OK[a[i]] = False

#print(OK)

if(OK[1]):
    d[1] = 1
else:
    d[1] = 0

for i in range(2,N+1):
    if(OK[i-1]):
        d[i] += d[i-1]
    if(OK[i-2]):
        d[i] += d[i-2]
    d[i] %= MOD
    '''
    if(i in a):
        d[i] = 0
    else:
        d[i] = d[i-1] + d[i-2]
    d[i] %= MOD
    '''

print(d[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]


MOD = 1000000007

d = [0] * (N+1)
d[0] = 1
if(1 in a):
    d[1] = 0
else:
    d[1] = 1

for i in range(2,N+1):
    if(i in a):
        d[i] = 0
    else:
        d[i] = d[i-1] + d[i-2]
    d[i] %= MOD

print(d[-1])


Fixed submission:
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]

MOD = 1000000007

d = [0] * (N+1)
OK = [True]*(N+1)
d[0] = 1

for i in range(M):
    OK[a[i]] = False

#print(OK)

if(OK[1]):
    d[1] = 1
else:
    d[1] = 0

for i in range(2,N+1):
    if(OK[i-1]):
        d[i] += d[i-1]
    if(OK[i-2]):
        d[i] += d[i-2]
    d[i] %= MOD
    '''
    if(i in a):
        d[i] = 0
    else:
        d[i] = d[i-1] + d[i-2]
    d[i] %= MOD
    '''

print(d[-1])
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input())

if(A>=13):
    print(B)
elif(6<=A<=12):
    print(B//2)
else:
    print(0)

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

if(A>=13):
    print(B)
elif(6<=A<=12):
    print(B//2)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())

d = []
for i in range(M):
    L,R = map(int,input().split())
    d += list(range(L,R+1))

res = [x for x in set(d) if d.count(x) == M]
print(len(res))

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

L_list = []
R_list = []

for i in range(M):
    L,R = map(int,input().split())
    L_list.append(L)
    R_list.append(R)

l = max(L_list)
r = min(R_list)

if(l > r):
    print(0)
else:
    print(r-l+1)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))
'''
res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    res = max(ans,res)
print(res)
'''

L = [0] * N
R = [0] * N

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i],R[i+1]))

print(ans)

Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))
'''
res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    res = max(ans,res)
print(res)
'''

L = [0] * (N+1)
R = [0] * (N+1)

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i],R[i+1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

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

res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    if(res < ans):
        res = ans
print(res)

Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))
'''
res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    res = max(ans,res)
print(res)
'''

L = [0] * (N+1)
R = [0] * (N+1)

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i],R[i+1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

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

res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    #print(tmp)
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    if(res < ans):
        res = ans
    #print(ans)
print(res)

Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))
'''
res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    res = max(ans,res)
print(res)
'''

L = [0] * (N+1)
R = [0] * (N+1)

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i],R[i+1]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
ques = []
for i in range(Q):
    l,r = map(int,input().split())
    ques.append((l,r))

for i in ques:
    tmp = S[i[0]-1:i[1]]
    tmp_s = ''.join(tmp)
    print(tmp_s.count('AC'))

Fixed submission:
N,Q = map(int,input().split())
S = input()
l = [0] * Q
r = [0] * Q

for i in range(Q):
    l[i],r[i] = map(int,input().split())

cs = [0]*(N+1)
for i in range(N-1):
    if(S[i] == 'A' and S[i+1] == 'C'):
        cs[i+2] = cs[i+1] + 1
    else:
        cs[i+2] = cs[i+1]
for q in range(Q):
    print(cs[r[q]] - cs[l[q]])
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())

cnt = 0
while True:
    if(S == []):
        break
    for i in range(len(S)-1):
        if(S[i] == '0' and S[i+1] == '1') or (S[i] == '1' and S[i+1] == '0'):
            S = S[:i] + S[i+2:]
            #print(S)
            cnt += 2
            break
    else:
        break
print(cnt)

Fixed submission:
S = list(input())

blue = S.count('1')
red = len(S) - blue

n = min(blue,red)

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

tmp = A[0]
while True:
    if(len(A) == 1):
        break
    for i in range(len(A)-1,0,-1):
        A[i] = A[i] - (A[i]//tmp)*tmp
        if 0 in A:
            A.remove(0)
    else:
        A.sort()
        tmp = A[0]
print(A[0])

Fixed submission:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd,A))
Buggy python submission (verdict: Runtime Error):
import sys

N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))

if N >= M:
    print(0)
    
s= [0]*(M-1)
for i in range(M-1):
    s[i] = X[i+1] - X[i]
s.sort(reverse=True)
res = sum(s)
if M == 1:
    res = 0
else:
    for i in range(N-1):
        res -= s[i]
print(res)

Fixed submission:
import sys

N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))

if N >= M:
    print(0)
    sys.exit()
    
s= [0]*(M-1)
for i in range(M-1):
    s[i] = X[i+1] - X[i]
s.sort(reverse=True)
res = sum(s)
if M == 1:
    res = 0
else:
    for i in range(N-1):
        res -= s[i]
print(res)

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

N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))

s= [0]*(M-1)
for i in range(M-1):
    s[i] = X[i+1] - X[i]
s.sort(reverse=True)
res = sum(s)
if M == 1:
    res = 0
else:
    for i in range(N-1):
        res -= s[i]
print(res)

Fixed submission:
import sys

N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))

if N >= M:
    print(0)
    sys.exit()
    
s= [0]*(M-1)
for i in range(M-1):
    s[i] = X[i+1] - X[i]
s.sort(reverse=True)
res = sum(s)
if M == 1:
    res = 0
else:
    for i in range(N-1):
        res -= s[i]
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]

res = 10**10
for i in combinations(h,K):
    tmp = max(i) - min(i)
    res = min(res,tmp)
print(res)

Fixed submission:
from itertools import combinations

N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]

'''
res = 10**10
for i in combinations(h,K):
    tmp = max(i) - min(i)
    res = min(res,tmp)
'''

d = sorted(h)
res = 1e+9
for i in range(N-K+1):
    res = min(res,d[i+K-1] - d[i])
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=1
for i in sorted(res):
    x = str(i[0])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if(tmp in d):
        c+=1
    else:
        c = 1
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Fixed submission:
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=0
res.sort()
t = str(res[0][0])
for i in res:
    x = str(i[0])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if x == t:
        c+=1
    else:
        c=1
        t = x
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=1
for i in sorted(res):
    x = str(i[0])
    y = str(i[1])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if(tmp in d):
        c+=1
        d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    else:
        c = 1
        d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Fixed submission:
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=0
res.sort()
t = str(res[0][0])
for i in res:
    x = str(i[0])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if x == t:
        c+=1
    else:
        c=1
        t = x
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
S = sorted(list(input()))
T = sorted(list(input()))

tmp = copy.copy(S)
for i in tmp:
    if i in T:
        S.remove(i)
        T.remove(i)
if len(set(S)) == len(set(T)):
    print('Yes')
else:
    print('No')

Fixed submission:
from collections import Counter
S = sorted(list(input()))
T = sorted(list(input()))

if Counter(Counter(S).values()) == Counter(Counter(T).values()):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
R = int(input())

if R < 1200:
    print('ABC')
elif 1200 <= R < 2800
    print('ARC')
else:
    print('AGC')

Fixed submission:
R = int(input())

if R < 1200:
    print('ABC')
elif 1200 <= R < 2800:
    print('ARC')
else:
    print('AGC')