Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
N=int(input())
D = list(map(int, input().split()))
M=int(input())
T = list(map(int, input().split()))
new_D=sorted(D)
new_T=sorted(T)
#print(new_D[0])
for i in range(len(T)):
    if new_D.count(new_T[i])==0:
        print("NO")
        sys.exit()
    if new_D.count(new_T[i])>=1:
        new_D.remove(new_T[i])
        #print(new_D.count(new_T[i]))
    
print("YES")

Fixed submission:
import math
import sys
import collections 
N=int(input())
D = list(map(int, input().split()))
M=int(input())
T = list(map(int, input().split()))
new_D=sorted(D)
new_T=sorted(T)
a=collections.Counter(new_D)
b=collections.Counter(new_T)
#print(a[10])
#print(new_D[0])
for i in new_T:
    if a[i]<b[i]:
        print("NO")
        sys.exit()
    
    
print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
flag = 0
c = 0

for i in range(1,n):
    flag = 0
    c = 0
    for j in range(1,i+1):
        if i % j == 0:
            if i / j == j:
                c *= 2
                c += 1
                ans += c
                break
            if j == flag:
                c *= 2
                ans += c
                break
            flag = j
            c += 1
    else:
        ans += c
        
print(ans)

Fixed submission:
import collections

zzz = 1
nn = int(input())
ans = 0

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in range(1,nn):
    zzz = 1
    cc = collections.Counter(prime_factorize(i))
    hoge = cc.values()
    for aaa in hoge:
        zzz *= aaa + 1
    ans += zzz
   
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

for i in range(1,n):
    hoge = n - i
    for j in range(1,hoge+1):
        if hoge % j == 0:
            ans += 1

print(ans)

Fixed submission:
import collections

zzz = 1
nn = int(input())
ans = 0

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in range(1,nn):
    zzz = 1
    cc = collections.Counter(prime_factorize(i))
    hoge = cc.values()
    for aaa in hoge:
        zzz *= aaa + 1
    ans += zzz
   
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

mm = 7
ans = 0
for i in range(10**6):
    ans += 1
    if mm%K==0:
        print(ans)
        break
    mm = mm*10 +7

else:
    print(-1)

Fixed submission:
K = int(input())

mm = 7
cnt = 1
for i in range(10**7):
    if mm%K==0:
        print(cnt)
        break
    else:
        mm = mm*10+7
        mm %= K
        cnt += 1
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import math

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

m = 0
M = max(A)

while(M-m>0):
    mm = 0

    mid = (M+m)//2
    for i in range(N):
        mm += math.ceil(A[i]/mid)-1

    if mm>K:
        m = mid+1
    else:
        M = mid

print(math.ceil(m))




Fixed submission:
import math

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

m = 1
M = max(A)

while(M-m>0):
    mm = 0

    mid = (M+m)//2
    for i in range(N):
        mm += math.ceil(A[i]/mid)-1

    if mm>K:
        m = mid+1
    else:
        M = mid

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

def main():
    for k in range(K):
        li = [0 for i in range(N+1)]
        rsl = [0 for i in range(N+1)]


        for i in range(N):
            if A[i] != 0:
                li[max(0,i-A[i])]+= 1
                li[min(N,i+A[i]+1)]-= 1
        
        mm = 0
        for i in range(N):
            mm += li[i]
            if A[i]>0:
                A[i] = mm
            else:
                A[i] = mm +1
        # print(A)

        if min(A)>=N:
            break
    print(*A)



main()



    





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

def main():
    for k in range(K):
        li = [0 for i in range(N+1)]
        rsl = [0 for i in range(N+1)]


        for i in range(N):
            if A[i] != 0:
                li[max(0,i-A[i])]+= 1
                li[min(N,i+A[i]+1)]-= 1
        
        mm = 0
        for i in range(N):
            mm += li[i]
            if A[i]>0:
                A[i] = mm
            else:
                A[i] = mm +1
        # print(A)

        if min(A)>=N:
            break
    print(*A)



main()
Buggy python submission (verdict: Runtime Error):
import math

A,B,H,M = map(int,input().split())

H = (H*360/12)+(M*30/60)
M = M*360/60

a = abs(H-M)
# print(a)
ans = math.sqrt((A**2)+(B**2)-2*A*B*math.cos(math.radians(a)))
print(ans)

mm = (A**2+B**2-(4.56425719433**2))/(2*A*B)
# print(mm)
mm = math.acos(mm)
mm = math.degrees(mm)
# print(mm)


Fixed submission:
import math

A,B,H,M = map(int,input().split())

H = (H*360/12)+(M*30/60)
M = M*360/60

a = abs(H-M)
# print(a)
ans = math.sqrt((A**2)+(B**2)-2*A*B*math.cos(math.radians(a)))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

li1 = [i+1-A[i] for i in range(N)]
li2 = [A[i]+i+1 for i in range(N)]

cnt = [0 for i in range(2*N+1)]
for i in li2:
    cnt[i] += 1

ans = 0
for i in li1:
    if i>=0:
        ans += cnt[i]
print(ans)







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

li1 = [i+1-A[i] for i in range(N)]
li2 = [A[i]+i+1 for i in range(N)]

cnt = [0 for i in range(2*N+1)]
for i in li2:
    if i<len(cnt)-1:
        cnt[i] += 1

ans = 0
for i in li1:
    if i>=0:
        ans += cnt[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
li = [0 for _ in range(K)]

mod = 10**9+7
ans = 0
for i in range(K,0,-1):
    mm = K//i
    mm = mm**N

    for j in range(2,(K//i)+1):
        mm -= li[i*j-1]    
    li[i-1] = mm


    ans += i*mm
    ans %= mod

print(ans)

Fixed submission:
#!/usr/bin/env python3

def pow(N,R,mod):
    ans = 1
    i = 0
    while((R>>i)>0):
        if (R>>i)&1:
            ans *= N
            ans %= mod
        N = (N*N)%mod
        i += 1
    return ans%mod


def main():
    N,K = map(int,input().split())
    li = [0 for _ in range(K)]

    mod = 10**9+7
    ans = 0
    for i in range(K,0,-1):
        mm = K//i
        mm = pow(mm,N,mod)

        for j in range(2,(K//i)+1):
            mm -= li[i*j-1]    
        li[i-1] = mm


        ans += (i*mm)%mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

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

mod = 10**9+7
ans = 0
for i in range(K,0,-1):
    mm = K//i
    mm = mm**N

    for j in range(2,K//i+1):
        mm -= li[i*j-1]    
    li[i-1] = mm


    ans += i*mm
    ans %= mod

print(ans)

Fixed submission:
#!/usr/bin/env python3

def pow(N,R,mod):
    ans = 1
    i = 0
    while((R>>i)>0):
        if (R>>i)&1:
            ans *= N
            ans %= mod
        N = (N*N)%mod
        i += 1
    return ans%mod


def main():
    N,K = map(int,input().split())
    li = [0 for _ in range(K)]

    mod = 10**9+7
    ans = 0
    for i in range(K,0,-1):
        mm = K//i
        mm = pow(mm,N,mod)

        for j in range(2,(K//i)+1):
            mm -= li[i*j-1]    
        li[i-1] = mm


        ans += (i*mm)%mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

# hd = []
# bc = []
# cnt = 0

for i in range(Q):
    q = list(input().split())

    if q[0]=="1":
        S.reverse()
    else:
        f = int(q[1])
        c = list(q[2])

        if f%2==0:
            S = S+c
        else:
            S = c+S
    # print(S)


    # if q[0]=="1":
    #     hd,bc = bc,hd
    #     cnt += 1
    
    # elif q[0]=="2":
    #     f = int(q[1])
    #     c = q[2]

    #     if f%2==0:
    #         bc.append(c)
    #     else:
    #         hd.append(c)
    # print(hd,bc)

# ans = hd + S + bc

for i in range(len(S)):
    print(S[i],end="")
print()











Fixed submission:
from collections import deque

S = list(input())
Q = int(input())

d = deque(S)

hd = []
bc = []
cnt = 0
mm = 0

for i in range(Q):
    q = list(input().split())

    if q[0]=="1":
        cnt += 1
    
# f:奇数 cnt:偶数 先頭    
# f:奇数 cnt:奇数 後方    
# f:偶数 cnt:偶数 後方
# f:奇数 cnt:偶数 先頭
#   
    elif q[0]=="2":
        f = int(q[1])
        c = q[2]
        mm += 1

        if (f+cnt)%2==0:
            d.append(c)
        else:
            d.appendleft(c)

if cnt%2==0:
    for i in range(len(S)+mm):
        # print(i,d)
        print(d.popleft(),end='')
else:
    for i in range(len(S)+mm):
        print(d.pop(),end='')
print()
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
li = [-1 for i in range(3)]

for i in range(M):
    s,c = map(int,input().split())


    if li[s-1]==-1 or li[s-1]==c:
        li[s-1] = c
    else:
        print(-1)
        break
else:
    ans = 0
    for i in range(N):
        mm = li[i]
        if li[i]==-1 and i!=0:
            li[i] = 0
        elif li[i]==-1 and i==0:
            li[i] = 1
        ans = ans * 10 + li[i]

    if c == 0 and s==1 and N >= 2:
        print(-1)
    elif c == 0 and s==1 and N==1:
        print(0)
    else:
        print(ans)
    
    



Fixed submission:
import sys

N,M = map(int,input().split())
li = [-1 for i in range(3)]

if M==0 and N==1:
    print(0)
elif M==0 and N==2:
    print(10)
elif M==0 and N==3:
    print(100)
if M==0:
    sys.exit()

for i in range(M):
    s,c = map(int,input().split())


    if li[s-1]==-1 or li[s-1]==c:
        li[s-1] = c
    else:
        print(-1)
        break
else:
    ans = 0
    for i in range(N):
        mm = li[i]
        if li[i]==-1 and i!=0:
            li[i] = 0
        elif li[i]==-1 and i==0:
            li[i] = 1
        ans = ans * 10 + li[i]

    if c == 0 and s==1 and N >= 2:
        print(-1)
    elif c == 0 and s==1 and N==1:
        print(0)
    else:
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

dp = [[0 for _ in range(N+1)] for _ in range(H+1)]

for h in range(1,H+1):
    dp[h][0] = 10**9

for n in range(1,N+1):
    for h in range(H+1):
        if h >= AB[n-1][0]:
            dp[h][n] = min(dp[h-AB[n-1][0]][n]+AB[n-1][1] , dp[h][n-1])
        else:
            dp[h][n] = dp[h][n-1]

# for i in range(H+1):
#     print(*dp[i])
        
ans = dp[H][N]
for n in range(N):
    for h in range(H):
        if (H-AB[n][0])<=h:
            ans = min(ans,dp[h][N]+AB[n][1])

print(ans)

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

dp = [[0 for _ in range(N+1)] for _ in range(H+1)]

for h in range(1,H+1):
    dp[h][0] = 10**9

for n in range(1,N+1):
    for h in range(H+1):
        if h >= AB[n-1][0]:
            dp[h][n] = min(dp[h-AB[n-1][0]][n]+AB[n-1][1] , dp[h][n-1])
        else:
            dp[h][n] = dp[h][n-1]

# for i in range(H+1):
#     print(*dp[i])
        
ans = dp[H][N]
for n in range(N):
    for h in range(H):
        if (H-AB[n][0])<=h:
            ans = min(ans,dp[h][N]+AB[n][1])

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = 10**6
li = [True for i in range(x)]
li[0] = False
li[1] = False

for i in range(int(x**0.5)+1):
    if li[i]:
        m = 2
        while(i*m<=x):
            li[i*m] = False
            m += 1
#print(li)
for i in range(x):
    if i>=n and li[i]:
        print(i)
        break

Fixed submission:
n = int(input())
x = 10**6
li = [True for i in range(x+10)]
li[0] = False
li[1] = False

for i in range(int(x**0.5)+1):
    if li[i]:
        m = 2
        while(i*m<=x):
            li[i*m] = False
            m += 1
#print(li)
for i in range(x):
    if i>=n and li[i]:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
a = list(int(input()))
a.append(int(input()))

for i in range(1,4):
    if not(i in a):
        print(i) 

Fixed submission:
a = []
a.append(int(input()))
a.append(int(input()))

for i in range(1,4):
    if not(i in a):
        print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

ans = 0
for i in range(10**3):
    mm = 0
    num = str(i).zfill(3)
    for j in range(N):
        if num[mm]==S[j]:
            mm += 1
        if mm==3:
            ans += 1
            break
print(ans)

Fixed submission:
N = int(input())
S = list(input())

ans = 0
for i in range(10**3):
    mm = 0
    num = str(i).zfill(3)
    for j in range(N):
        if num[mm]==S[j]:
            mm += 1
        if mm==3:
            ans += 1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = int((n-1)*n)/2)

print(ans)

Fixed submission:
n = int(input())

ans = ((n-1)*n)//2

print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
mod = 10**9+7

a = [1 for i in range(2010)]

memo = 1
for i in range(1,2001):
    memo *= i
    a[i] = memo



for i in range(1,k+1):
    if not((n-k+2 > i)):
        print(0)

    else:
        memo1 = a[n-k+1]*a[k-1]
        memo2 = a[i]*a[n-k+1-i]*a[i-1]*a[k-i]

        ans2 = memo1//memo2
        print(ans2%mod)
    


Fixed submission:
s = input()

a = []
for i in s:
    a.append(i)

cnt1 = 0
cnt2 = 0
memo =24
for i in range(1,4):
    if a[0] == a[i]:
        memo = i
        break;
    

ans = "No"
if(memo != 24):
    for i in range(1,4):
        for j in range(i+1,4):
            if (i != memo and j != memo):
                if a[i] == a[j]:
                    if a[0] != a[i]:
                        ans = "Yes"
                        break;


print(ans)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())



for i in range(1,k+1):
    if (n-k < i):
        print(1)

    else:
        total = 1
        total2 = 1
        total3 = 1
        for j in range(i+1):
            total *= n-k+1-j
            total2 *= j+1
            total3 = int(total/total2)
            
        ww = i**(k-i-2)
        ans = ww * total3

        ans2 = ans % 1000000007

        print(ans2)
    


Fixed submission:
s = input()

a = []
for i in s:
    a.append(i)

cnt1 = 0
cnt2 = 0
memo =24
for i in range(1,4):
    if a[0] == a[i]:
        memo = i
        break;
    

ans = "No"
if(memo != 24):
    for i in range(1,4):
        for j in range(i+1,4):
            if (i != memo and j != memo):
                if a[i] == a[j]:
                    if a[0] != a[i]:
                        ans = "Yes"
                        break;


print(ans)
Buggy python submission (verdict: Runtime Error):
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


s = list(input())

if a[0] == a[1] or a[1] == a[2] or a[2] == a[3]:
    print("Bad")
else:
    print("Good")

Fixed submission:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


a = list(input())

if a[0] == a[1] or a[1] == a[2] or a[2] == a[3]:
    print("Bad")
else:
    print("Good")
Buggy python submission (verdict: Runtime Error):
#bin/usr/env python3

n, x = map(int,input().split())
length = input().split()

total_len = 0
for i in range(n):
    total_len += int(length[i])
    if total_len > x:
        print(i+1)
        break
    if i = n-1:
        print(n+1)





Fixed submission:
#bin/usr/env python3

n, x = map(int,input().split())
length = input().split()

total_len = 0
for i in range(n):
    total_len += int(length[i])
    if total_len > x:
        print(i+1)
        break
    if i == n-1:
        print(n+1)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()

    li = []
    mm1 = A[N-1]
    mm2 = A[0]
    i = 1
    
    while(i<N-1):
        if A[i]<=0:
            li.append([mm1,A[i]])
            mm1 -= A[i]
        else:
            li.append([mm2,A[i]])
            mm2 -= A[i]
        i += 1
        li.append([mm1,mm2])
    print(mm1-mm2)
    for i in range(N-1):
        print(*li[i])

        


if __name__ == '__main__':
    main()





Fixed submission:
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()

    li = []
    mm1 = A[N-1]
    mm2 = A[0]
    i = 1
    while(i<N-1):
        if A[i]<=0:
            li.append([mm1,A[i]])
            mm1 -= A[i]
        else:
            li.append([mm2,A[i]])
            mm2 -= A[i]
        i += 1
    li.append([mm1,mm2])
    print(mm1-mm2)
    for i in range(N-1):
        print(*li[i])
    

        


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#bin/usr/env python3

n,m = map(int, input().split())
mod = 10**9+7

br = [0 for i in range(n+1)]
for i in range(m):
    a = int(input())
    br[a] = 1

can = [0 for i in range(n+1)]

can[1] = 1
can[2] = 2

if br[1] == 1:
    can[1] = 0
    can[2] = 1
if br[2] == 1:
    can[1] = 1
    can[2] = 0

for i in range(3, n+1):
    if br[i]!=1 :
        can[i] = (can[i-1] + can[i-2])%mod
    
    else:
        can[i] = 0

print(can[n])




Fixed submission:
#bin/usr/env python3

n,m = map(int, input().split())
mod = 10**9+7

br = [0 for i in range(n+2)]
for i in range(m):
    a = int(input())
    br[a] = 1

can = [0 for i in range(n+2)]

can[1] = 1
can[2] = 2

if br[1] == 1:
    can[1] = 0
    can[2] = 1
if br[2] == 1:
    can[1] = 1
    can[2] = 0
if br[1] == 1 and br[2] == 1:
    can[1] = 0
    can[2] = 0

for i in range(3, n+1):
    if br[i]!=1 :
        can[i] = (can[i-1] + can[i-2])%mod
    
    else:
        can[i] = 0

print(can[n])
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d = map(int,input().split())
sub = "#"+input()
s = list(sub)

con = True
for i in range(a,d+1):
    if s[i-1]=="#" and s[i]=="#":
        print("No")
        con = False
        break

if (con):
    if (c<b) or (c<d):
        print("Yes")
        con = False

if (con):
    for i in range(b-1,c):
        if s[i]=="." and s[i+1]=="." and s[i+2]==".":
            print("Yes")
            con = False
            break

if (con):
    print("No")



Fixed submission:
n,a,b,c,d = map(int,input().split())
sub = "#"+input()
s = list(sub)

con = True
for i in range(a,d+1):
    if s[i-1]=="#" and s[i]=="#":
        print("No")
        con = False
        break

if (con):
    if (c<b) or (c<d):
        print("Yes")
        con = False

if (con):
    for i in range(b-1,d):
        if s[i]=="." and s[i+1]=="." and s[i+2]==".":
            print("Yes")
            con = False
            break

if (con):
    print("No")

Buggy python submission (verdict: Runtime Error):
#bin/usr/env python3

n, a, b, c, d = map(int,input().split())
s = input()
s_li = []

for i in s:
    s_li.append(i)

last = c
reach = True

if last < d:
    last = d

if c < d:
    for i in range(a-1,last-1):
        if(s_li[i] == "#" and s_li[i+1] == "#"):
            reach = False
            break

elif d < c:
    for i in range(a-1,last-1):
        if(s_li[i] == "#" and s_li[i+1] == "#"):
            reach = False
            break
        reach = False

        if(s_li[i+2] == "." and s_li[i] == "." and s_li[i+1] == "."):
            reach = True
            break

if (reach):
    print("Yes")
else:
    print("No")
    
            
    


Fixed submission:
n,a,b,c,d = map(int,input().split())
sub = "#"+input()
s = list(sub)

con = True
for i in range(a,d+1):
    if s[i-1]=="#" and s[i]=="#":
        print("No")
        con = False
        break

if (con):
    if (c<b) or (c<d):
        print("Yes")
        con = False

if (con):
    for i in range(b-1,d):
        if s[i]=="." and s[i+1]=="." and s[i+2]==".":
            print("Yes")
            con = False
            break

if (con):
    print("No")
Buggy python submission (verdict: Runtime Error):
import itertools

n, m = map(int,input().split())

s = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))

li = [0,1]
ans = 0
for elm in itertools.product(li,repeat=n):
    for i in range(n):
        mm = 0
        for j in range(len(s[i])-1):
            if elm[s[i][j]-1]==1:
                mm += 1
        if mm%2!=p[i]:
            break
    else:
        ans += 1
print(ans)

Fixed submission:
import itertools

n, m = map(int,input().split())

s = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))

li = [0,1]
ans = 0
for elm in itertools.product(li,repeat=n):
    for i in range(m):
        mm = 0
        for j in range(1,s[i][0]+1):
            if elm[s[i][j]-1]==1:
                mm += 1
        if mm%2!=p[i]:
            break
    else:
        ans += 1
        #print(elm)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A = sorted(A,key=lambda x:x*(-1))
BC = sorted(BC,key=lambda x:x[1]*(-1))
li = []

cnt = 0
j = 0
while(cnt<N or j<M):
    if BC[j][0]>0:
        BC[j][0] -= 1
        li.append(BC[j][1])
    else:
        j+=1
    cnt += 1

ans = 0
ai = 0
bi = 0
cnt2 = 0
while(cnt2<N):
    if bi<len(li) and ai<N:
        if li[bi]>A[ai]:
            ans += li[bi]
            bi += 1
        else:
            ans += A[ai]
            ai += 1
    
    elif bi<len(li):
        ans += li[bi]
        bi += 1

    else:
        ans += A[ai]
        ai += 1
    cnt2 += 1

print(ans)


Fixed submission:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A = sorted(A,key=lambda x:x*(-1))
BC = sorted(BC,key=lambda x:x[1]*(-1))
li = []

cnt = 0
j = 0
while(cnt<N and j<M):
    if BC[j][0]>0:
        BC[j][0] -= 1
        li.append(BC[j][1])
        cnt += 1
    else:
        j+=1
    

ans = 0
ai = 0
bi = 0
cnt2 = 0
while(cnt2<N):
    if bi<len(li) and ai<N:
        if li[bi]>A[ai]:
            ans += li[bi]
            bi += 1
        else:
            ans += A[ai]
            ai += 1
    
    elif bi<len(li):
        ans += li[bi]
        bi += 1

    else:
        ans += A[ai]
        ai += 1
    cnt2 += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import math

n = int(input())
a = input().split()
num1 = 10000000000
num2 = 10000000000

for i in range(n-1):
    w = math.gcd(int(a[i]),int(a[i+1]))
    if w < num1:
        num1 = w
    elif num1 <= w <= num2:
        num2 = w

if num2 == 10000000000:
    print(num1)
else:
    print(num2)
    


Fixed submission:
#!/usr/bin/env python3

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = int(input())
a = list(map(int,input().split()))

memo1 = 10**9
memo2 = 10**9

lf = [0 for i in range(n)]
rgt = [0 for i in range(n)]

lf[0] = a[0]
rgt[0] = a[n-1]

for i in range(1,n):
	lf[i] = gcd(lf[i-1],a[i])
	rgt[i] = gcd(rgt[i-1],a[i*(-1)-1])


mx = 0
mx = max(mx,lf[n-2])
mx = max(mx,rgt[n-2])

for i in range(1,n-1):
	mx = max(mx,gcd(lf[i-1],rgt[i*(-1)-2]))

print(mx)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N = float(input())

data = []

for i in range(N):
    price = input().split()
    data.append(price) 

total = 0

for i in range(N):
    if data[i][1] == "JPY":
        total += int(data[i][0])
    elif data[i][1] == "BTC":
        total += 380000 * float(data[i][0])

print(total)


Fixed submission:
#!/usr/bin/env python3

N = int(input())

data = []

for i in range(N):
    price = input().split()
    data.append(price) 

total = 0

for i in range(N):
    if data[i][1] == "JPY":
        total += int(data[i][0])
    elif data[i][1] == "BTC":
        total += 380000 * float(data[i][0])

print(total)