Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	if n == 3:
		return 1/0
	al = lin()
	bl = lin()
	cl = lin()
	al.sort()
	bl.sort()
	cl.sort()
	cl_num=bl[:]
	cl_pos=0
	for i, vb in enumerate(bl):
		while cl_pos <n and cl[cl_pos] <= vb:
			cl_pos += 1
		cl_num[i] = n-cl_pos
		
	cl_nokori=[0]*n
	cl_nokori[-1] = cl_num[-1]
	for i, v in enumerate(cl_num[::-1]):
		if i == 0:
			continue
		cl_nokori[n-i-1] = cl_nokori[n-i]+v
	
	ret = 0
	bl_pos=0
	for va in al:
		while bl_pos < n and va >= bl[bl_pos]:
			bl_pos += 1
		if bl_pos == n:
			break
		ret += cl_nokori[bl_pos]
	print(ret)
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Fixed submission:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	bl = lin()
	cl = lin()
	al.sort()
	bl.sort()
	cl.sort()
	cl_num=bl[:]
	cl_pos=0
	for i, vb in enumerate(bl):
		while cl_pos <n and cl[cl_pos] <= vb:
			cl_pos += 1
		cl_num[i] = n-cl_pos
		
	cl_nokori=[0]*n
	cl_nokori[-1] = cl_num[-1]
	for i, v in enumerate(cl_num[::-1]):
		if i == 0:
			continue
		cl_nokori[n-i-1] = cl_nokori[n-i]+v
	
	ret = 0
	bl_pos=0
	for va in al:
		while bl_pos < n and va >= bl[bl_pos]:
			bl_pos += 1
		if bl_pos == n:
			break
		ret += cl_nokori[bl_pos]
	print(ret)
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
Buggy python submission (verdict: Runtime Error):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def is_ok(sd, st, t):
	if len(sd) < st+len(t):
		return False
	for i, c in enumerate(sd[st:st+len(t)]):
		if c != '?' and t[i] != c:
			return False
	return True
	
def to_aaa(a_str):
	rr=list(a_str)
	for i, c in enumerate(rr):
		rr[i] = 'a' if c == '?' else c
	ret = ''.join(rr)
	return ret

def mk_s(a_s_dash, i, t):
	front = to_aaa(a_s_dash[:i])
	back = to_aaa(a_s_dash[i+len(t):])
	ret = front+t+back
	#pa((i,t,front,t,back,ret))
	return ret
			
def main():
	s_dash = input()
	t=input()
	dd='UNRESTORABLE'
	qq='?'
	
	aa=[]
	for i, _ in enumerate(s_dash[:len(t)+1]):
		if is_ok(s_dash,i,t):
			aa.append(mk_s(s_dash, i, t))
			#pa(aa)
			
	if len(aa)>0:
		
		aa.sort()
		ret = aa[0]
		print(ret)
		return
	aa=aa.copy()
	print(dd)
	return
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Fixed submission:
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def is_ok(sd, st, t):
	if len(sd) < st+len(t):
		return False
	for i, c in enumerate(sd[st:st+len(t)]):
		if c != '?' and t[i] != c:
			return False
	return True
	
def to_aaa(a_str):
	rr=list(a_str)
	for i, c in enumerate(rr):
		rr[i] = 'a' if c == '?' else c
	ret = ''.join(rr)
	return ret

def mk_s(a_s_dash, i, t):
	front = to_aaa(a_s_dash[:i])
	back = to_aaa(a_s_dash[i+len(t):])
	ret = front+t+back
	#pa((i,t,front,t,back,ret))
	return ret
			
def main():
	s_dash = input()
	t=input()
	dd='UNRESTORABLE'
	qq='?'
	
	aa=[]
	for i, _ in enumerate(s_dash[:len(s_dash)+1]):
		#pa((s_dash,i,t))
		if is_ok(s_dash,i,t):
			aa.append(mk_s(s_dash, i, t))
			#pa(aa)
			
	if len(aa)>0:
		aa.sort()
		ret = aa[0]
		print(ret)
		return
		
	print(dd)
	return
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
Buggy python submission (verdict: Runtime Error):
al=list(map(int,input.split()))
al.sort()
print(sum(al)-al[1]*2)

Fixed submission:
al=list(map(int,input().split()))
al.sort()
print(sum(al)-al[1]*2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	a = int(input())
	al=[]
	for i in range(a):
		b = int(input())
		al.append(b)
		
	opened_list=set()
	st=0
	opened_list.add(st)
	count=0
	while st != 1:
		st = al[st]-1
		count+=1
		if st in opened_list:
			return -1
			
	return count
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Fixed submission:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	a = int(input())
	al=[]
	for i in range(a):
		b = int(input())
		al.append(b)
		
	opened_list=set()
	st=0
	opened_list.add(st)
	count=0
	while st != 1:
		st = al[st]-1
		count+=1
		if st in opened_list:
			return -1
		opened_list.add(st)
			
	return count
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

#+++++
		
def main():
	k, s = map(int, input().split())
	c=0
	for x in range(k+1):
		for y in range(k+1):
			for z in range(k+1):
				c+=1 if x+y+z==s else 0
	
	print(c)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(ret)

Fixed submission:
import sys
input = sys.stdin.readline

#+++++
		
def main():
	k, s = map(int, input().split())
	c=0
	for x in range(k+1):
		for y in range(k+1):
			ccc=s-(x+y)
			c+=1 if ccc <= k and 0<= ccc else 0
	
	print(c)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(ret)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A,B = map(int,input().split())

count = 1

for i in range(N):
   
      
    if  count == A or B:
        count += 0
    else:
       count += 1 
    
print(count)

Fixed submission:
K = int(input())



for i in range(K):

  print("ACL", end='')

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

if a <c:
  

    if b-c>=0 :
       print ("Yes")
    else:
       print("No")
        
else:
    if b-c>=0 :
       print ("No")
    else:
       print("Yes")

Fixed submission:
K = int(input())



for i in range(K):

  print("ACL", end='')
Buggy python submission (verdict: Runtime Error):
N = int(input())

k=0

for s in range(1,N):
  k = (N-1) // s
  t += k 
  
print (t)

Fixed submission:
S = str(input())

if S[-1] == "s" :

 print( S + "es" )

else:

 print( S + "s" )

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

count = 0

for i in range(N):
    k, t = map(int, input().split())
    if count == 3:
      print ( "yes" )
     
      break
      
    if not k == t:
        count *= 0
    if k == t:
       count += 1 
if not count == 3:
        print ("no")



Fixed submission:
S = str(input())

if S[-1] == "s" :

 print( S + "es" )

else:

 print( S + "s" )
Buggy python submission (verdict: Runtime Error):
N = int(input())

count = 0

for i in range(N +1):
    k, t = map(int, input().split())
    if count == 3:
      print ( "yes" )
      count += 5
      break
      
    if not k == t:
        count *= 0
    if k == t:
       count += 1 
       
      
if not count >= 3:
  print ("no")



Fixed submission:
N = int(input())

count = 0

for i in range(N):
    k, t = map(int, input().split())
      
    if not k == t:
        count *= 0
    if k == t:
       count += 1 
    if count == 3:
      print ( "Yes" )
     
      break
        
if count == 3:
        print ("")
else:
  print ("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())

k=0

for s in range(1,N):
  k = (N-1) // s
  t += k 
  
print (t)


Fixed submission:
N = int(input())

k=0

for s in range(1,N):
  k += (N-1) // s
   
  
print (k)

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

k = 0

for s in range(1,N) :
  k = (N-1) // s
  t += k 
  
print(k)

Fixed submission:
N = int(input())

k=0

for s in range(1,N):
  k += (N-1) // s
   
  
print (k)
Buggy python submission (verdict: Runtime Error):
r, D, x = map(int, input().split())

for i range(10):
  x = r*x -D
  print(x)

Fixed submission:
A, B = map(int, input().split())
if A >= 13:
 print (B)
  
elif 6<=A<=12:
 print (int(B/2))
  
else:
 print (0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int, input().split())
sum = 0
for i in lis:
   for j in lis:
        sum += i * j
print(sum % 1000000009)           

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

s = sum(lis) ** 2
ss = sum([i ** 2 for i in lis])

print(((s - ss)//2)%(10**9+7))
Buggy python submission (verdict: Runtime Error):
S = input()
if S == ABC:
  print("ARC")
else:
  print("ABC")

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")

else:
  print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
kake = 0

for i in range(N):
    kake = A[i]
    tasu = 0
    for j in range(i+1, N):
        tasu += A[j]
    ans = (ans + kake*tasu)%MOD
        
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split())) + [0]
B = [0]*(N+1)

for i in range(N-1):
    B[N-i-1] = A[N-i-1]+B[N-i]
ans = 0
MOD = 10**9 + 7

for i in range(N-1):
    ans = (ans + A[i]*B[i+1])%MOD
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7

for i in range(N):
    for j in range(i+1, N):
        ans = (ans + (A[i]*A[j]))%MOD
        
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split())) + [0]
B = [0]*(N+1)

for i in range(N-1):
    B[N-i-1] = A[N-i-1]+B[N-i]
ans = 0
MOD = 10**9 + 7

for i in range(N-1):
    ans = (ans + A[i]*B[i+1])%MOD
        
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()

xn = X.count('1')
x10 = int(X,2)

def f(one, ten):
    c = 0
    while ten:
        c += 1
        ten %= one
        one = str(bin(ten)).count('1')
    print(c)


for i,j in enumerate(X):
    k = N - 1 - i
    if j == '1':
        f(xn - 1, x10 - (2**k))
    elif j == '0':
        f(xn + 1, x10 + (2**k))


Fixed submission:
l, r, d = map(int, input().split())

ans = 0

for i in range(l, r+1):
    if i % d == 0:
        ans += 1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

sumA = 0
num = [0]*100000
for aa in a:
    num[aa] += 1
    sumA += aa

for b, c in bc:
    if b < 100001 and c <100001:
        sumA = sumA + ((c - b) * num[b])
        num[c] += num[b]
        num[b] = 0
    print(sumA)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

sumA = 0
num = [0]*100100
for aa in a:
    num[aa] += 1
    sumA += aa

for b, c in bc:
    sumA = sumA + ((c - b) * num[b])
    num[c] += num[b]
    num[b] = 0
    print(sumA)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

sumA = 0
num = [0]*100000
for aa in a:
    num[aa] += 1
    sumA += aa

for b, c in bc:
    sumA = sumA + ((c - b) * num[b])
    num[c] += num[b]
    num[b] = 0
    print(sumA)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

sumA = 0
num = [0]*100100
for aa in a:
    num[aa] += 1
    sumA += aa

for b, c in bc:
    sumA = sumA + ((c - b) * num[b])
    num[c] += num[b]
    num[b] = 0
    print(sumA)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]
a_dict = {}
for i in a:
    if i not in a_dict:
        a_dict[i] = 1
    else:
        a_dict[i] += 1
        
for b, c in bc:
    sumA = 0
    if b in a_dict:
        bn = a_dict[b]
        a_dict[b] = 0
        if c in a_dict:
            a_dict[c] += bn
        else:
            a_dict[c] = bn
    for k, v in a_dict.items():
        sumA += k*v
    print(sumA)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

sumA = 0
num = [0]*100100
for aa in a:
    num[aa] += 1
    sumA += aa

for b, c in bc:
    sumA = sumA + ((c - b) * num[b])
    num[c] += num[b]
    num[b] = 0
    print(sumA)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

for b, c in bc:
    sumA = 0
    for i in range(0, n):
        if a[i] == b:
            a[i] = c
        sumA += a[i]
    print(sumA)
            

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

sumA = 0
num = [0]*100100
for aa in a:
    num[aa] += 1
    sumA += aa

for b, c in bc:
    sumA = sumA + ((c - b) * num[b])
    num[c] += num[b]
    num[b] = 0
    print(sumA)
Buggy python submission (verdict: Runtime Error):
x = int(input())
y = list(map(int, input().split()))

y.sort()
ans = [bool(a+1) for a in range(x)]

for i in range(x-1):
    if ans[i] == True:
        if y[i] == y[i+1]:
            ans[i] = False
        for j in range(i+1 ,x):
            if (ans[j] == True) and (y[j]%y[i]==0):
                ans[j] = False

print(sum(ans))

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

for i, j in enumerate(x, 1):
    if i != j:
        print(i)

Buggy python submission (verdict: Runtime Error):
x = list(map(int, input().split()))
y = set(map(int, input().split()))

if x[1] == 0:
    min = x[0]
else:
    for i in range(1, x[1]):
        if set() == {x[0]-i}&y:
            print(x[0]-i)
            exit()
        elif set() == {x[0]+i}&y:
            print(x[0]+i)
            exit()


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

for i, j in enumerate(x, 1):
    if i != j:
        print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N

for i in range(1, N):
    m = math.inf
    for j in range(1, K+1):
        k = i - j
        if k < 0:
            break
        m = min(m, abs(h[i] - h[k]) + dp[k])
    dp[i] = m
print(dp[N-1])
    

Fixed submission:
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * N

for i in range(1, N):
    m = math.inf
    for j in range(1, K+1):
        k = i - j
        if k < 0:
            break
        m = min(m, abs(h[i] - h[k]) + dp[k])
    dp[i] = m
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
print((input()-2)*180)

Fixed submission:
print((int(input())-2)*180)

Buggy python submission (verdict: Runtime Error):
n = input()
x = (n-2)*180
print(x)

Fixed submission:
print((int(input())-2)*180)
Buggy python submission (verdict: Runtime Error):
x = input()
x_len = len(x)
count_w, count_l = 0,0
for i in range(len(x)):
  if x[i] == 'o':
    count_w += 1
  if x[i] == 'x':
    count_l += 1
    
if 15 - x_len + count_win >= 8:
  print('YES')
else:
  print('NO')



Fixed submission:
x = input()
x_len = len(x)
count_w, count_l = 0,0
for i in range(len(x)):
  if x[i] == 'o':
    count_w += 1
  if x[i] == 'x':
    count_l += 1
    
if 15 - x_len + count_w >= 8:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
import scipy.fftpack as F
from numpy import *
m=200003
n=int(input())
a=[0]*m
b=[0]*(m-1)
ans=0
for i in range(m):
    a[pow(2,i,m)]=i
for i in map(int,input().split()):
    if i:
        b[a[i]]+=1
        ans-=i*i%m
b=array(b,dtype=float64)
b=F.fft(b)
b=b*b
b=F.ifft(b)
for i,j in enumerate(b):
    ans+=int(round(j.real))*pow(2,i,m)
print(ans//2)

Fixed submission:
import scipy.fftpack as F
from numpy import *
m=200003
n=int(input())
a=[0]*m
b=[0]*(m-1)
ans=0
for i in range(m-1):
    a[pow(2,i,m)]=i
for i in map(int,input().split()):
    if i:
        b[a[i]]+=1
        ans-=i*i%m
b=array(b,dtype=float64)
b=F.fft(b)
b=b*b
b=F.ifft(b)
for i,j in enumerate(b):
    ans+=int(round(j.real))*pow(2,i,m)
print(ans//2)
Buggy python submission (verdict: Runtime Error):
from math import sin,cos
N,L=map(int,input().split())
S=N*(N-1)*(N-2)/6
T=[int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1, N)])for i in range(N)])/S,sum([sum([sin((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1,N)])for i in range(N)])/S)

Fixed submission:
from math import sin,cos,pi
N,L=map(int,input().split())
S=N*(N-1)*(N-2)/ 6
T=[int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j]))*(N+2*(i-j)) for j in range(i+1, N)]) for i in range(N)])/S,sum([sum([sin((T[i]+T[j]))*(N+2*(i-j)) for j in range(i+1,N)]) for i in range(N)])/S)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)

@lru_cache(None)
def f(n,a,b,c,d):
  if n==0:return 0
  if n==1:return d
  if n==2:return min(d*2,a+d)
  if n==3:return min(d*3,d+a+d,b+d)
  if n==4:return min(d*4,a+a+d,d+b+d,d+c+d)
  if n==5:return min(d*5,d+a+a+d,d+d+b+d,d+a+b+d,c+d)
  if n==6:return min(d*6,a+b+d,a+d+a+d,b+d+b+d,d+c+d)
  # print(n,a,b,c,d)
  p=n*d
  for i in range(-10, 11):
    nn=n+i
    if nn<0:continue
    if nn%2==0and nn//2<n:p=min(p,f(nn//2,a,b,c,d)+abs(i)*d+a)
    if nn%3==0and nn//3<n:p=min(p,f(nn//3,a,b,c,d)+abs(i)*d+b)
    if nn%5==0and nn//5<n:p=min(p,f(nn//5,a,b,c,d)+abs(i)*d+c)
  return p

for _ in range(int(input())):
  n,a,b,c,d = map(int,input().split())
  print(f(n,a,b,c,d))

Fixed submission:
from functools import lru_cache

def solve(n,a,b,c,d):
    @lru_cache(None)
    def rec(cur):
        if cur == 0:    return 0
        if cur == 1:    return d
        ret = cur * d
        p,q = divmod(cur, 2)
        if q == 0:  ret = min(ret, rec(p) + a)
        if q == 1:  ret = min(ret, rec(p) + a + d, rec(p + 1) + a + d)
        p,q = divmod(cur, 3)
        if q == 0:  ret = min(ret, rec(p) + b)
        if q == 1:  ret = min(ret, rec(p) + b + d)
        if q == 2:  ret = min(ret, rec(p) + b + d * 2, rec(p + 1) + b + d)
        p,q = divmod(cur, 5)
        if q == 0:  ret = min(ret, rec(p) + c)
        if q == 1:  ret = min(ret, rec(p) + c + d)
        if q == 2:  ret = min(ret, rec(p) + c + d * 2)
        if q == 3:  ret = min(ret, rec(p) + c + d * 3, rec(p + 1) + c + d * 2)
        if q == 4:  ret = min(ret, rec(p) + c + d * 4, rec(p + 1) + c + d)
        return ret

    return rec(n)

for _ in range(int(input())):
    n,a,b,c,d = map(int,input().split())
    print(solve(n,a,b,c,d))
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n)    for (ll (i) = 0;   (i) < (n); ++(i))
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))

signed main() {

    int a, b;
    cin >> a >> b;
    if (a > b) cout << "safe" << endl;
    else cout << "unsafe" << endl;

}


Fixed submission:
s,w = map(int,input().split())
if s <= w:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

res = 0
dp = np.zeros(s + 1)

for i in range(n):
    dp[0] += 1
    dp[a[i]:] += dp[:s+1-a[i]]
    dp %= mod
    res += dp[s]
    res %= mod

print(int(res))


Fixed submission:
import numpy as np

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

res = 0
dp = np.zeros(s + 1, dtype = int)

for i in range(n):
    dp[0] += 1
    dp[a[i]:] += dp[:-a[i]].copy()
    dp %= mod
    res += dp[s]
    res %= mod

print(res)
Buggy python submission (verdict: Runtime Error):
n=input()
print((n+1)//2)

Fixed submission:
n = int(input())
print((n + 1) // 2)