Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(map(int, input().split())) 
q = int(input())

for i in range(q):
    a,b = map(int, input().split())
    al = [b if j == a else j for j in al ]
    print(sum(al))

Fixed submission:
n = int(input())
al = list(map(int, input().split())) 
q = int(input())

from collections import Counter
count = Counter(al)

als = sorted(al)
dp = [0]*(10**5+1)
res = sum(als)

for i in range(10**5+1):
    dp[i] =count[i]

for j in range(q):
    a,b = map(int, input().split())
    res += dp[a] * (b-a)
    dp[b] += dp[a]
    dp[a] = 0
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(map(int, input().split())) 

res = 1
for i in range(n):
    res *= al[i]
    
if res > 10**18:
    print(-1)
    exit()

else:        
    print(res)

Fixed submission:
n = int(input())
al = list(map(int, input().split())) 

res = 1
from collections import Counter
count = Counter(al)
cc = count[0]

if cc >=1:
    print(0)
    exit()

for i in range(n):
    res *= al[i]    
    if res > 10**18:
        print(-1)
        exit()

else:        
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())     
Alist = [int(x) for x in input().split()]
for i in range(1,N+1):
    print(Alist.count(i))

Fixed submission:
import collections
N = int(input())     
Alist = [int(x) for x in input().split()]
c = collections.Counter(Alist)
for i in range(1,N+1):
    print(c[i])
Buggy python submission (verdict: Runtime Error):
n,k = (int(x) for x in input().split())
for i in range(k,n+2):
    base = n*i -(i*(i-1)) +1
#    print(base)
    res = res+ base

resu = res%1000000007

print(resu)

Fixed submission:
n,k = (int(x) for x in input().split())
res = 0
for i in range(k,n+2):
    base = n*i -(i*(i-1)) +1
    res = res+ base
resu = res%1000000007
print(resu)
Buggy python submission (verdict: Runtime Error):
a,b,q = map(int, input().split())

s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]

import bisect

for i in range(q):
    qq = int(input())
    sp = bisect.bisect(s,qq)
    tp = bisect.bisect(t,qq)
    s1 = s[sp-1]
    if sp <a:
        s2 = s[sp]

    t1 = t[tp-1]
    if tp <b:
        t2 = t[tp]
    print(min(abs(qq-s1)+abs(s1-t1),abs(qq-s1)+abs(s1-t2),
              abs(qq-s2)+abs(s2-t1),abs(qq-s2)+abs(s2-t2),
              abs(qq-t1)+abs(t1-s1),abs(qq-t1)+abs(t1-s2),
              abs(qq-t2)+abs(t2-s1),abs(qq-t2)+abs(t2-s2)))

Fixed submission:
a,b,q = map(int, input().split())

s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]

import bisect

for i in range(q):
    s2 = 10**12
    t2 = 10**12
    qq = int(input())
    sp = bisect.bisect(s,qq)
    tp = bisect.bisect(t,qq)
    s1 = s[sp-1]
    if sp <a:
        s2 = s[sp]

    t1 = t[tp-1]
    if tp <b:
        t2 = t[tp]
    print(min(abs(qq-s1)+abs(s1-t1),abs(qq-s1)+abs(s1-t2),
              abs(qq-s2)+abs(s2-t1),abs(qq-s2)+abs(s2-t2),
              abs(qq-t1)+abs(t1-s1),abs(qq-t1)+abs(t1-s2),
              abs(qq-t2)+abs(t2-s1),abs(qq-t2)+abs(t2-s2)))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
al = list(map(int, input().split()))

import math
keta = math.log(k,2)
keta_i = int(keta)+2

dp = [n]*(keta_i)

for i in range(n):
    i_bit = bin(al[i])[2:]
    lenb = len(i_bit)
    for j in range(lenb-1,-1,-1):
        dp[lenb-1-j] -= int(i_bit[j])

temp = k
res = 0
m = n//2

for i in range(keta_i-1,-1,-1):
    if dp[i] > m and 2**i <= k:
        temp -= 2**i
        res += (2**i)*(dp[i]) 
    else:
        res += (2**i)*(n-dp[i])

print(res)

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

dp = [n]*41

for i in range(n):
    i_bit = bin(al[i])[2:]
    lenb = len(i_bit)
    for j in range(lenb-1,-1,-1):
        dp[lenb-1-j] -= int(i_bit[j])

temp = k
res = 0
m = n//2

for i in range(40,-1,-1):
    if dp[i] > m and 2**i <= temp:
        temp -= 2**i
        res += (2**i)*(dp[i]) 
    else:
        res += (2**i)*(n-dp[i])

print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())

dp =[0]*40

if n ==0:
    print(0)

elif n >0:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

else:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

Fixed submission:
n = int(input())

dp =[0]*40

if n ==0:
    print(0)

elif n >0:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

else:
    x = bin(-n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==0 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())

for i in range(a,b+1):
    if i <=a+k-1:
        print(i)

    elif i >=b-k+1:
        print(i)

Fixed submission:
a,b,k = map(int, input().split())

for i in range(a,a+k):
    if i <= b:
        print(i)

for i in range(b-k+1,b+1):
    if i >=a+k :
        print(i)
Buggy python submission (verdict: Runtime Error):
h,w,d = map(int, input().split())

dp= [0]*(h*w+1)

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

for i in range(w):
    for j in range(h):
        s = ab[i][j]
        dp[s] =[i,j]
        
dpp= [0]*(h*w+1)

for k in range(d+1,h*w+1):
#    print(k)
    dpp[k] = dpp[k-d] + abs(dp[k][0]-dp[k-d][0]) +abs(dp[k][1]-dp[k-d][1])
    
q = int(input())

for x in range(q):
    a,b = map(int, input().split())
    print(dpp[b]-dpp[a])

Fixed submission:
h,w,d = map(int, input().split())

dp= [0]*(h*w+1)

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

for i in range(h):
    for j in range(w):
        s = ab[i][j]
        dp[s] =[i,j]
        
dpp= [0]*(h*w+1)

for k in range(d+1,h*w+1):
#    print(k)
    dpp[k] = dpp[k-d] + abs(dp[k][0]-dp[k-d][0]) +abs(dp[k][1]-dp[k-d][1])
    
q = int(input())

for x in range(q):
    a,b = map(int, input().split())
    print(dpp[b]-dpp[a])
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())

from collections import defaultdict
V = defaultdict(list)
 
for _ in range(m):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,-c])

inf  = float("inf") 

def dfs(source):
    dist = [inf]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=inf:
                if dist[b[0]] != dist[a] +b[1]:
                    print("No")
                    exit()
            else:
                dist[b[0]] = dist[a] + b[1]
                q.append(b[0])
    return dist

dfs(min(V))

print("Yes")

Fixed submission:
n,m = map(int, input().split())

if m <=1:
    print("Yes")
    exit()

from collections import defaultdict
V = defaultdict(list)
 
for _ in range(m):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,-c])

inf  = float("inf") 
dist = [inf]*(n+1)

def dfs(source):
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=inf:
                if dist[b[0]] != dist[a] +b[1]:
                    print("No")
                    exit()
            else:
                dist[b[0]] = dist[a] + b[1]
                q.append(b[0])

for i in range(n):
    if dist[i] ==inf:
        dfs(i)

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]

if n ==1:
    print(0)
    exit()

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            for k in range(0,100010):
                if temp <= ab[j+1][1] + ab[j+1][2]*k:
                    temp = ab[j+1][1]+ab[j+1][2]*k +ab[j+1][0] 
                    break
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])

Fixed submission:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]

if n ==1:
    print(0)
    exit()

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            if temp <= ab[j+1][1]:
                temp = ab[j+1][1] + ab[j+1][0]
            else:
                if temp % ab[j+1][2] ==0:
                    temp += ab[j+1][0]
                else:
                    temp = ((temp//ab[j+1][2])+1) * ab[j+1][2] +ab[j+1][0]
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int, input().split())

res = 0

for i in range(1,n+1):
    x5 = i//10000
    x4 = (i-x5*10000)//1000
    x3 = (i-x5*10000-x4*1000)//100
    x2 = (i-x5*10000-x4*1000-x3*100)//10
    x1 = i % 10
    
    xx = x5+x4+x3+x2+x1
    if b >= xx >= a:
        res += i

print(res)

Fixed submission:
x,y = map(int, input().split())

z = y//x 

temp = 1
for i in range(10000):
    temp *= 2
    if z < temp:
        print(i+1)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1

while len(res) >1:
    resu = min(resu,max(res[0],sum(res[1:])))
    x = res.pop(1)
    res[0]  = res[0]+x    
    
print(resu)

Fixed submission:
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1
m = n-1

while len(res) >1:
    resu = min(resu,max(res[0],m-res[0]))
    x = res.pop(1)
    res[0]  = res[0]+x    
    
print(resu)

Buggy python submission (verdict: Runtime Error):
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1

while len(res) >1:
    resu = min(resu,max(res[0],res[1:]))
    x = res.pop(1)
    res[0]  = res[0]+x    
"""
    if res[0] > sum(res[1:]):
        resu = min(resu,res[0])
        x = res.pop(1)
        res[0] = res[0]+x
    else:
        resu = min(resu,sum(res[1:]))
        x = res.pop(1)
        res[0] =res[0]+x
"""
print(resu)

Fixed submission:
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1
m = n-1

while len(res) >1:
    resu = min(resu,max(res[0],m-res[0]))
    x = res.pop(1)
    res[0]  = res[0]+x    
    
print(resu)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1

while len(res) >1:
    if res[0] > sum(res[1:]):
        resu = min(resu,res[0])
        x = res.pop(1)
        res[0] = res[0]+x
    else:
        resu = min(resu,sum(res[1:]))
        x = res.pop(1)
        res[0] =res[0]+x

print(resu)

Fixed submission:
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1
m = n-1

while len(res) >1:
    resu = min(resu,max(res[0],m-res[0]))
    x = res.pop(1)
    res[0]  = res[0]+x    
    
print(resu)
Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

lal = sorted(al,reverse = True)
lbl = sorted(bl,reverse = True)
lcl = sorted(cl,reverse = True)



d =[0]*n

for i in range(n):
    x = lbl[i]
    for j in range(n):
        y = lal[j]
        if x > y:
            d[i] = (n-j)
            break
        
res =0
for i in range(n):
    x = lcl[i]
    for j in range(n):
        y = lbl[j]
        if x >y:            
            res += sum(d[j:])
            break

print(res)

Fixed submission:
n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

lal = sorted(al)
lbl = sorted(bl)
lcl = sorted(cl)


from bisect import bisect_left, bisect_right
 

res = 0

for i in range(n):
    bx = lbl[i]
    ax = bisect_left(lal,bx)
    cx = n - bisect_right(lcl,bx)
    
    res += ax*cx

print(res)
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())

print(a*a -b )

Fixed submission:
n = int(input())
k = int(input())

print(n*n -k)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d,e,f = map(int, input().split())


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        if 0 < (a*i + b*j)*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    if (c*k + d*l <= (a*i + b*j)*e) and (a*i + b*j)*100+(c*k + d*l) <= f:
                        g = (c*k + d*l)/((a*i + b*j)*100+(c*k + d*l))
                        res.append([g,(a*i + b*j)*100+(c*k + d*l),(c*k + d*l)])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

Fixed submission:
a,b,c,d,e,f = map(int, input().split())


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        wa = a*i + b*j
        if 0 < wa*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    su = c*k + d*l
                    if (su <= wa*e) and wa*100+su <= f:
                        g = su/(wa*100+su)
                        res.append([g,wa*100+su,su])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d,e,f = map(int, input().split())


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        if 0 < (a*i + b*j)*100 < f:
            for k in range(maxcd):
                for l in range(maxcd):
                    if (c*k + d*l <= (a*i + b*j)*e) and (a*i + b*j)*100+(c*k + d*l) <= f:
                        g = (c*k + d*l)/((a*i + b*j)*100+(c*k + d*l))
                        res.append([g,(a*i + b*j)*100+(c*k + d*l),(c*k + d*l)])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

Fixed submission:
a,b,c,d,e,f = map(int, input().split())


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        wa = a*i + b*j
        if 0 < wa*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    su = c*k + d*l
                    if (su <= wa*e) and wa*100+su <= f:
                        g = su/(wa*100+su)
                        res.append([g,wa*100+su,su])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])
Buggy python submission (verdict: Runtime Error):
x,t = map(int, input().split())

print((max(x-t),0))

Fixed submission:
x,t = map(int, input().split())

print(max(x-t,0))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = input().split()

print(max((min(b,d)-max(a,c)),0))

Fixed submission:
a,b,c,d = map(int, input().split())

print(max((min(b,d)-max(a,c)),0))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
 
n = int(input())
V = defaultdict(list)

for _ in range(n-1):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,c])

def dfs(source):
    dist = [-1]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=-1:
                continue
            dist[b[0]] = dist[a] + b[1]
            q.append(b[0])
    return dist

q,k = map(int, input().split())

for i in range(q):
    x,y = map(int,input().split())
    print(dfs(x)[k]+dfs(y)[k])

Fixed submission:
from collections import defaultdict
 
n = int(input())
V = defaultdict(list)

for _ in range(n-1):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,c])

def dfs(source):
    dist = [-1]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=-1:
                continue
            dist[b[0]] = dist[a] + b[1]
            q.append(b[0])
    return dist

q,k = map(int, input().split())
dk = dfs(k)

for i in range(q):
    x,y = map(int,input().split())
    print(dk[x]+dk[y])
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())

from collections import defaultdict 
V = defaultdict(list)

for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

def dfs(source):
    dist = [-1]*(n+1)
    dist[source] = 0
    q = [source]
    while q and cur <3:
        a = q.pop()
        for b in V[a]:
            if dist[b]!=-1:
                continue
            dist[b] = dist[a] + 1
            q.append(b)
        cur = dist[b]
    return dist

d1 = dfs(1)
if d1[n] ==2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
n,m = map(int, input().split())

from collections import defaultdict 
V = defaultdict(list)

for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * (n+1) # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in V[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                queue.append(i)
    return d

b1 = bfs(1)
if b1[n] ==2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

from collections import defaultdict 
V = defaultdict(list)

for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

def dfs(source):
    dist = [-1]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b]!=-1:
                continue
            dist[b] = dist[a] + 1
            q.append(b)
    return dist

d1 = dfs(1)
if dfs(n) <=2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
n,m = map(int, input().split())

from collections import defaultdict 
V = defaultdict(list)

for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * (n+1) # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in V[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                queue.append(i)
    return d

b1 = bfs(1)
if b1[n] ==2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(map(int, input().split()))

sal=sum(al)
res=10**9+1

for i in range(1,n):
    temp = al[:i]
    res = min(res,abs(sal/2-sum(temp)))

print(int(res*2))

Fixed submission:
n = int(input())
al = list(map(int, input().split()))

sal=sum(al)
res=10**9+1
temp=0
for i in range(0,n-1):
    temp += al[i]
    res = min(res,abs(sal/2-temp))
    if res <=0.5:
        break

print(int(res*2))
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())

if abs(n-m) >1:
    print(0)
    exit()

p = 10**9+7
fact =[1,1]
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    
if n ==m:
    res = fact[n]*fact[m]*2

else:
    res = fact[n]*fact[m]

print(res%p)

Fixed submission:
n,m = map(int, input().split())

if abs(n-m) >1:
    print(0)
    exit()

p = 10**9+7
fact =[1,1]
for i in range(2, max(n,m) + 1):
    fact.append((fact[-1] * i) % p)
    
if n ==m:
    res = fact[n]*fact[m]*2

else:
    res = fact[n]*fact[m]

print(res%p)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)] 

abb = ab.sort()

temp =0

for i in range(n):
    if temp < k:
        temp += abb[i][1]
    else:
        print(abb[i-1][0])
        exit()

Fixed submission:
n,k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

abb = sorted(ab)
temp =0

for i in range(n+1):
    if temp < k:
        temp += abb[i][1]
    else:
        print(abb[i-1][0])
        exit()