Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
date = int(input().replace("/", ""))
if date <= 20190430:
    print("Heisei")
else:
    print("TBD")S = list(map(int, input().split("/")))
ans = True
if S[0] > 2019:
    ans = False
elif S[0] == 2019 and S[1] > 4:
    ans = False

if ans:
    print("Heisei")
else:
    print("TBD")

Fixed submission:
date = input()

import re
date_num = int(re.sub("\D", "", date))

if date_num <= 20190430:
    print("Heisei")
else:
    print("TBD")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

a.sort(reverce = True)

alice = sum(a[0::2])
bob = sum(a[1::2])

print(alice - bob)


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

alice = 0
bob = 0

a.sort(reverse = True)

i = 0

while True:
    if i >= n:
        break
    alice += a[i]
    i += 1
    if i >= n:
        break
    bob += a[i]
    i += 1

print(alice - bob)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(a+b/2)

Fixed submission:
a,b = map(int,input().split())
c = int(a+b/2)
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
pool=[0]*n
for i in range(n-1):
    if s[i]=='R' and s[i+1]=='L':
        pool[i]=1
        pool[i+1]=2
final=[0]*n
for i in range(n):
    index=i
    flag=0
    while pool[index]==0:
        if s[index]=='R':
            flag=1-flag
            index+=1
        else:
            flag=1-flag
            index-=1
    if pool[index]==1:
        if flag==0:
            final[index]+=1
        else:
            final[index+1]+=1
    else:
        if flag==0:
            final[index]+=1
        else:
            final[index-1]+=1
for i in final:
    print(i,end=" ")


Fixed submission:
s=input()
n=len(s)
pool=[]
blue=[0]*n
final=[0]*n
for i in range(n-1):
    if s[i]=='R' and s[i+1]=='L':
        pool.append(i)
        pool.append(i+1)
        blue[i]=1
        blue[i+1]=1
        final[i]+=1
        final[i+1]+=1
counter=-1
for i in range(n):
    if blue[i]==1:
        counter+=1
    else:
        if s[i]=='L':
            index=pool[counter]
            if (i-index)%2==0:
                final[index]+=1
            else:
                final[index-1]+=1
        else:
            index=pool[counter+1]
            if (index-i)%2==0:
                final[index]+=1
            else:
                final[index+1]+=1
f=[str(i) for i in final]
print(' '.join(f))
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

n=int(input())
arr=[int(i) for i in input().split()]
sum=0
for i in range(n):
    sum+=arr[i]
sum//=2
for x in range(n):
    ex=0
    i=x
    while(True):
        ex+=arr[i]
        i+=2
        i%=n
        if (i+1)%n==x:
            ex+=arr[i]
            break

    print(((ex-sum)*2),end=" ")


Fixed submission:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

n=int(input())
arr=[int(i) for i in input().split()]
sum=0
for i in range(n):
    sum+=arr[i]
sum//=2
ans=0
for x in range(0,1):
    ex=0
    i=x
    while(True):
        ex+=arr[i]
        i+=2
        i%=n
        if (i+1)%n==x:
            ex+=arr[i]
            break

    ans=((ex-sum))
io=0
while(io!=n):
    print(ans*2,end=" ")
    ans=arr[(io)%n]-ans
    io+=1

Buggy python submission (verdict: Runtime Error):
# your code goes here
import numpy as np
n=int(input())
arr=[[0]*n]
arr=arr*n
#print(arr)

A=np.array(arr)
for i in range(n):
	A[i][i]=1
	#print(A)
	A[i][(i+1)%n]=1
#print(A)

B=np.linalg.inv(A)
c=[int(i) for i in input().split()]
C=np.array(c)
x=np.matmul(C,B)
#print(x)
for i in range(-1,x.shape[0]-1):
	print(int(x[i%n]*2),end=" ")

Fixed submission:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

n=int(input())
arr=[int(i) for i in input().split()]
sum=0
for i in range(n):
    sum+=arr[i]
sum//=2
ans=0
for x in range(0,1):
    ex=0
    i=x
    while(True):
        ex+=arr[i]
        i+=2
        i%=n
        if (i+1)%n==x:
            ex+=arr[i]
            break

    ans=((ex-sum))
io=0
while(io!=n):
    print(ans*2,end=" ")
    ans=arr[(io)%n]-ans
    io+=1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += a[i] * a[j]

print(ans%(10**9+7))


Fixed submission:
import copy
n = int(input())
a = list(map(int,input().split()))
a_2 = copy.copy(a)
a_2.reverse()
sinu = [0] * n
t = 0
for i in range(n):
    t += a_2[i]
    sinu[i] += t
sinu.reverse()

ans = 0
for i in range(n-1):
    #print(a[i],sinu[i+1])
    ans += a[i] * sinu[i+1]

    
print(ans%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))

t = 0
for i in range(n-k+1):
    t_2 = 0
    if i == 0:
        for j in range(k):
            t += a[j+i]
        continue
    for j in range(k):
        t_2 += a[j+i]
    if t_2>t:
        print("Yes")
    else:
        print("No")
    t = t_2


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

for i in range(n-k):
    if a[i+k] > a[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
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 = (ans, i + j)
print(ans)


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: Runtime Error):
import numpy as np
n = int(input())
a = list(map(int,input().split()))

ans = np.prod(a)
if ans >= 10**18:
    ans = -1
print(ans)


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

if 0 in a:
    print(0)
    exit()

c = 1
for i in a:
    c *= i
    if c > 10 ** 18:
        print(-1)
        exit()

print(c)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
a_m = max(a)
tt = [-1] * a_m
tt[0] = 0
ans_l = []

i = 0
while True:
    if tt[a[i]-1] != -1:
        loop = i - tt[a[i]-1]
        k -= tt[a[i]-1]
        break
    tt[a[i]-1] = i + 1
    ans_l.append(a[i])
    i += 1

ans_c = k % loop
print(ans_l[ans_c+tt[a[i]-1]])


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

num = 1
li = [1]
flag = [True] * n
flag[0] = False

for i in range(k):
    num = a[num-1]
    if flag[num-1]:
        li.append(num)
        flag[num-1] = False
    else:
        break

d = li.index(num)
ans = (k-d)%(len(li)-d)+d

print(li[ans])
Buggy python submission (verdict: Runtime Error):
s = input()

if s == "ABC":
  ans = "ARC"
else:
  ans = "ABC"
  
 print(ans)


Fixed submission:
s = input()

if s == "ABC":
  ans = "ARC"
else:
  ans = "ABC"
  
print(ans)

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

if s == "ABC":
  ans = "ARC"
 else:
  ans = "ABC"
  
 print(ans)

Fixed submission:
s = input()

if s == "ABC":
  ans = "ARC"
else:
  ans = "ABC"
  
print(ans)
Buggy python submission (verdict: Runtime Error):
x = int(input())

for a in range(1000):
    for b range(1000):
        if a ** 5 - b ** 5 == x:
            print(a,b)
            exit()
            


Fixed submission:
x = int(input())

for a in range(-1000,1000):
    for b in range(-1000,1000):
        if a ** 5 - b ** 5 == x:
            print(a,b)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())

f = 1
while True:
    if f:
        c -= b
        f = 0
        if c == 0:
            print("Yes")
            break
    else:
        a -= d
        f = 1
        if a == 0:
            print("No")
            break
    


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

ans_1 = math.ceil(c / b)
ans_2 = math.ceil(a / d)

#print(ans_1,ans_2)
if ans_1 > ans_2:
    print("No")
else:
    print("Yes")

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

f = 1
while True:
    if a == 0:
        print("No")
        break
    elif c == 0:
        print("Yes")
        break
    if f:
        c -= b
        f = 0
    else:
        a -= d
        f = 1
    


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

ans_1 = math.ceil(c / b)
ans_2 = math.ceil(a / d)

#print(ans_1,ans_2)
if ans_1 > ans_2:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

for i in range(1,n+1):
    print(a.count(i))


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

ans = [0 for i in range(n)]
for i in a:
    ans[i-1] += 1

for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
t = [[] for _ in range(n)]
for i in range(m):
    t_1,t_2 = map(int,input().split())
    t[t_1-1].append(t_2)

ans = ""
for i in range(n):
    if len(set(t[i])) == 1:
        ans += str(t[i][0])
    if not t[i]:
        if i == 0:
            ans += "1"
        else:
            ans += "0"
if ans[0] == "0":
    if n == 1:
        print(0)
    else:
        print(-1)
else:
    print(ans)


Fixed submission:
n,m = map(int,input().split())
t = [[] for _ in range(n)]
for i in range(m):
    t_1,t_2 = map(int,input().split())
    t[t_1-1].append(t_2)

ans = ""
for i in range(n):
    if len(set(t[i])) == 1:
        ans += str(t[i][0])
    elif not t[i]:
        if i == 0:
            if n == 1:
                ans += "0"
            else:    
                ans += "1"
        else:
            ans += "0"
    else:
        print(-1)
        exit()
if ans[0] == "0":
    if n == 1:
        print(0)
    else:
        print(-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
t = [[] for _ in range(n)]
for i in range(m):
    t_1,t_2 = map(int,input().split())
    t[t_1-1].append(t_2)

ans = ""
for i in t:
    if len(set(i)) == 1:
        ans += str(i[0])
    if not i:
        ans += "0"
if ans[0] == "0":
    if n == 1:
        print(0)
    else:
        print(-1)
else:
    print(ans)


Fixed submission:
n,m = map(int,input().split())
t = [[] for _ in range(n)]
for i in range(m):
    t_1,t_2 = map(int,input().split())
    t[t_1-1].append(t_2)

ans = ""
for i in range(n):
    if len(set(t[i])) == 1:
        ans += str(t[i][0])
    elif not t[i]:
        if i == 0:
            if n == 1:
                ans += "0"
            else:    
                ans += "1"
        else:
            ans += "0"
    else:
        print(-1)
        exit()
if ans[0] == "0":
    if n == 1:
        print(0)
    else:
        print(-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
t = [[] for _ in range(n)]
for i in range(m):
    t_1,t_2 = map(int,input().split())
    t[t_1-1].append(t_2)

ans = ""
for i in t:
    if len(set(i)) == 1:
        ans += str(i[0])
    if not i:
        ans += "0"
if ans[0] == "0":
    print(-1)
else:
    print(ans)


Fixed submission:
n,m = map(int,input().split())
t = [[] for _ in range(n)]
for i in range(m):
    t_1,t_2 = map(int,input().split())
    t[t_1-1].append(t_2)

ans = ""
for i in range(n):
    if len(set(t[i])) == 1:
        ans += str(t[i][0])
    elif not t[i]:
        if i == 0:
            if n == 1:
                ans += "0"
            else:    
                ans += "1"
        else:
            ans += "0"
    else:
        print(-1)
        exit()
if ans[0] == "0":
    if n == 1:
        print(0)
    else:
        print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
for i in range(K):
    if A == 0:
        K_2 = K - i
        break
    A -= 1
for i in range(K_2):
    B -= 1
print(A,B)


Fixed submission:
A,B,K = map(int,input().split())
if K == 0:
    print(A,B)
    exit()
if (A+B) < K:
    print(0,0)
    exit()
elif A > K:
    A -= K
else:
    A -= K
    if A != 0:
        B += A
        A -= A
print(A,B)
Buggy python submission (verdict: Runtime Error):
x = int(input())
while True:
    for i in range(2,int(x**0.5)+1):
        if x % i == 0:
            c = False
            break
        c = True
    if c == True:
        print(x)
        break
    elif c == False:
        x += 1
        
    


Fixed submission:
x = int(input())
if x == 2:
    print(2)
    exit()
elif x == 3:
    print(3)
    exit()
while True:
    for i in range(2,int(x**0.5)+1):
        if x % i == 0:
            c = False
            break
        c = True
    if c == True:
        print(x)
        break
    elif c == False:
        x += 1
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
A,B = int(input().split())
print((A*B) // gcd(A,B))


Fixed submission:
from fractions import gcd
A,B = map(int,input().split())
print((A*B) // gcd(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

a_2 = sorted(a)
for i in range(n):
    print(a.index(a_2[i])+1,end=" ")
    


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = [0] * n

for i in range(n):
    ans[a[i]-1] = i + 1
    
print(*ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

ans = []
c = 0
for i in range(n-1):
    if h[i+1] <= h[i]:
        c += 1
        if i == n-2:
            ans.append(c)
    elif h[i+1] > h[i]:
        ans.append(c)
        c = 0

print(max(ans))


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

ans = []
c = 0
for i in range(n-1):
    if h[i+1] <= h[i]:
        c += 1
        if i == n-2:
            ans.append(c)
    elif h[i+1] > h[i]:
        ans.append(c)
        c = 0

if not ans:
    print(0)
    exit()
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = []
for i in range(n):
    s = input()
    l.append("".join(sorted(s)))

l_2 = set(l)
ans = 0
k = l.count
for j in l_2:
    i = k(j)
    ans += int((i*(i-1))/2)

print(ans)


Fixed submission:
import collections

n = int(input())

l = []
for i in range(n):
    s = input()
    l.append("".join(sorted(s)))

l_2 = collections.Counter(l)
ans = 0
for j in l_2.values():
    ans += int((j*(j-1))/2)

print(ans)

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

l = []
for i in range(n):
    s = input()
    l.append("".join(sorted(s)))

l_2 = set(l)
ans = 0
for j in l_2:
    i = l.count(j)
    ans += int((i*(i-1))/2)

print(ans)


Fixed submission:
import collections

n = int(input())

l = []
for i in range(n):
    s = input()
    l.append("".join(sorted(s)))

l_2 = collections.Counter(l)
ans = 0
for j in l_2.values():
    ans += int((j*(j-1))/2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
c = a.count(max(a))
a_2 = copy.copy(a)

if c > 1:
    for i in range(n):
        print(max(a))
else:
    t = max(a)
    a_2.remove(t)
    t_2 = max(a_2)
    for i in a:
        if i == t:
            print(t_2)
        else:
            print(t)


Fixed submission:
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
c = a.count(max(a))
a_2 = copy.copy(a)
t = max(a)

if c > 1:
    for i in range(n):
        print(t)
else:
    a_2.remove(t)
    t_2 = max(a_2)
    for i in a:
        if i == t:
            print(t_2)
        else:
            print(t)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
x = list(map(int,input().split()))
t_3 = max(x) - min(x)
t = []
t_2 = 0
x.sort()
if m == 1:
    print(0)
    exit()

for i in range(m-1):
    t.append(x[i+1]-x[i])

t.sort(reverse=True)
for i in range(n-1):
    t_2 += t[i]

print(t_3-t_2)


Fixed submission:
n,m = map(int,input().split())
x = list(map(int,input().split()))
t_3 = max(x) - min(x)
t = []
t_2 = 0
x.sort()
if m == 1:
    print(0)
    exit()

for i in range(m-1):
    t.append(x[i+1]-x[i])

t.sort(reverse=True)
pp = min(n-1,m-1)
for i in range(pp):
    t_2 += t[i]

print(t_3-t_2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
for i in range(N):
    t = int(input())
    if t in a:
        a.remove(t)
        continue
    a.append(t)
    
print(len(a))


Fixed submission:
N = int(input())
a = [input() for _ in range(N)]
a = sorted(a)
#print(a)
c = 0
ans = 0
for i in range(N):
    c += 1
    if i == N-1:
        if c % 2 == 1:
            ans += 1
    elif a[i] != a[i+1]:
        #print(a[i])
        if c % 2 == 1:
            ans += 1
        c = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
b = 1
c = 1
d = []
for i in range(n):
    a.append(int(input()))
while True:
    d.append(b-1)
    b = a[b-1]
    if b == 2:
        print(c)
        break
    if (b-1) in d:
        print(-1)
        break
    c += 1
    


Fixed submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

k = 1
p = False
for i in range(n):
    if a[k-1] == 2:
        print(i+1)
        p = True
        break
    k = a[k-1]
if not p:
    print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

k = 1
p = False
for i in range(n):
    if a[k-1] == 2:
        print(i+1)
        p = True
        break
    k = a[k-1]
if not p:
    print(-1)


Fixed submission:
a,b,c = map(int,input().split())
for i in range(b):
    if i * a % b == c:
        print("YES")
        exit()
print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
for i in range(n):
    i = i+1
    ans = ans * i
print(ans%(10**9+7))


Fixed submission:
n = int(input())
ans = 1
for i in range(n):
    i = i+1
    ans = (ans * i) % (10**9+7)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys


def dfs(idx):
    for x in arr[idx]:
        if not vis[x]:
            vis[x] = True
            dfs(x)


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

arr = [[] * (n + 1) for _ in range(n + 1)]
vis = [False] * (n + 1)

for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    arr[a].append(b)
    arr[b].append(a)

ans = 0

dfs(1)
for i in range(2, n + 1):
    if not vis[i]:
        vis[i] = True
        dfs(i)
        ans += 1
for i in range(1, n + 1):
    if not vis[i]:
        ans += 1
print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)


def dfs(idx):
    for x in arr[idx]:
        if not vis[x]:
            vis[x] = True
            dfs(x)


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

arr = [[] * (n + 1) for _ in range(n + 1)]
vis = [False] * (n + 1)

for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    arr[a].append(b)
    arr[b].append(a)

ans = 0

if m == 0:
    print(n-1)
    sys.exit()

dfs(1)
for i in range(2, n + 1):
    if not vis[i]:
        vis[i] = True
        dfs(i)
        ans += 1

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

ans = 0

print((n-1)+len(range(n**(1/2))))

Fixed submission:
n = int(input())
ans = 0
for a in range(1, n):
  ans += (n - 1) // a
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

if x >= 30:
  print('Yes')
else:
  print('No')

Fixed submission:
x = int(input())
 
if x >= 30:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

for i in range(1, n+1):
    count = 0
    for x in range(1, int(i**(1/2))+1):
        for y in range(1, int(i**(1/2))+1):
            for z in range(1, int(i**(1/2))+1):
                if ((x+y+z)**2 - x*y - y*z - z*x) == i:
                    count += 1
    print(count)

Fixed submission:
n = int(input())
ans = [0] * (n + 1)
 
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if val <= n:
                ans[val] += 1
 
print(*ans[1:], sep="\n")

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

loop = int(n**(1/2))

for i in range(1, n+1):
    count = 0
    for x in range(1, loop+1):
        for y in range(1, loop+1):
            for z in range(1, loop+1):
                if ((x+y+z)**2 - x*y - y*z - z*x) == i:
                    count += 1
    print(count)

Fixed submission:
n = int(input())
ans = [0] * (n + 1)
 
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if val <= n:
                ans[val] += 1
 
print(*ans[1:], sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split())) 
q = int(input())

arr = [0] * (10**5+1)
# arr = [i for i in range(1, 10**5+1)]

for i in A:
    arr[i] += i

for _ in range(q):
    b, c = map(int, input().split())
    arr[c] += (arr[b]//b*c)
    arr[b] = 0

    print(sum(arr))


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

from collections import Counter
arr = Counter(A)
ans = sum([i*arr[i] for i in arr])
 
for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)

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

from collections import Counter
a = Counter(A)
x = 0

for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0

    s = sum(item*a[item] for item in a if item!=0)
    # s = 0
    # for i,v in a.items():
    #     if v != 0:
    #         s += i*v
    print(s)

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

from collections import Counter
arr = Counter(A)
ans = sum([i*arr[i] for i in arr])
 
for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)

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

from collections import Counter
a = Counter(A)
x = 0

for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0

    s = sum(item*a[item] for item in a)
    # s = 0
    # for i,v in a.items():
    #     if v != 0:
    #         s += i*v
    print(s)

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

from collections import Counter
arr = Counter(A)
ans = sum([i*arr[i] for i in arr])
 
for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)

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

from collections import Counter
a = Counter(A)
x = 0

for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0

    s = 0
    for i,v in a.items():
        if v != 0:
            s += i*v
    print(s)

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

from collections import Counter
arr = Counter(A)
ans = sum([i*arr[i] for i in arr])
 
for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split())) 

ans = 1

exit
for i in a:
    ans *= i

if ans <= 10**18:
    print(ans)
else:
    print(-1)

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

ans = 1

if 0 in a:
    print(0)
    exit()

for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()
        
print(ans)