ZhenlongDai/ACPR huggingface dataset:
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
*a,=map(int, input().split())
from collections import Counter
ca=Counter(a)
q=int(input())
sm=sum(a)
for _ in range(q):
    bi,ci=map(int, input().split())
    if ci in ca:
        if bi in ca:
            sm+=(ci-bi)*ca[ci]
            ca[ci]+=ca[bi]
            del ca[bi]
    else:
        if bi in ca:
            sm+=(ci-bi)*ca[ci]
            ca[ci]=ca[bi]
            del ca[bi]
    print(sm)
        
        

Failing test case input:
4
0 1 1 1
3
1 2
2 1
0 5

Expected output:
6
3
8


Actual output:
3
3
3


Fixed submission (verdict: Accepted):
n=int(input())
*a,=map(int, input().split())
from collections import Counter
ca=Counter(a)
q=int(input())
sm=sum(a)
for _ in range(q):
    bi,ci=map(int, input().split())
    if ci in ca:
        if bi in ca:
            sm+=(ci-bi)*ca[bi]
            ca[ci]+=ca[bi]
            del ca[bi]
    else:
        if bi in ca:
            sm+=(ci-bi)*ca[bi]
            ca[ci]=ca[bi]
            del ca[bi]
    print(sm)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

for j in range(q):
 x,y=map(int,input().split())
 ans=-(x-y)*cnt[x]+sum
 cnt[x]+=cnt[y]
 print(ans)

Failing test case input:
4
-1 3 4 3
3
1 1
3 4
0 4

Expected output:
9
11
11


Actual output:
9
11
9


Fixed submission (verdict: Accepted):
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
  
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(y-x)*cnt[x]
 cnt[y]+=cnt[x]
 cnt[x]=0
 print(sum)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
n = int(input())
a_lst = list(map(int, input().split()))

cs = collections.Counter(a_lst)
res = sum(a_lst)
q = int(input())
for i in range(q):
  b, c = map(int, input().split())
  if b in cs:
    res = res - b * cs[b] + c * cs[b]
    if c in cs:
      cs[c] += cs[b]
      cs[b] = 0
    else:
      cs[c] = cs[b]
      cs[b] = 0      
    print(res)

Failing test case input:
2
1 2
3
1 100
2 001
110 1001

Expected output:
102
101
101


Actual output:
102
101


Fixed submission (verdict: Accepted):
import collections
n = int(input())
a_lst = list(map(int, input().split()))

cs = collections.Counter(a_lst)
res = sum(a_lst)
q = int(input())
for i in range(q):
  b, c = map(int, input().split())
  if b in cs:
    res = res - b * cs[b] + c * cs[b]
    if c in cs:
      cs[c] += cs[b]
      cs[b] = 0
    else:
      cs[c] = cs[b]
      cs[b] = 0
  print(res)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc =[list(map(int, input().split())) for _ in range(q)]
temp = [0] * (10**5 + 1)

for i in a:
    temp[i] += 1
ans = sum(a)
for i in range(q):
    b,c = bc[i][0],bc[i][1]
    ans = ans - temp[b] * b + temp[b] * c 
    print(ans)
    temp[c] += temp[b]
  


Failing test case input:
4
0 2 5 6
3
0 1
5 4
0 4

Expected output:
14
13
13


Actual output:
14
13
17


Fixed submission (verdict: Accepted):

  
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc =[list(map(int, input().split())) for _ in range(q)]
    temp = [0] * (10**5 + 1)
    
    for i in a:
        temp[i] += 1
    ans = sum(a)
    for i in range(q):
        b,c = bc[i][0],bc[i][1]
        ans = ans - temp[b] * b + temp[b] * c 
        print(ans)
        temp[c] += temp[b]
        temp[b] = 0
if __name__ == "__main__":
    main()

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] 
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10**5+1)
for i in range(10**5+1):
  numlist[i]=listA.count(i)
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  sum=sum+(C-B)*numlist[B]
  print(C)
  numlist[C]+=numlist[B]
  numlist[B]=0
  
  print(sum)


Failing test case input:
4
0 2 1 1
3
0 0
2 1
5 10

Expected output:
4
3
3


Actual output:
0
4
1
3
10
3


Fixed submission (verdict: Accepted):
N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] 
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10**5+1)
for i in listA:
  numlist[i]+=1
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  if numlist[B]!=0:
    sum=sum+(C-B)*numlist[B]
    
    numlist[C]+=numlist[B]
    numlist[B]=0
    
  print(sum)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
d=dict(Counter(a))
ans=sum(a)
q=int(input())
for _ in range(q):
    b,c=map(int,input().split())
    if b not in d.keys(): continue
    ans+=(c*d[b]-b*d[b])
    print(ans)
    if c in d.keys(): d[c]+=d[b]
    else: d[c]=d[b]
    d[b]=0

Failing test case input:
4
0 1 1 1
3
1 0
2 1
5 10

Expected output:
0
0
0


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
d=dict(Counter(a))
ans=sum(a)
q=int(input())
for _ in range(q):
    b,c=map(int,input().split())
    if b not in d.keys():
        print(ans)
        continue
    ans+=(c*d[b]-b*d[b])
    print(ans)
    if c in d.keys(): d[c]+=d[b]
    else: d[c]=d[b]
    d[b]=0
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

stra=str()
for i in numlista:
  stra+=str(i)

suma=0
for i in range(n):
  suma+=numlista[i]

q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  k=c-b
  o=stra.count(str(b))
  suma+=k*o
  print(suma)

Failing test case input:
4
0 2 5 8
3
0 4
5 4
0 4

Expected output:
19
18
18


Actual output:
19
18
22


Fixed submission (verdict: Accepted):

n=int(input())
numlista=list(map(int,input().split()))
import collections
numkosuu=collections.Counter(numlista)
suma=0
for i in numlista:
  suma+=i
q=int(input())
for i in range(q):
  b,c=map(int,input().split())

  suma+=(c-b)*numkosuu[b]

  numkosuu[c]+=numkosuu[b]
  numkosuu[b]=0
  print(suma)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections

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

ad = collections.Counter(a)
print(ad)

for i in range(q):
    b, c = map(int, input().split())
    s += ad.get(b, 0) * (c - b) 
    print(s)
    ad[c] += ad.get(b, 0)
    ad[b] = 0

Failing test case input:
4
0 1 1 1
3
1 4
2 1
0 8

Expected output:
12
12
20


Actual output:
Counter({1: 3, 0: 1})
12
12
20


Fixed submission (verdict: Accepted):
import collections

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

ad = collections.Counter(a)

for i in range(q):
    b, c = map(int, input().split())
    s += ad.get(b, 0) * (c - b) 
    print(s)
    ad[c] += ad.get(b, 0)
    ad[b] = 0

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import bisect
import collections
n=int(input())
a=sorted(list(map(int,input().split())))
q=int(input())
A=collections.Counter(a)
ans=sum(a)
for _ in range(q):
  b,c=map(int,input().split())
  k=A[b]
  ans=(c-b)*k+ans
  print(ans)
  del A[b]
  A[c]=k

Failing test case input:
4
1 0 2 1
3
0 2
2 1
3 13

Expected output:
6
4
4


Actual output:
6
5
5


Fixed submission (verdict: Accepted):
import bisect
import collections
n=int(input())
a=sorted(list(map(int,input().split())))
q=int(input())
A=collections.Counter(a)
ans=sum(a)
for _ in range(q):
  b,c=map(int,input().split())
  k=A[b]
  ans=(c-b)*k+ans
  print(ans)
  del A[b]
  A[c]+=k

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

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

b = []
c = []
for i in range(q):
	B, C = map(int, input().split())
	b.append(B)
	c.append(C)

arr = Counter(a)

s = sum(arr)

for i in range(q):
	s -= b[i]*arr[b[i]]
	s += c[i]*arr[c[i]]
	arr[c[i]] += arr[b[i]]
	arr[b[i]] = 0
	print(s)

Failing test case input:
4
1 1 1 1
3
1 2
2 0
3 5

Expected output:
8
0
0


Actual output:
-3
-11
-11


Fixed submission (verdict: Accepted):
from collections import Counter

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

cnt = Counter(a)

s = sum(a)

for i in range(q):
	b, c = map(int, input().split())
	s = s - b*cnt[b]
	s = s + c*cnt[b]
	cnt[c] += cnt[b]
	cnt[b] = 0
	print(s)
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter

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

ans = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    v = a[b]
    a[c] += v
    a[b] = 0
    ans += (c - b) * v
    print(ans)


Failing test case input:
4
0 1 1 1
3
1 2
2 1
3 5

Expected output:
6
3
3


Actual output:
4
1
1


Fixed submission (verdict: Accepted):
from collections import Counter

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

ans = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    ans += (c - b) * ac[b]
    ac[c] += ac[b]
    ac[b] = 0
    print(ans)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
u = []
for i in range(q):
    u.append(tuple(map(int,input().split())))

from collections import Counter
z = Counter(a)

sum = sum(a)
for i in range(q):
    try:
        rev = z.pop(u[i][0])
        print(sum+(u[i][1]-u[i][0])*rev)
        if u[i][1] in z.keys():
            z[u[i][1]]+=rev
        else:
            z[u[i][1]]=rev
    except KeyError:
        print(sum)

Failing test case input:
4
2 1 1 1
3
1 2
2 1
3 5

Expected output:
8
4
4


Actual output:
8
1
5


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
u = []
for i in range(q):
    u.append(tuple(map(int,input().split())))

from collections import Counter
z = Counter(a)

sum = sum(a)
for i in range(q):
    try:
        rev = z.pop(u[i][0])
        sum+=(u[i][1]-u[i][0])*rev
        print(sum)
        if u[i][1] in z:
            z[u[i][1]]+=rev
        else:
            z[u[i][1]]=rev
    except KeyError:
        print(sum)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
for i in range(q):
    b, c = map(int, input().split())
    if b in dic and c not in dic:
        dic[b] = dic[c]
        del dic[b]
    elif b in dic and c in dic:
        dic[c] += dic[b]
        del dic[b]
    sum_list = [x * y for (x, y) in dic.items()]
    print(sum(sum_list))


Failing test case input:
2
2 4
3
1 100
2 001
110 1001

Expected output:
6
5
5


Actual output:
6
4
4


Fixed submission (verdict: Accepted):
import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
sum_list = [x * y for (x, y) in dic.items()]
sum = sum(sum_list)
for i in range(q):
    b, c = map(int, input().split())
    if b in dic and c not in dic:
        sum -= (b - c) * dic[b]
        print(sum)
        dic[c] = dic[b]
        del dic[b]
    elif b in dic and c in dic:
        sum -= (b - c) * dic[b]
        print(sum)
        dic[c] += dic[b]
        del dic[b]
    else:
        print(sum)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):






N = int(input())



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























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

tot = sum(A)
cnt = [0] * 100001
for i in A:
    cnt[i] += 1


for l in B_C:
    cnt[l[1]] += cnt[l[0]]
    cnt[l[0]] = 0
    tot += cnt[l[0]] * (l[1] - l[0])
    print(tot)


Failing test case input:
4
0 2 5 6
3
0 2
5 4
0 4

Expected output:
15
14
14


Actual output:
13
13
13


Fixed submission (verdict: Accepted):






N = int(input())



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























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

tot = sum(A)
cnt = [0] * 100001
for i in A:
    cnt[i] += 1



for l in B_C:
    cnt[l[1]] += cnt[l[0]]
    tot += cnt[l[0]] * (l[1] - l[0])
    cnt[l[0]] = 0
    print(tot)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):







import collections

N=int(input())



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


Q=int(input())
c=collections.Counter(A)
s=sum(A)
for i in range(Q):
    
    B,C = map(int,input().split())
    print(c[B])
    if c[B]:
        s += (C-B)*c[B]
        c[C] += c[B]
        c[B] = 0

    print(s)


Failing test case input:
4
0 2 1 1
3
1 0
1 1
5 10

Expected output:
2
2
2


Actual output:
2
2
0
2
0
2


Fixed submission (verdict: Accepted):







import collections

N=int(input())



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


Q=int(input())
c=collections.Counter(A)
s=sum(A)
for i in range(Q):
    
    B,C = map(int,input().split())
    if c[B]:
        s += (C-B)*c[B]
        c[C] += c[B]
        c[B] = 0

    print(s)

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
t=int(input())
import math
a=list(map(int,input().strip().split()))
q=int(input())
h=[0]*(100000+1)
sumi=0
for i in range(len(a)):
    h[a[i]]+=1
    sumi+=a[i]
    
for i in range(q):
    b,c=map(int,input().strip().split())
    sumi+=h[b]*(c-b)
    h[c]+=h[b]
    print(sumi)
        
        
        
    
    
    
        
        
    
        
        
            
        
    


Failing test case input:
4
0 2 5 6
3
0 1
5 4
0 4

Expected output:
14
13
13


Actual output:
14
13
17


Fixed submission (verdict: Accepted):
t=int(input())
import math
a=list(map(int,input().strip().split()))
q=int(input())
h=[0]*(1000000+1)
sumi=0
for i in range(len(a)):
    h[a[i]]+=1
    sumi+=a[i]
 
for i in range(q):
    b,c=map(int,input().strip().split())
    
    sumi+=h[b]*(c-b)
    h[c]+=h[b]
    h[b]=0
    
    print(sumi)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
numbers = list(map(int,input().split()))
numOfOperation = int(input())
dic = {}

for num in numbers:
    if num in dic : dic[num] += 1
    else: dic[num] = 1
    

sums = sum(numbers)
for i in range(numOfOperation):
    B,C = map(int,input().split())
    if (B in dic) : 
        cnt = dic[B]
        dic[B] = 0
        if (C not in dic) : dic[C] = 1
        else : dic[C] += cnt
        sums += cnt * (C - B)
    print(sums)


Failing test case input:
4
1 1 1 1
3
1 2
2 1
3 5

Expected output:
8
4
4

Actual output:
8
7
7


Fixed submission (verdict: Accepted):
N = int(input())
numbers = list(map(int,input().split()))
numOfOperation = int(input())
dic = {}

for num in numbers:
    if num in dic : dic[num] += 1
    else: dic[num] = 1
    

sums = sum(numbers)
for i in range(numOfOperation):
    B,C = map(int,input().split())
    if (B in dic) : 
        cnt = dic[B]
        dic[B] = 0
        if (C not in dic) : dic[C] = cnt
        else : dic[C] += cnt
        sums += cnt * (C - B)
    print(sums)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

counter = Counter(A)
ans = 0
for num, count in counter.items():
    ans += num * count

for i in range(Q):
    if B[i] in counter:
        ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]
    print(ans)


Failing test case input:
4
2 1 1 1
3
1 2
2 1
3 5

Expected output:
8
4
4


Actual output:
8
7
7


Fixed submission (verdict: Accepted):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

counter = Counter(A)
ans = 0
for num, count in counter.items():
    ans += num * count

for i in range(Q):
    if B[i] in counter:
        ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]
        counter[C[i]] = counter[C[i]] + counter.pop(B[i])
    print(ans)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections

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

bc = [map(int, input().split()) for _ in range(Q)]
b, c= [list(i) for i in zip(*bc)]

count = collections.Counter(A)

sumA = sum(A)

for iter in range(Q):
    sumA += count[b[iter]]*(c[iter]- b[iter])
    c_tmp = count[c[iter]]
    count[c[iter]] += count[b[iter]] 
    count[b[iter]] -= c_tmp
    print(sumA)





Failing test case input:
4
0 2 4 6
3
0 1
3 4
0 4

Expected output:
13
13
13


Actual output:
13
13
17


Fixed submission (verdict: Accepted):
import collections

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

bc = [map(int, input().split()) for _ in range(Q)]
b, c= [list(i) for i in zip(*bc)]

count = collections.Counter(A)

sumA = sum(A)

for iter in range(Q):
    sumA += count[b[iter]]*(c[iter]- b[iter])
    count[c[iter]] += count[b[iter]] 
    count[b[iter]] = 0
    print(sumA)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
S = sum(A)

Q = int(input())
for _ in range(Q):
    x, y = map(int, input().split())
    S += (c[x]*(y-x))
    print(S)

Failing test case input:
4
2 1 1 1
3
1 2
2 1
3 5

Expected output:
8
4
4


Actual output:
8
7
7


Fixed submission (verdict: Accepted):
from collections import Counter

N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
S = sum(A)

Q = int(input())
for _ in range(Q):
    x, y = map(int, input().split())
    S += (c[x]*(y-x))
    print(S)
    c[y] += c[x]
    c[x] = 0

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import *
from operator import mul

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


A_dic = Counter(A)
A_sum = sum(A)

for _ in range(q):
    b, c = map(int, input().split())
    tmp = A_dic[b]
    A_dic[c] += tmp
    A_dic[b] = 0
    A_sum += c*A_dic[c] - b*tmp
    print(A_sum)

Failing test case input:
4
0 2 5 8
3
0 4
5 4
0 4

Expected output:
19
18
18


Actual output:
19
22
30


Fixed submission (verdict: Accepted):
from collections import *
from operator import mul

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


A_dic = Counter(A)
A_sum = sum(A)

for _ in range(q):
    b, c = map(int, input().split())
    tmp = A_dic[b]
    A_dic[c] += tmp
    A_dic[b] = 0
    A_sum += tmp*(c - b)
    print(A_sum)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections

N = int(input())
A = list(map(int,input().split()))
S = sum(A)
c = collections.Counter(A)

Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())
    ans = S - B * c[B] + C * c[B]
    print(ans)
    S = ans
    c[B] = 0
    c[C] += c[C]

Failing test case input:
4
0 2 5 8
3
0 4
5 0
0 4

Expected output:
19
14
18


Actual output:
19
14
14


Fixed submission (verdict: Accepted):
import collections

N = int(input())
A = list(map(int,input().split()))
S = sum(A)
c = collections.Counter(A)

Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())
    ans = S - B * c[B] + C * c[B]
    print(ans)
    S = ans
    c[C] += c[B]
    c[B] = 0
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

A.sort()
S = 0
d = {}
for i in A:
    S += i
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

Q = int(input())

for i in range(Q):
    B,C = map(int,input().split())
    if B in d:
        x = d[B]
        S -= B * x
        S += C * x
        if C in d:
            d[C] += x
        else:
            d[C] = x
    print(S)


Failing test case input:
4
0 2 4 6
3
0 1
3 4
0 4

Expected output:
13
13
13


Actual output:
13
13
17


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

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

A.sort()
S = 0
d = {}
for i in A:
    S += i
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

Q = int(input())

for i in range(Q):
    B,C = map(int,input().split())
    if B in d:
        x = d[B]
        S += (C-B) * x
        d[B] = 0
        if C in d:
            d[C] += x
        else:
            d[C] = x
    print(S)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
N = int(input())

A = list(map(int,input().split()))
Q = int(input())

counter = Counter(A)
sum_res = sum(A)

for _ in range(Q):
    bf,af = map(int,input().split())
    sum_res -= bf*counter[bf]
    sum_res += af*counter[af]
    
    counter[af] += counter[bf]
    counter[bf] = 0
    
    print(sum_res)

Failing test case input:
4
1 1 1 0
1
0 1
2 1
5 2

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
from collections import Counter
N = int(input())

A = list(map(int,input().split()))
Q = int(input())

counter = Counter(A)
sum_res = sum(A)

for _ in range(Q):
    bf,af = map(int,input().split())
    sum_res -= bf*counter[bf]
    sum_res += af*counter[bf]
    
    counter[af] += counter[bf]
    counter[bf] = 0
    
    print(sum_res)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0


Failing test case input:
4
1 1 1 1
3
1 2
2 1
3 5

Expected output:
8
4
4

Actual output:
8
4


Fixed submission (verdict: Accepted):
from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    else:
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
N = int(input())

Line = [int(s) for s in input().split()]
c = collections.Counter(Line)



Q = int(input())


for _ in range(Q):
    Line = [int(s) for s in input().split()]
    try:
        c[Line[1]] += c[Line[0]]
        c.pop(Line[0])
    except:
        print('Error')
    print(c)
    
    s=0
    for i in c:
        
        s += i * c[i]
    print(s)    

Failing test case input:
4
1 3 3 3
3
1 2
3 4
0 4

Expected output:
11
14
14


Actual output:
Counter({3: 3, 2: 1})
11
Counter({4: 3, 2: 1})
14
Error
Counter({4: 3, 2: 1})
14


Fixed submission (verdict: Accepted):
import collections
N = int(input())

Line = [int(s) for s in input().split()]
c = collections.Counter(Line)


v = 0

for i in c:
    
    v += i * c[i]


Q = int(input())


for _ in range(Q):
    Line = [int(s) for s in input().split()]
    try:
        c[Line[1]] += c[Line[0]]
        
        
        v += c[Line[0]] * (Line[1] - Line[0])
        c.pop(Line[0])
        
    except:
        pass
        
        
    

    
    
    
    
    print(v)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Q=int(input())





counterA = dict(Counter(A))
counterAkeys=set(counterA.keys())


sumA = sum(A)


for _ in range(Q):
  b,c=map(int,input().split())
  
  if b not in counterAkeys:
    print(sumA)
    continue
  b_cnt = counterA[b]
  if c in counterAkeys:
    counterA[c] += b_cnt
  else:
    counterA[c] = b_cnt
    counterAkeys.add(c)

  sumA+=(c-b)*b_cnt
  print(sumA)

Failing test case input:
4
0 2 5 6
3
0 1
5 4
0 4

Expected output:
14
13
13


Actual output:
14
13
17


Fixed submission (verdict: Accepted):
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Q=int(input())





counterA = dict(Counter(A))
counterAkeys=set(counterA.keys())


sumA = sum(A)


for _ in range(Q):
  b,c=map(int,input().split())
  
  if b not in counterAkeys:
    print(sumA)
    continue
  b_cnt = counterA[b]
  counterA[b]=0
  if c in counterAkeys:
    counterA[c] += b_cnt
  else:
    counterA[c] = b_cnt
    counterAkeys.add(c)

  sumA+=(c-b)*b_cnt
  print(sumA)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections as c

n = int(input())

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

q = int(input())

s = sum(a)

cnt = c.Counter(a)

for i in range(q):
    b,c = map(int,input().split())
    s += (c-b)*cnt[b-1]
    cnt[c-1] += cnt[b-1]
    cnt[b-1] = 0
    print(s)

Failing test case input:
4
0 2 5 6
3
0 2
5 4
0 4

Expected output:
15
14
14


Actual output:
13
13
13


Fixed submission (verdict: Accepted):
import collections as c

n = int(input())

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

q = int(input())

s = sum(a)

cnt = c.Counter(a)

for i in range(q):
    b,c = map(int,input().split())
    s += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(s)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    CA = Counter(A)
    sumA = 0
    for key, value in CA.items():
        sumA += key*value

    Q = int(input())
    for i in range(Q):
        b, c = map(int, input().split())
        sumA = (c-b)*CA[b]
        CA[c] += CA[b]
        CA[b] = 0
        print(sumA)

main()

Failing test case input:
4
4 0 3 2
3
0 2
1 1
4 5

Expected output:
11
11
12


Actual output:
2
0
1


Fixed submission (verdict: Accepted):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    CA = Counter(A)
    sumA = 0
    for key, value in CA.items():
        sumA += key*value

    Q = int(input())
    for i in range(Q):
        b, c = map(int, input().split())
        sumA += (c-b)*CA[b]
        CA[c] += CA[b]
        CA[b] = 0
        print(sumA)

main()

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())

d = Counter(A)
total = sum(A)

for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    if d[b]:
        total += (c - b) * d[b]
        d[c] = d[b]
        d[b] = 0
    print(total)



Failing test case input:
4
2 0 2 1
3
0 2
2 1
3 13

Expected output:
7
4
4


Actual output:
7
6
6


Fixed submission (verdict: Accepted):
from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())

d = Counter(A)
total = sum(A)

for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    if d[b]:
        total += (c - b) * d[b]
        d[c] = d[b] + (d[c] if d[c] else 0)
        d[b] = 0
    print(total)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

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

b = []
c = []
for i in range(q):
	B, C = map(int, input().split())
	b.append(B)
	c.append(C)

cnt = Counter(a)

s = sum(cnt)

for i in range(q):
	s -= b[i]*cnt[b[i]]
	s += c[i]*cnt[b[i]]
	cnt[c[i]] += cnt[b[i]]
	cnt[b[i]] = 0
	print(s)

Failing test case input:
4
1 1 1 0
2
0 2
1 1
5 4

Expected output:
5
5


Actual output:
3
3


Fixed submission (verdict: Accepted):
from collections import Counter

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

cnt = Counter(a)

s = sum(a)

for i in range(q):
	b, c = map(int, input().split())
	s = s - b*cnt[b]
	s = s + c*cnt[b]
	cnt[c] += cnt[b]
	cnt[b] = 0
	print(s)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  n = count[b]
  sum_ -= b*n
  count[c] += n
  sum_ += c*count[c]
  print(sum_)

Failing test case input:
4
0 1 1 1
3
1 4
2 1
0 8

Expected output:
12
12
20


Actual output:
12
15
23


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  count[c] += count[b]
  sum_ += (c-b)*count[b]
  count[b] = 0
  print(sum_)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin
input=stdin.readline
input()
a=list(map(int,input().split()))
ans=sum(a)
b=[0]*(max(a)+1)
y=max(a)+1
for i in a:
  b[i]+=1
c=int(input())
for i in range(c):
  n,m=map(int,input().split())
  if n<y and m<y:
    x=b[n]
    if x>0:
      b[m]+=x
      b[n]=0
      ans+=(m-n)*x
  print(ans)

Failing test case input:
2
1 4
3
1 100
2 001
110 1001

Expected output:
104
104
104


Actual output:
5
5
5


Fixed submission (verdict: Accepted):
from sys import stdin
input=stdin.readline
input()
a=list(map(int,input().split()))
ans=sum(a)
b=[0]*(10**5+1)
for i in a:
  b[i]+=1
c=int(input())
for i in range(c):
  n,m=map(int,input().split())
  if b[n]>0:
    x=b[n]
    if x>0:
      b[m]+=x
      b[n]=0
      ans+=(m-n)*x
  print(ans)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
sums = sum(a)
d = {}

for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1

for i in range(q):
    b,c = map(int, input().split())
    if b in d:
        sums += d[b]*(c-b)
        if c in d:
          d[c] += d[b]
        else:
          d[c] = d[b]
  
    print(sums)

Failing test case input:
4
0 2 5 8
3
0 4
5 4
0 4

Expected output:
19
18
18


Actual output:
19
18
22


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
sums = sum(a)
d = {}

for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1

for i in range(q):
    b,c = map(int, input().split())
    if b in d:
        sums += d[b]*(c-b)
        if c in d:
          d[c] += d[b]
        else:
          d[c] = d[b]
        d[b] = 0
    print(sums)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

for j in range(q):
 x,y=map(int,input().split())
 ans=-(x-y)*cnt[x]+sum
 print(ans)

Failing test case input:
4
1 3 3 3
3
1 2
3 4
0 4

Expected output:
11
14
14


Actual output:
11
13
10


Fixed submission (verdict: Accepted):
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
  
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(y-x)*cnt[x]
 cnt[y]+=cnt[x]
 cnt[x]=0
 print(sum)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

ans = sum(A)
cnt = collections.Counter(A)

dp = [0]*(10**5+1)

for i in cnt.items():
    dp[i[0]] = i[1]

for i in range(Q):
    ans += (BC[i][1] - BC[i][0]) * dp[BC[i][0]]
    dp[BC[i][1]] += dp[BC[i][0]]
    dp[BC[i][0]] == 0
    print(ans)


Failing test case input:
4
0 2 5 8
3
0 4
5 2
0 4

Expected output:
19
16
16


Actual output:
19
16
20


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

ans = sum(A)
dp = [0]*(10**5+1)
for i in A:
    dp[i] += 1

for i in BC:
    ans += (i[1] - i[0]) * dp[i[0]]
    dp[i[1]] += dp[i[0]]
    dp[i[0]] = 0
    print(ans)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())

al=list(map(int,input().split()))

q=int(input())
import collections
dic=collections.Counter(al)
total=sum(al)
for i in range(q):
    b,c=map(int,input().split())
    b_num=dic[b]
    total=total+b_num*(c-b)
    print(total)
    dic[c]=dic.get(c,0)+b_num



Failing test case input:
4
1 5 0 1
3
1 0
5 1
5 1

Expected output:
5
1
1


Actual output:
5
1
-3


Fixed submission (verdict: Accepted):
n=int(input())

al=list(map(int,input().split()))

q=int(input())
dic={}
for a in al:
    dic[a]=dic.get(a,0)+1

total=sum(al)
ansl=[]
for i in range(q):
    b,c=map(int,input().split())
    b_num=dic.get(b,0)
    total=total+b_num*(c-b)
    ansl.append(total)
    dic[b]=0
    dic[c]=dic.get(c,0)+b_num

for ans in ansl:
    print(ans)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
bc_list = []
for _ in range(q):
    bc_list.append(list(map(int, input().split())))

sum_num = sum(a_list)
counter = Counter(a_list)

for i, (b, c) in enumerate(bc_list):
    sum_num = sum_num + ((c - b) * counter[b])
    counter[c] = counter[c] + counter[b]
    print(sum_num)


Failing test case input:
4
0 2 4 3
3
0 1
3 4
0 4

Expected output:
10
11
11


Actual output:
10
11
15


Fixed submission (verdict: Accepted):
from collections import Counter

n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
bc_list = []
for _ in range(q):
    bc_list.append(list(map(int, input().split())))

sum_num = sum(a_list)
counter = Counter(a_list)

for i, (b, c) in enumerate(bc_list):
    sum_num = sum_num + ((c - b) * counter[b])
    counter[c] = counter[c] + counter[b]
    counter[b] = 0
    print(sum_num)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline

n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))

s = sum(a)
for b, c in L:
  print(a)
  if b in a:
    a[c] += a[b]
    del a[b]
  
    
print(a)


Failing test case input:
4
2 3 4 3
3
1 2
3 1
0 1

Expected output:
12
8
8


Actual output:
Counter({3: 2, 2: 1, 4: 1})
Counter({3: 2, 2: 1, 4: 1})
Counter({1: 2, 2: 1, 4: 1})
Counter({1: 2, 2: 1, 4: 1})


Fixed submission (verdict: Accepted):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

ans = sum(a)
a_c = Counter(a)

for i in range(q):
    b_num = a_c[b[i]]
    ans += (c[i] - b[i]) * b_num
    a_c[c[i]] += b_num
    print(ans)


Failing test case input:
4
0 2 4 3
3
0 4
3 4
0 4

Expected output:
13
14
14


Actual output:
13
14
18


Fixed submission (verdict: Accepted):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

ans = sum(a)
a_c = Counter(a)

for i in range(q):
    b_num = a_c[b[i]]
    ans += (c[i] - b[i]) * b_num
    a_c[c[i]] += b_num
    a_c[b[i]] = 0
    print(ans)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
l= list(map(int,input().split()))
c = [0] * (10 ** 5 + 1)
for i in l:
  c[i] += 1
n = int(input())
s = sum(c)
for i in range(n):
  be,af = map(int,input().split())
  s -= be * c[be]
  s += af * c[be]
  c[af] += c[be]
  c[be] = 0
  print(s)

Failing test case input:
2
1 2
3
1 100
2 001
110 1001

Expected output:
102
101
101


Actual output:
101
100
100


Fixed submission (verdict: Accepted):
N = int(input())
A= list(map(int,input().split()))
Q = int(input())
heavy = [0] * (10 ** 5 + 1)
for i in A:
  heavy[i] += 1
s = sum(A)
for i in range(Q):
  be,af = map(int,input().split())
  s -= be * heavy[be]
  s += af * heavy[be]
  heavy[af] += heavy[be]
  heavy[be] = 0
  print(s)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
l=[]
for _ in range(Q):
    l.append(list(map(int,input().split())))
c = collections.Counter(A)
sum=sum(A)
for i in range(Q):
    print(c)
    if c[l[i][0]] == 0:
        print(sum)
        continue
    else:
        sum+=c[l[i][0]]*(l[i][1]-l[i][0])
        c[l[i][1]]+=c[l[i][0]]
        del c[l[i][0]]
        print(sum)


Failing test case input:
4
0 2 4 4
3
1 4
3 4
0 2

Expected output:
10
10
12


Actual output:
Counter({4: 2, 0: 1, 2: 1})
10
Counter({4: 2, 0: 1, 2: 1})
10
Counter({4: 2, 0: 1, 2: 1})
12


Fixed submission (verdict: Accepted):
import collections
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
l=[]
for _ in range(Q):
    l.append(list(map(int,input().split())))
c = collections.Counter(A)
sum=sum(A)
for i in range(Q):
    if c[l[i][0]] == 0:
        print(sum)
        continue
    else:
        sum+=c[l[i][0]]*(l[i][1]-l[i][0])
        c[l[i][1]]+=c[l[i][0]]
        del c[l[i][0]]
        print(sum)

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
from collections import defaultdict
R = defaultdict(int)
for a in A:
    R[a] += 1
Q = int(input())
for i in range(Q):
    b,c = map(int,input().split())
    cnt = R[b]
    del R[b]
    R[c] += cnt
    if i == 0:
        ans = 0
        for key in R.keys():
            ans += (R[key]*key)
            print(ans)
    else:
        ans = ans - cnt*b + cnt*c
        print(ans)

Failing test case input:
4
2 3 4 3
3
1 2
3 1
0 1

Expected output:
12
8
8


Actual output:
2
8
12
8
8


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]
from collections import defaultdict
R = defaultdict(int)
for a in A:
    R[a] += 1
Q = int(input())
for i in range(Q):
    b,c = map(int,input().split())
    cnt = R[b]
    del R[b]
    R[c] += cnt
    if i == 0:
        ans = 0
        for key in R.keys():
            ans += (R[key]*key)
        print(ans)
    else:
        ans = ans - cnt*b + cnt*c
        print(ans)
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
numl = [0] * 100005
resl = []
suma = sum(a)
for i in range(n):
    numl[a[i]]+=1
for i in range(q):
    b, c = map(int, input().split())
    bn = numl[b]
    suma += (c - b)* bn
    resl.append(suma)
    numl[c] -= bn
    numl[c] += bn
for i in resl:
    print(i)

Failing test case input:
2
1 2
3
1 100
2 100
100 1000

Expected output:
102
200
2000

Actual output:
102
200
200


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
numl = [0] * 100005
resl = []
suma = sum(a)
for i in range(n):
    numl[a[i]]+=1
for i in range(q):
    b, c = map(int, input().split())
    bn = numl[b]
    suma += (c - b)* bn
    resl.append(suma)
    numl[b] -= bn
    numl[c] += bn
for i in resl:
    print(i)

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]

L=[0]*(10**5+1)
S=0
for i in range(N):
    L[A[i]]+=1
    S+=A[i]

for i in range(q):
    S+=L[Q[i][0]]*(Q[i][1]-Q[i][0])
    L[Q[i][0]]=0
    L[Q[i][1]]+=L[Q[i][0]]
    print(S)

Failing test case input:
2
1 2
3
1 100
2 100
100 1000

Expected output:
102
200
2000

Actual output:
102
200
200


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]

L=[0]*(10**5+1)
S=0
for i in range(N):
    L[A[i]]+=1
    S+=A[i]

for i in range(q):
    S+=L[Q[i][0]]*(Q[i][1]-Q[i][0])
    L[Q[i][1]]+=L[Q[i][0]]
    L[Q[i][0]]=0
    
    print(S)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())

counter = Counter(A)
sum_res = sum(A)

for _ in range(Q):
  B,C = map(int,input().split())
  sum_res = sum_res - B*counter[B] + C*counter[C]
  counter[C] += counter[B]
  counter[B] = 0
  
  print(sum_res)

Failing test case input:
4
-1 3 4 3
3
1 1
3 4
0 4

Expected output:
9
11
11


Actual output:
9
7
19


Fixed submission (verdict: Accepted):
from collections import Counter

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

counter = Counter(a)
sum_res = sum(a)  


for _ in range(q):
    before, after = map(int, input().split())

    
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
ans=sum(a)
L=[0]*(10**5+1)
for i in range(n):
    L[a[i]]+=1
for i in range(q):
    b,c=map(int,input().split())
    num=L[b]
    L[c]+=num
    ans-=num*b
    ans+=num*c
    print(ans)

Failing test case input:
4
0 2 4 6
3
0 1
3 4
0 4

Expected output:
13
13
13


Actual output:
13
13
17


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
ans=sum(a)
L=[0]*(10**5+1)
for i in range(n):
    L[a[i]]+=1
for i in range(q):
    b,c=map(int,input().split())
    num=L[b]
    L[b]=0
    L[c]+=num
    ans-=num*b
    ans+=num*c
    print(ans)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
elements= input().split()
q=int(input())
actions=[]
for i in range(q):
    actions.append(input().split())
 
dict={}
for e in elements:
    count=dict.get(e,0)
    count+=1
    dict[e]=count
 
sum=0
for key in dict.keys():
    sum+=int(key)* dict[key]

for act in actions:
    count=dict.get(act[0],0)
    sum+=(int(act[1])-int(act[0]))*count
    count+=dict.get(act[1],0)
    dict[act[1]]=count
 
    print(str(sum))

Failing test case input:
4
1 5 0 1
3
1 0
5 1
5 1

Expected output:
5
1
1


Actual output:
5
1
-3


Fixed submission (verdict: Accepted):
n=int(input())
elements= input().split()
q=int(input())
actions=[]
for i in range(q):
    actions.append(input().split())
 
dict={}
for e in elements:
    count=dict.get(e,0)
    count+=1
    dict[e]=count
 
sum=0
for key in dict.keys():
    sum+=int(key)* dict[key]

for act in actions:
    count=dict.get(act[0],0)
    sum+=(int(act[1])-int(act[0]))*count
    count+=dict.get(act[1],0)
    dict[act[1]]=count
    dict[act[0]]=0
 
    print(str(sum))

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
C = Counter(A)

for i in range(Q):
  b, c = map(int, input().split())
  if b in A:
    cnt = C[b]
    C[c] += cnt
    C[b] = 0
    ans += (c-b) * cnt
  print(ans)

Failing test case input:
4
1 1 1 0
2
0 2
2 1
5 2

Expected output:
5
4


Actual output:
5
5


Fixed submission (verdict: Accepted):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
C = Counter(A)

for i in range(Q):
  b, c = map(int, input().split())
  if C[b] != 0:
    cnt = C[b]
    C[c] += cnt
    C[b] = 0
    ans += (c-b) * cnt
  print(ans)
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
q=int(input())
dp=[0]*(10**5+1)
for i in range(1,10**5+1):
  dp[i]=a.count(i)

for j in range(min(q,20000)):
  b,c=map(int,input().split())
  ans+=(c-b)*dp[b]
  dp[c]+=dp[b]
  dp[b]=0
  print(ans)

Failing test case input:
4
0 2 4 6
3
0 1
3 4
0 4

Expected output:
13
13
13


Actual output:
12
12
12


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
q=int(input())
dp=[0]*(10**5+1)
for i in a:
  dp[i]+=1

for j in range(q):
  b,c=map(int,input().split())
  ans+=(c-b)*dp[b]
  dp[c]+=dp[b]
  dp[b]=0
  print(ans)
Problem: p03407
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C = map(int, input().split())
if 2*(A+B) < C:
    print('No')
else:
    print('Yes')

Failing test case input:
31 36 76

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
A, B, C = map(int, input().split())
if A+B < C:
    print('No')
else:
    print('Yes')

Problem: p03407
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c=map(int, input().split())
if a+b<=c:
  print("Yes")
else:
  print("No")

Failing test case input:
120 100 2

Expected output:
Yes


Actual output:
No


Fixed submission (verdict: Accepted):
a, b, c=map(int, input().split())
if a+b>=c:
  print("Yes")
else:
  print("No")

Problem: p03407
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C=map(int,input().split())
if A+B>=C:
  print('No')
elif A+B<C:
  print('Yes')


Failing test case input:
1677 011 0110

Expected output:
Yes


Actual output:
No


Fixed submission (verdict: Accepted):
A,B,C=map(int,input().split())
if A+B>=C:
  print('Yes')
elif A+B<=C:
  print('No')

Problem: p03407
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c = map(int, input().split())
if a + b > c:
  print("No")
else:
  print("Yes")

Failing test case input:
500 101 1000

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
a, b, c = map(int, input().split())
if a + b < c:
  print("No")
else:
  print("Yes")

Problem: p03407
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
A,B,C=map(int,input().split())
if A+B*2>=C:
    print("Yes")
else:
    print("No")

Failing test case input:
0 730 1200

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):


A,B,C=map(int,input().split())
if A+B>=C:
    print("Yes")
else:
    print("No")

Problem: p03407
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c=list(map(int,input().split()))
if a+b*2>=c:
    print('Yes')
else:
    print('No')

Failing test case input:
31 36 76

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
a,b,c=list(map(int,input().split()))
if a+b>=c:
    print('Yes')
else:
    print('No')

Problem: p03407
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c = map(int, input().split())
print("yes" if a+b >= c else "No")

Failing test case input:
1977 011 1111

Expected output:
Yes


Actual output:
yes


Fixed submission (verdict: Accepted):
a,b,c = map(int, input().split())
print("Yes" if a+b >= c else "No")

Problem: p03407
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c=map(int,input().split())
if (a+2*b)>=c:
    print("Yes")
else:
    print("No")

Failing test case input:
0 730 1200

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
a,b,c=map(int,input().split())
if (a+b)>=c:
    print("Yes")
else:
    print("No")