Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math as m
a,b=list(map(float,input().split()))
print(m.floor(a*(b*1000)/1000))

Fixed submission:
N=int(input())
s=sorted(list(map(int, input().split()))[::-1])
a=1
for i in range(N):
  if a>10**18:
    break
  a*=s[i]
print(-1 if a>10**18 else a)

Buggy python submission (verdict: Runtime Error):
import math as m
a,b=list(map(float,input().split()))
print(m.floor(a*(b*10**5)/10**5))

Fixed submission:
N=int(input())
s=sorted(list(map(int, input().split()))[::-1])
a=1
for i in range(N):
  if a>10**18:
    break
  a*=s[i]
print(-1 if a>10**18 else a)

Buggy python submission (verdict: Runtime Error):
N=int(input())
s=list(map(int, input().split()))
a=1
for i in range(N):
  if if a>1000000000000000000:
    break
  a*=s[i]
print(-1 if a>1000000000000000000 else a)

Fixed submission:
N=int(input())
s=sorted(list(map(int, input().split()))[::-1])
a=1
for i in range(N):
  if a>10**18:
    break
  a*=s[i]
print(-1 if a>10**18 else a)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=list(map(int, input().split()))
a=1
for i in range(N):
  a*=s[i]
print(-1 if a>1000000000000000000 else a)

Fixed submission:
N=int(input())
s=sorted(list(map(int, input().split()))[::-1])
a=1
for i in range(N):
  if a>10**18:
    break
  a*=s[i]
print(-1 if a>10**18 else a)
Buggy python submission (verdict: Runtime Error):
40
ferelibenterhominesidquodvoluntcredunt

Fixed submission:
n=int(input())
s=input()
if len(s)>n:
  print(s[:n]+"...")
else:
  print(s)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int input().split())
print(c,a,b)

Fixed submission:
a,b,c = map(int, input().split())
print(c,a,b)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split()):print(min(a+b,a-b,a*b))

Fixed submission:
a,b=map(int,input().split());print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
#N, M, X = [int(n) for n in input().split()]

#CA = [list(map(int, input().split())) for n in range(N)]

#print(N,M,X)
#print(CA)

min_cost = 12*10**5


def dfs(CA, cost, skills, cur, used, min_cost):
  #Pdb().set_trace()
  #print(cur)
  skills = [skills[i] + n for i, n in enumerate(CA[cur][1:])]
  used += [cur]
  cost += CA[cur][0]
  
  if all([s >= X for s in skills]):
  	return cost
  else:
    candidates = [n for n in range(N) if n not in used]
    prev_used = used
    prev_skills = skills
    prev_cost = cost
    for i in candidates:
        min_cost = min(min_cost, dfs(CA, prev_cost, prev_skills, i, prev_used, min_cost))
  return min_cost
       

for i in range(N):
  Pdb().set_trace()
  used = []
  cost = 0
  skills = [0] * M
  min_cost = min(min_cost, dfs(CA, cost, skills, i, used, min_cost)) 

print(min_cost)

Fixed submission:
N, M, X = [int(n) for n in input().split()]

CA = [list(map(int, input().split())) for n in range(N)]

ans = 10**10

for i in range(2**N):
  cost = 0
  skills = [0] * M
  for j in range(N):
    if ((i >> j) & 1):
      #print(i, j)
      for k in range(M):
        skills[k] += CA[j][1+k]
      cost += CA[j][0]
  #print("skills", skills)
  if all([n >= X for n in skills]):
  	ans = min(ans, cost)
  #print("ans", ans)
if ans == 10**10:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for n in range(N)]

ans =[]
for s in S:
  if s not in ans:
    ans.append(s)
print(len(ans))

Fixed submission:
N = int(input())
ans = set([input() for n in range(N)])
print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import math
              
K = int(input())
total = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            total += math.gcd(c,math.gcd(a,b))
print(total)

Fixed submission:
import math 
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
 
a = int(input())
 
ans = 0
 
for i in range(1,a+1):
    for j in range(1,i+1):
        for k in range(1,j+1):
            if i == j and i == k:
                ans += gcd(i,j,k)
            elif i == j or i == k or j == k:
                ans += gcd(i,j,k)*3
            else:
                ans += gcd(i,j,k)*6
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from math import gcd

K = int(input())
total = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            total += reduce(gcd, [a,b,c])
print(total)

Fixed submission:
import math 
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
 
a = int(input())
 
ans = 0
 
for i in range(1,a+1):
    for j in range(1,i+1):
        for k in range(1,j+1):
            if i == j and i == k:
                ans += gcd(i,j,k)
            elif i == j or i == k or j == k:
                ans += gcd(i,j,k)*3
            else:
                ans += gcd(i,j,k)*6
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r

pq_cnt = 0
r_cnt = 0
total = 0
for i in range(len(pq_rev)):
  if pq_rev[pq_cnt] < r_rev[r_cnt] and r_cnt < num_r:
    total += r_rev[r_cnt]
    r_cnt += 1
  else:
    total += pq_rev[pq_cnt]
    pq_cnt += 1

print(total)

Fixed submission:
x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

total = sum(sorted(pq_rev + r, reverse=True)[:x+y])
print(total)

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

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r

pq_cnt = 0
r_cnt = 0
total = 0
for i in range(len(pq_rev)):
  if pq_rev[pq_cnt] > r_rev[r_cnt]:
    total += pq_rev[pq_cnt]
    pq_cnt += 1
  else:
    total += r_rev[r_cnt]
    r_cnt += 1
print(total)

Fixed submission:
x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

total = sum(sorted(pq_rev + r, reverse=True)[:x+y])
print(total)

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

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r
total = sum(pq_rev[:(-1)*num_r])
#print(total)
pq_cnt=0
r_cnt = 0
for i in range(num_r):
  if pq_rev[start + pq_cnt] > r_rev[r_cnt]:
    total += pq_rev[start + pq_cnt]
    pq_cnt += 1
  else:
    total += r_rev[r_cnt]
    r_cnt += 1
print(total)

Fixed submission:
x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

total = sum(sorted(pq_rev + r, reverse=True)[:x+y])
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]

#print(N)
#print(A)
all = {}
for a in A:
  if a not in all:
    all[a] = 0
  all[a] +=1

#print(all)
for k in range(len(A)):
  ans = 0
  for key, v in all.items():
    if v > 1:
      if key == A[k]:
      	ans += int(max(int(v-1)*(v-2)/2, 0))
      else:
        ans += int(v*(v-1)/2)

  print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

#print(N)
#print(A)
all = {}
for a in A:
  if a not in all:
    all[a] = 0
  all[a] +=1

#print(all)
total = 0
for key, v in all.items():
  total += int(v*(v-1)/2)

for k in range(len(A)):
  ans = total - (all[A[k]] -1)
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
  T = input().split()
  #print("S", S)
  #print("T", T)
  if T[0] == '1':
    S = S[::-1]
  elif T[0] == '2':
    if T[1] == '1':
      S = T[2] + S 
    elif T[1] == '2':
      S = S + T[2]
print(S)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
queue = deque(S)

rev_cnt = 0
rev = 0
for i in range(Q):
  query = input().split()
  if query[0]=="1":
    rev_cnt += 1
    rev = rev_cnt % 2
  elif query[0]=="2":
    #print(query)
    s=query[2]
    if query[1] == "1" and rev == 0:
      queue.appendleft(s)
    elif query[1] == "1" and rev == 1:
      queue.append(s)
    elif query[1] == "2" and rev == 0:
      queue.append(s)
    elif query[1] == "2" and rev == 1:
      queue.appendleft(s)
if rev == 0:
  print(''.join(list(queue)))
else:
  print(''.join(reversed(list(queue))))
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(i) for i in  input().split()]
length = len(H)
h = [0]*length
def z_counter(start):
  cnt = 0
  for i in range(start+1, length):
    if H[i] <= H[i-1]:
      cnt += 1
    else:
      break
  return cnt
for i in range(1, length):
  h[i] = z_counter(i)
  ans = max(h)

print(ans)

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
h=[0]*N
count=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        count+=1
    else:
        count=0
    h[i]=count
print(max(h))

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(i) for i in  input().split()]
length = len(H)
def z_counter(start):
  cnt = 0
  for i in range(start+1, length):
    if H[i] <= H[i-1]:
      cnt += 1
    else:
      break
  return cnt
ans = []
for i in range(1, length):
  ans.append(z_counter(i))

print(max(ans))

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
h=[0]*N
count=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        count+=1
    else:
        count=0
    h[i]=count
print(max(h))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = [int(i) for i in  input().split()]
length = len(H)
def z_counter(start):
  cnt = 0
  for i in range(start+1, length):
    if H[i] <= H[i-1]:
      cnt += 1
    else:
      break
  return cnt
ans = 0
for i in range(1, length):
  ans = max(ans, z_counter(i))

print(ans)

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
h=[0]*N
count=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        count+=1
    else:
        count=0
    h[i]=count
print(max(h))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

cnt=0
for n in range(1,N+1):
  item_cnt=0
  num_digit =len(str(n))
  chk_n = n
  chk_7 = 0
  chk_5 = 0
  chk_3 = 0
  for i in range(num_digit):
    a = chk_n % 10
    chk_n = chk_n // 10
    if a == 7:
      chk_7 += 1
      item_cnt += 1
      if item_cnt == num_digit and chk_7 > 0 and chk_5 > 0 and chk_3 >0:
        cnt +=1
        #print(n)
        break
    elif a== 5:
      chk_5 += 1
      item_cnt += 1
      if item_cnt == num_digit and chk_7 > 0 and chk_5 > 0 and chk_3 >0:
        cnt +=1
        #print(n)
        break
    elif a == 3:
      chk_3 += 1
      item_cnt += 1
      if item_cnt == num_digit and chk_7 > 0 and chk_5 > 0 and chk_3 >0:
        cnt +=1
        #print(n)
        break      
   
    else:
      break
print(cnt)

Fixed submission:
N = int(input())

def calculate(s):
  if len(s) > 1:
    if int(s) > N:
      return 0
  
  ret = 1 if all([s.count(c) for c in '753']) else 0
  
  for i in '753':
    ret +=calculate(s+i)
  return ret

print(calculate(''))
Buggy python submission (verdict: Runtime Error):
S, T = [input() for _ in range(2)]

S = sorted(S)
T = sorted(T)
print(S,T)
flg = False
if len(S) < len(T):
  flg =True
      
if len(S) == len(T):
  for i in range(len(S)):
    if T[i] > s[i]:
      print("T>S")
      flg =True
    
if flg:
  print('Yes')
else:
  print('No')

Fixed submission:
s = input()
s_dash = sorted(s)
#print(s_dash)

t = input()
t_dash = sorted(t, reverse=True)
#print(t_dash)

if s_dash < t_dash:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
S, T = [input() for _ in range(2)]

S = sorted(S)
T = sorted(T)
print(S,T)
flg = False
if len(S) < len(T):
  for i, s in enumerate(S):
    print(T[i], s)
    if T[i] <= s:
      #print("T>S")      
      flg = True
      
if len(S) == len(T):
  for i, s in enumerate(S):
    if T[i] < s[i]:
      #print("T>S")
      flg =True
    
if flg:
  print('Yes')
else:
  print('No')

Fixed submission:
s = input()
s_dash = sorted(s)
#print(s_dash)

t = input()
t_dash = sorted(t, reverse=True)
#print(t_dash)

if s_dash < t_dash:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
import math
print(math.factorial(int(input())) /(10**9 +7))

Fixed submission:
import math
print(math.factorial(int(input())) % (10**9 +7))
Buggy python submission (verdict: Runtime Error):
L, N = list(map(int, input().split()))
S = [str(input()) for _ in range(N)]

#print(S)
S = sorted(S)
#print("sorted", S)
total = "".join(S)
print(total)

Fixed submission:
N, L = map(int, input().split())
S = []
for i in range(N):
    line = input()
    S.append(line)
S.sort()
print("".join(S))

Buggy python submission (verdict: Runtime Error):
L, N = list(map(int, input().split()))
S = [str(input()) for _ in range(N)]

#print(S)
S = sorted(S)
#print("sorted", S)

total = ''
for i in range(len(S)):
  total += str(S[i])

print(total)

Fixed submission:
N, L = map(int, input().split())
S = []
for i in range(N):
    line = input()
    S.append(line)
S.sort()
print("".join(S))

Buggy python submission (verdict: Runtime Error):
L, N = list(map(int, input().split()))
S = [input() for _ in range(N)]

#print(S)
S = sorted(S)
#print("sorted", S)

total = ''
for i in range(len(S)):
  total += S[i]

print(total)

Fixed submission:
N, L = map(int, input().split())
S = []
for i in range(N):
    line = input()
    S.append(line)
S.sort()
print("".join(S))
Buggy python submission (verdict: Runtime Error):
numbers = str(input())
ans = 0
for(i = 0;i<3;i++){
	if(numbers[i] == "7")
  		ans =1
}
if(ans == 0){
	print("No")
}else{
	print("Yes")
}

Fixed submission:
numbers = str(input())
ans = 0
for i in range(3):
	if numbers[i] == "7":
  		ans =1
if ans == 0:
	print("No")
else :
	print("Yes")
Buggy python submission (verdict: Runtime Error):
from itertools import *
X,Y = map(int,input().split())
if X*2 == Y:
    print("Yes")
elif X*4 == Y:
    print("Yes")
else:
    tmp = [2 for i in range(25)]+[4 for i in range(25)]
    li = set(combinations(tmp,X))
    for i in li:
        if sum(i) == Y:
            print("Yes")
            exit()
    print("No")


Fixed submission:
print(list(map(int,input().split())).index(0)+1)

Buggy python submission (verdict: Runtime Error):
from itertools import *
X,Y = map(int,input().split())
if X*2 == Y:
    print("Yes")
elif X*4 == Y:
    print("Yes")
else:
    tmp = [2 for i in range(20)]+[4 for i in range(20)]
    li = set(combinations(tmp,X))
    for i in li:
        if sum(i) == Y:
            print("Yes")
            exit()
    print("No")


Fixed submission:
print(list(map(int,input().split())).index(0)+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int,input().split()))
mul = eval('*'.join([str(n) for n in arr]))
print("-1" if mul > (10**18) else mul)

Fixed submission:
a,b = map(int,input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import *
ip = stdin.readline
n = int(ip())
arr = list(map(int,ip().split()))
mul = 1
for i in arr:
    mul *= i
print("-1" if mul > (10**18) else mul)

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

if 0 in arr:
    print(0)
else:
    r = 1
    for i in arr:
        if r*i > 10**18:
            print(-1)
            exit()
        r *= i
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import *
ip = stdin.readline
n = int(ip())
arr = list(map(int,ip().split()))
mul = 1
for i in arr:
    mul *= i
print("-1" if mul > (10**18) else mul)

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

if 0 in arr:
    print(0)
else:
    r = 1
    for i in arr:
        if r*i > 10**18:
            print(-1)
            exit()
        r *= i
    print(r)

Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int,input().split()))
mul = eval('*'.join([str(n) for n in arr]))
print("-1" if mul > (10**18) else mul)

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

if 0 in arr:
    print(0)
else:
    r = 1
    for i in arr:
        if r*i > 10**18:
            print(-1)
            exit()
        r *= i
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
n = int(input())
arr = list(map(int,input().split()))
def multiply(arr):
    return reduce(lambda x, y: x * y, arr)
mul = multiply(arr)
print("-1" if mul > (10**18) else mul)

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

if 0 in arr:
    print(0)
else:
    r = 1
    for i in arr:
        if r*i > 10**18:
            print(-1)
            exit()
        r *= i
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = list(map(int,input().split()))
mul = 1
for i in arr:
    mul *= i
print("-1" if mul > (10**18) else mul)

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

if 0 in arr:
    print(0)
else:
    r = 1
    for i in arr:
        if r*i > 10**18:
            print(-1)
            exit()
        r *= i
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = list(map(int,input().split()))
mul = 1
for i in arr:
    mul *= i
print("-1" if mul > (10**18) else mul)

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

if 0 in arr:
    print(0)
else:
    r = 1
    for i in arr:
        if r*i > 10**18:
            print(-1)
            exit()
        r *= i
    print(r)
Buggy python submission (verdict: Runtime Error):
1print('ABC' if input()=='ARC' else 'ARC')

Fixed submission:
print('ABC' if input()=='ARC' else 'ARC')
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = set()
for _ in range(k):
    input()
    s.add(*list(map(int, input().split())))
print(n - len(s))

Fixed submission:
n, k = map(int, input().split())
s = set()
for _ in range(k):
    input()
    a = list(map(int, input().split()))
    for i in a:
        s.add(i)
print(n - len(s))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    ipt = list(map(int, input().split()))
    k.append(ipt[0])
    s.append(ipt[1:])
p = list(map(int, input().split()))
cnt = 0
for sw in (list(format(i, f'0{n}b')) for i in range(2 ** n)):
    for i in range(m):
        if sum([int(sw[j - 1]) for j in s[i]]) % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)

Fixed submission:
n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    ipt = list(map(int, input().split()))
    k.append(ipt[0])
    s.append(ipt[1:])
p = list(map(int, input().split()))
cnt = 0
for sw in (list(format(i, '0{}b'.format(n))) for i in range(2 ** n)):
    for i in range(m):
        if sum([int(sw[j - 1]) for j in s[i]]) % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import itertools
from functools import reduce
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
C = [list(i) for i in itertools.combinations(A, K)]
digits = [[] for i in range(len(C))]
for i, v in enumerate(C): 
  for j in v: 
    digits[i].append(len(str(abs(j))))
max_digits = max([reduce(lambda x, y: x+y, j) for j in digits])
res = [reduce(lambda x, y: x*y%MOD, j) for j in C]
res = [i for i in res if len(str(i)) <= max_digits]
ans = max(res)
if ans < 0:
  print(ans % MOD)
else:
  print(ans)

Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
MOD = 10 ** 9 + 7
s, t = [], []  # 正、負の配列
for i in a:
  if i < 0:
    t.append(i)
  else:
    s.append(i)
S, T = len(s), len(t)
is_positive = False  # 積が正である
if S > 0:
  # 正の数が0より大きい
  if n == k:
    # nとkが同じ
    is_positive = (T % 2 == 0) # 負の数が偶数個のとき、積は正
  else:
    is_positive = True
else:
  is_positive = (k % 2 == 0)

ans = 1
if not is_positive:
  a.sort(key=abs)
  for i in range(k):
    ans = ans * a[i] % MOD
else:
  s.sort()
  t.sort(reverse=True)
  if k % 2 == 1:
    ans = ans * s.pop(-1) % MOD
  p = []
  while(len(s) >= 2):
    x = s.pop(-1)
    x *= s.pop(-1)
    p.append(x)
  while(len(t) >= 2):
    x = t.pop(-1)
    x *= t.pop(-1)
    p.append(x)
  p.sort(reverse=True)
  for i in range(k // 2):
    ans = ans * p[i] % MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import zip_longest
import sys

sys.maxsize
N, M, K = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
# iter_A = iter(A)
# iter_B = iter(B)
S = sum(A) + sum(B)
S_len = len(A) + len(B)
if K >= S:
    print(S_len)
else:
    ans = 0
    a_index = 0
    b_index = 0
    while K >= 0:
        for i in range(max(len(A), len(B))):
            if K < 0:
                break
            if A[a_index] <= B[b_index]:
                if K < 0:
                    break
                K -= A[a_index]
                a_index += 1
                ans += 1
            elif A[a_index] > B[b_index]:
                if K < 0:
                    break
                K -= B[b_index]
                b_index += 1
                ans += 1
    print(ans - 1)


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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
count = Counter(a)
q = int(input())
b_c = [list(map(int, input().split())) for i in range(q)]
for i in b_c:
  count[i[1]] += count[i[0]]
  count[i[0]] = 0
  ans = 0
  for k, v in count.items():
    ans += k * v
  print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
s = sum(a)
count = Counter(a)
q = int(input())
b_c = [list(map(int, input().split())) for i in range(q)]
for i in b_c:
  s += (i[1] - i[0]) * count[i[0]]
  count[i[1]] += count[i[0]]
  count[i[0]] = 0
  print(s)