ZhenlongDai/ACPR huggingface dataset:
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())
 sum+=(x-y)*cnt[x]
 print(sum)
 cnt[x]+=cnt[y]
 cnt[y]=0

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

Expected output:
4


Actual output:
2


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):
from collections import Counter
n = int(input())
ar = list(map(int, input().split()))
 
t = int(input())
c = Counter(ar)
s = sum(ar)
for i in range(t):
    a, b = list(map(int, input().split()))
    if b in c:
        c[b] += c[a]
    else:
        c[b] = c[a]
    s += ((b-a)*c[a])
    print(s)

  
  

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):
import collections
N = int(input())
A = list(map(int,input().split()))
D = collections.Counter(A)
Q = int(input())

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

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
a=[0]*(10**5+1)
num=0
for i in range(N):
    s=A[i]
    a[s]+=1
    num+=s
Q=int(input())
ans=[]
print(num)
for i in range(Q):
    B,C=map(int,input().split())
    a[C]+=a[B]
    num+=(C-B)*a[B]
    a[B]=0
    ans.append(num)
for i in ans:
    print(i)

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

Expected output:
102
100
1000


Actual output:
3
102
100
1000


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
a=[0]*(10**5+1)
num=0
for i in range(N):
    s=A[i]
    a[s]+=1
    num+=s
Q=int(input())
ans=[]
for i in range(Q):
    B,C=map(int,input().split())
    a[C]+=a[B]
    num+=(C-B)*a[B]
    a[B]=0
    ans.append(num)
for i in ans:
    print(i)

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())

total = sum(a)
a = collections.Counter(a)

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

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):
import collections

N = int(input())
a = list(map(int,input().split()))
Q = int(input())
ans = sum(a)
a = collections.Counter(a)

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

S = sum(List)

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

for i in range(N):
  a = List[i]
  arr[a] += 1
  
for i in range(Q):
  a,b = map(int,input().split())
  aa = arr[a]
  arr[b] += aa
  S += int ( (b-a) * aa )
  print(int(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):
N = int(input())
List = list(map(int,input().split()))
Q = int(input())

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

for i in range(N):
  a = List[i]
  arr[a] += 1
  S += int(a)
  
for i in range(Q):
  a,b = map(int,input().split())
  aa = arr[a]
  arr[b] += aa
  arr[a] = 0
  S += int ( (b-a) * aa )
  print(int(S))

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

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

q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1

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



for i in range(q):
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    
    s = 0
    for j in range(n+1):
        s += j * z[j]
    print(s)

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

Expected output:
6
3
11


Actual output:
6
3
3


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

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

q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1
x = sum(a)
b = []
for _ in range(q):
    b.append(list(map(int,input().split())))



for i in range(q):
    x += (b[i][1] - b[i][0]) * z[b[i][0]]
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    print(x)

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s=set()
l = [0] * ( 10 ** 5 + 1 )
N = int(input())
A = list(map(int, input().split()))
for i in range(len(A)):
  l[A[i]] += 1
Q = int(input())
for i in range(Q):
  B, C = map(int, input().split())
  l[C] += l[B]
  if l[C] > 0:
    s.add(C)
  l[B] = 0
  s.discard(B)
  sum=0
  for i in s:
    sum += i * l[i]
  print(sum)

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

Expected output:
5
5
5


Actual output:
0
0
0


Fixed submission (verdict: Accepted):
s=set()
l = [0] * ( 10 ** 5 + 1 )
sum=0
N = int(input())
A = list(map(int, input().split()))
for i in range(len(A)):
    l[A[i]] += 1
    s.add(A[i])
    sum += A[i]
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    if l[B] > 0:
        s.add(C)
        sum = sum + l[B] * ( C - B )
        l[C] += l[B]
        l[B] = 0
        s.discard(B)
    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())
num_list = [0 for i in range(100001)]
for i in a:
    num_list[i] += 1
ans = 0
for i in range(100001):
    ans += i * num_list[i]

for _ in range(q):
    b, c = map(int, input().split())
    num_list[c] += num_list[b]
    ans += num_list[b] * (c - b)
    print(ans)

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

Expected output:
17
16
16


Actual output:
17
16
20


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

for _ in range(q):
    b, c = map(int, input().split())
    num_b = num_list[b]
    num_list[c] += num_b
    ans += num_b * (c - b)
    num_list[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())
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])
    print(tot)


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())
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 (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[bi]
            ca[ci]=ca[bi]
            del ca[bi]
    print(sm)
        
        

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

Expected output:
9
10
14


Actual output:
9
10
18


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 (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
*a, = map(int,input().split())
g = [0] * (10**5 + 1)
s = 0
for A in a:
    g[A] += 1
    s += A
q = int(input())
for loop in range(q):
    b,c = map(int,input().split())
    s += g[b] * c
    g[c] += g[b]
    g[b] == 0
    print(s)


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

Expected output:
4
3
3


Actual output:
4
5
5


Fixed submission (verdict: Accepted):
n = int(input())
*a, = map(int,input().split())
M = 10**5+1
g = [0] * M
s = 0
for A in a:
    g[A] += 1
    s += A

q = int(input())
for loop in range(q):
    b,c = map(int,input().split())
    if g[b] == 0:
        print(s)
        continue
    s += g[b] * (c - b)
    g[c] += g[b]
    g[b] = 0
    print(s)

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,n+1):
  dp[i]=a.count(i)

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)

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

Expected output:
6
6
11


Actual output:
6
6
6


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: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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())
for i in range(Q):
    if B[i] not in A:
        continue
    for j in range(N):
        if A[j] == B[i]:
            A[j] = C[i]
    print(sum(A))

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

Expected output:
4
4
12


Actual output:
4
12


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
cnt = [0]*100005
s = sum(A)
for i in A:
    cnt[i] += 1
for i in range(Q):
    B, C = map(int,input().split())
    s += (C-B)*cnt[B]
    print(s)
    cnt[C] += cnt[B]
    cnt[B] = 0
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
readline = sys.stdin.readline

def solve():
    N = int(readline())
    A = list(map(int, readline().split()))
    Q = int(readline())
    BC = [list(map(int, readline().split())) for i in range(Q)]

    count = {}
    for a in A:
        count[a] = count.get(a, 0) + 1
    
    s = sum(A)

    for b, c in BC:
        if b in count:
            nb = count[b]
            diff = (c - b) * nb
            s += diff
            print(s)

            del count[b]
            count[c] = count.get(c, 0) + nb


solve()

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

Expected output:
6
6
6


Actual output:
6
6


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

def solve():
    N = int(readline())
    A = list(map(int, readline().split()))
    Q = int(readline())
    BC = [list(map(int, readline().split())) for i in range(Q)]

    count = {}
    for a in A:
        count[a] = count.get(a, 0) + 1
    
    s = sum(A)

    for b, c in BC:
        if b in count:
            nb = count[b]
            diff = (c - b) * nb
            s += diff
            print(s)

            del count[b]
            count[c] = count.get(c, 0) + nb
        else:
            print(s)


solve()

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

n = int(input())
al = list(map(int, input().split()))
al_sum = sum(al)
al_c = Counter(al)


q = int(input())
for _ in range(q):
    bi, ci = map(int, input().split())
    al_sum += al_c[bi]*(ci - bi)

    al_c.update({ci:al_c[bi]})
    del al_c[al_c[bi]]

    print(al_sum)






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

Expected output:
9
10
14


Actual output:
9
10
10


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

num = [0]*100001
for a in al:
    num[a] += 1


for _ in range(q):
    bi, ci = map(int, input().split())

    al_sum += num[bi]*(ci - bi)
    num[ci] += num[bi]
    num[bi] = 0

    print(al_sum)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
cnt = [0]*(10**5)
for i in range(0,10*5):
    cnt[i] = a.count(i+1)
s = sum(a)
q = int(input())
for _ 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 2 4
3
1 4
3 4
0 2

Expected output:
8
8
10


Actual output:
8
8
8


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)

cnt = [0]*(10**5)
for i in a:
    cnt[i-1] += 1

q = int(input())
for _ 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)
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

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:
        S -= B * d[B]
        S += C * d[B]
        if C in d:
            d[C] += d[B]
        else:
            d[C] = d[B]
    print(S)


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):
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):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
L = [list(map(int, input().split())) for i in range(Q)]

a = [0] * (10 ** 5 + 1)
ans = 0

for i in range(N):
    a[A[i]] += 1
    ans += A[i]

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


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())

a = [0] * (10 ** 5 + 1)
ans = sum(A)

for i in range(N):
    a[A[i]] += 1

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

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math as mt
import collections as cc
I=lambda:list(map(int,input().split()))
n,=I()
l=I()
f=cc.Counter(l)
s=sum(l)
for i in range(int(input())):
    x,y=I()
    s-=x*(f[x])
    s+=f[x]*y
    f[y]=f[x]
    f[x]=0
    print(s)
    
    
    

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

Expected output:
10
12
16


Actual output:
10
12
14


Fixed submission (verdict: Accepted):
import math as mt
import collections as cc
I=lambda:list(map(int,input().split()))
n,=I()
l=I()
f=cc.defaultdict(int)
for i in l:
    f[i]+=1
s=sum(l)
for i in range(int(input())):
    x,y=I()
    if f[x]==0:
        print(s)
    else:
        s-=f[x]*x
        s+=f[x]*y
        f[y]+=f[x]
        f[x]=0
        print(s)
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 l in range(q)]
cnt=[0]*100001
Sum=0
for i in range(n):
  cnt[a[i]]+=1
  Sum+=a[i]
for i in range(q):
  Sum+=(bc[i][1]-bc[i][0])*cnt[bc[i][1]]                           
  cnt[bc[i][1]]+=cnt[bc[i][0]]
  cnt[bc[i][0]]=0
  print(Sum)

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

Expected output:
10
12
16


Actual output:
10
10
14


Fixed submission (verdict: Accepted):
n=int(input())
a = list(map(int,input().split()))
q=int(input())
bc = [list(map(int, input().split())) for l in range(q)]
cnt=[0]*100001
Sum=0
for i in range(n):
  cnt[a[i]]+=1
  Sum+=a[i]
for i in range(q):
  Sum+=(bc[i][1]-bc[i][0])*cnt[bc[i][0]]                           
  cnt[bc[i][1]]+=cnt[bc[i][0]]
  cnt[bc[i][0]]=0
  print(Sum)

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

CNT = {}
S = 0

for a in map(int, input().split()):
    if not(a in CNT):
        CNT[a] = 0

    CNT[a] += 1
    S += a

Q = int(input())
for _ in range(Q):
    B,C = map(int, input().split())

    if B in CNT:
        cnt = CNT[B]
        S -= B*cnt
        S += C*cnt
        
        if not(C in CNT):
            CNT[C] = 0

        CNT[C] += cnt
        
    print(S)



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
22


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

CNT = {}
S = 0

for a in map(int, input().split()):
    if not(a in CNT):
        CNT[a] = 0

    CNT[a] += 1
    S += a

Q = int(input())
for _ in range(Q):
    B,C = map(int, input().split())

    if B in CNT:
        cnt = CNT[B]
        del CNT[B]

        S -= B*cnt
        S += C*cnt
        
        if not(C in CNT):
            CNT[C] = 0

        CNT[C] += cnt
        
    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()))
suma=sum(a)
dica=Counter(a)
q=int(input())
b=[]
c=[]
for i in range(q):
  b_,c_=map(int,input().split())
  b.append(b_)
  c.append(c_)

i=0
j=0

while i<=(q-1):
  num=dica[b[i]]
  new_sum=suma-b[i]*num+c[i]*num
  print(new_sum)
  
  suma=new_sum
  try:
    dica[c[i]]+=num
  except:
    dica.setdefault(c[i],num)
  i+=1

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):
n=int(input())
a=list(map(int,input().split()))
suma=sum(a)
q=int(input())
b=[]
c=[]
for i in range(q):
  b_,c_=map(int,input().split())
  b.append(b_)
  c.append(c_)

counter=[0]*(10**5+1)
for i in a:
  counter[i]+=1
new_sum=suma
for i in range(q):
  new_sum=new_sum-b[i]*counter[b[i]]+c[i]*counter[b[i]]
  
  counter[c[i]]+=counter[b[i]]
  counter[b[i]]=0
  print(new_sum)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
sum1=sum(a)
d={}
for x in range(n):
  s=a[x]
  if s not in d:
    d[s]=0
  d[s]+=1

for y in range(q):
  h,g=map(int,input().split())
  if h in d:
    r=d[h]
    sum1=sum1-r*h
    
    if g not in d:
      d[g]=0
    d[g]+=r
    sum1+=r*g
    d[h]=0
    print(sum1)

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

Expected output:
6
5
5


Actual output:
5


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
sum1=sum(a)
d={}
for x in range(n):
  s=a[x]
  if s not in d:
    d[s]=0
  d[s]+=1

for y in range(q):
  h,g=map(int,input().split())
  if h in d:
    r=d[h]
    sum1=sum1-r*h
    
    if g not in d:
      d[g]=0
    d[g]+=r
    sum1+=r*g
    d[h]=0
    
  print(sum1)

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
Dict = {}
for i in A:
    if i not in Dict:
        Dict[i] = 1
    else:
        Dict[i]+=1
ans = sum(A)
for i in range(Q):
    B, C = map(int,input().split())
    if B in Dict and Dict[B]!=0:
        b = Dict[B]
        Dict[B]=0
        if C not in Dict:
            Dict[C]=0
        Dict[C]+=b
        
        ans+=(C-B)*b
        print(ans)

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

Expected output:
1
-1
-1


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
Dict = {}
for i in A:
    if i not in Dict:
        Dict[i] = 1
    else:
        Dict[i]+=1
ans = sum(A)
for i in range(Q):
    B, C = map(int,input().split())
    if B in Dict and Dict[B]!=0:
        b = Dict[B]
        Dict[B]=0
        if C not in Dict:
            Dict[C]=0
        Dict[C]+=b
        
        ans+=(C-B)*b
    print(ans)

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
A = {}
for i in a:
    if not i in A:
        A[i] = 1
    else:
        A[i] += 1

s = 0
for k,v in A.items():
    s += k*v

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

    print (s)


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
22


Fixed submission (verdict: Accepted):
n = int(input())
A = {}
a = list(map(int,input().split()))
for i in a:
    if not i in A:
        A[i] = 1
    else:
        A[i] += 1

s = 0
for k,v in A.items():
    s += k*v

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

    print (s)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())

ans = sum(a)
numbers = [0]*(10**5+1)
for _ in range(q):
    b,c = [int(i) for i in input().split()]
    nb = numbers[b]
    ans += (c-b)*nb
    print(ans)
    numbers[b] = 0
    numbers[c] += nb    

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

Expected output:
11
10
10


Actual output:
3
3
3


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())

ans = sum(a)
numbers = [0]*(10**5+1)
for v in a:
    numbers[v] += 1

for _ in range(q):
    b,c = [int(i) for i in input().split()]
    nb = numbers[b]
    ans += (c-b)*nb
    print(ans)
    numbers[b] = 0
    numbers[c] += nb

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
from collections import deque
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = list(IL())
    q = I()
    s = deque()
    for rep in range(q):
        b,c = IL()
        tmp = 0
        for item in a:
          if item==b:
            tmp += c
          else:
            tmp += item
        s.append(tmp)
    for _ in range(q):
        print(s.popleft())
    return

if __name__=='__main__':
    Main()

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

Expected output:
2
1
1


Actual output:
2
3
4


Fixed submission (verdict: Accepted):
import sys
from collections import deque, Counter
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = list(IL())
    C = Counter(a)
    m = sum(a)
    q = I()
    s = []
    for rep in range(q):
        b,c = IL()
        if b in C:
            m += (c-b)*C[b]
            C[c] += C[b]
            C[b] = 0
        s.append(m)
    for rep in s:
        print(rep)
    return

if __name__=='__main__':
    Main()

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
x=[0]*10**6
sum_a=sum(a)
for _ in range(q):
  b,c=list(map(int,input().split()))
  tmp=x[c]
  x[c]=a.count(b)
  sum_a+=(c-b)*(x[c]+x[b])
  x[c]+=tmp

  print(sum_a)

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 defaultdict
 
N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)
for a in A:
  d[a]+=1

q = int(input())
sum_a=sum(A)
for _ in range(q):
  b,c=list(map(int,input().split()))
  sum_a+=(c-b)*d[b]
  d[c]+=d[b]
  d[b]=0

  print(sum_a)
Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
*a, = map(int,input().split())
g = [0] * (10**5 + 1)
s = 0
for A in a:
    g[A] += 1
    s += A
q = int(input())
for loop in range(q):
    b,c = map(int,input().split())
    s += g[b] * (c - b)
    g[c] += g[b]
    g[b] == 0
    print(s)


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):
n = int(input())
*a, = map(int,input().split())
M = 10**5+1
g = [0] * M
s = 0
for A in a:
    g[A] += 1
    s += A

q = int(input())
for loop in range(q):
    b,c = map(int,input().split())
    if g[b] == 0:
        print(s)
        continue
    s += g[b] * (c - b)
    g[c] += g[b]
    g[b] = 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):
    if c[l[i][0]] == 0:
        print(sum)
        break
    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
4 -1 3 2
3
0 2
1 1
4 5

Expected output:
8
8
9


Actual output:
8


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=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(1):
  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
1 5 0 1
2
1 0
5 1
5 1

Expected output:
5
1


Actual output:
5


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: 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 = [list(map(int, input().split())) for _ in range(q)]

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

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

Expected output:
15
14
14


Actual output:
15
14
18


Fixed submission (verdict: Accepted):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int, input().split())) for _ in range(q)]

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

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
al = list(map(int,input().split()))
q = int(input())

from collections import defaultdict
dic = defaultdict(int)

ans = 0
for a in al:
    dic[a] += 1
    ans += a

print(dic)
for _ in range(q):
    b,c = map(int,input().split())
    ans += dic[b] * (c - b)
    dic[c] += dic[b]
    dic[b] = 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:
defaultdict(<class 'int'>, {0: 1, 2: 1, 5: 1, 8: 1})
19
16
16


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

from collections import defaultdict
dic = defaultdict(int)

ans = 0
for a in al:
    dic[a] += 1
    ans += a


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

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
n = int(input())
l = list(map(int, input().split()))
a = int(input())
c = collections.Counter(l)
answer = sum(l)
for i in range(a):
    j,k =  map(int, input().split())
    save = c[j]
    del c[j]
    c[k] += save
    answer = answer + c[k] -save
    print(answer)


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

Expected output:
17
16
16


Actual output:
13
14
16


Fixed submission (verdict: Accepted):
import collections
n = int(input())
l = list(map(int, input().split()))
a = int(input())
c = collections.Counter(l)
answer = sum(l)
for i in range(a):
    j,k =  map(int, input().split())
    save = c[j]
    del c[j]
    c[k] += save
    answer = answer + k*save - j*save
    print(answer)
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())
 sum+=(y-x)*cnt[x]
 cnt[y]+=cnt[x]
 cnt[y]=0
 print(sum)

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

Expected output:
11
12
16

Actual output:
11
12
12


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 (PyPy3 (7.3.0), verdict: Wrong Answer):
import collections

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

s = sum(A)
c = collections.Counter(A)

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

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
19


Fixed submission (verdict: Accepted):
import collections

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

s = sum(A)
c = collections.Counter(A)

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

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

n = int(input())
aa = tuple(map(int, input().split()))
actr = Counter(aa)
q = int(input())

tb = {}
for i in range(q):
    b, c = map(int, input().split())
    tb[b] = c
    for k, v in tb.items():
        if v == b:
            tb[k] = c

    ans = 0
    for a, n in actr.items():
        ans += tb.get(a, a) * n
    print(ans)



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

Expected output:
4
4


Actual output:
4
2


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

n = int(input())
aa = tuple(map(int, input().split()))
actr = Counter(aa)
q = int(input())

ans = sum([a * n for a, n in actr.items()])
for i in range(q):
    b, c = map(int, input().split())
    n = actr[b]
    ans = ans - b * n + c * n
    actr[c] += n
    del actr[b]
    print(ans)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = map(int, input().split())
Q = int(input())

from collections import defaultdict
count = defaultdict(int)

for a in A:
  count[a] += 1

for _ in range(Q):
  B, C = map(int, input().split())
  if count[B] > 0:
    count[C] += count[B]
    count[B] = 0


ans = 0
for k, v in count.items():
  ans += k * v

print(ans)

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

Expected output:
8
0
0


Actual output:
0


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

from collections import defaultdict
count = defaultdict(int)

for a in A:
  count[a] += 1

ans = sum(A)

for _ in range(Q):
  B, C = map(int, input().split())
  if count[B] > 0:
    ans += C * count[B]
    ans -= B * count[B]
    count[C] += count[B]
    count[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())
sum_res = sum(A)
counter = [0 for _ in range(10 ** 5 + 1)]

for a in A:
    counter[a] += 1

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


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

Expected output:
102
200
2000

Actual output:
102
200
1100


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
sum_res = sum(A)
counter = [0 for _ in range(10 ** 5 + 1)]

for a in A:
    counter[a] += 1

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

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
a = na()
q = ni()
l = [na() for _ in range(q)]

import collections

c = collections.Counter(a)
ans = sum(a)
for i in l:
  if c[i[0]] >0:
    ans = ans - c[i[0]]*i[0] + i[1]*(c[i[0]])
    c[i[1]] = c[i[1]] + c[i[0]]
    c[i[0]] = 0
    print(ans)
    

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

Expected output:
4
3
3


Actual output:
4
3


Fixed submission (verdict: Accepted):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
a = na()
q = ni()
l = [na() for _ in range(q)]

import collections

c = collections.Counter(a)
ans = sum(a)
for i in l:
  if c[i[0]] >0:
    ans = ans - c[i[0]]*i[0] + i[1]*(c[i[0]])
    c[i[1]] = c[i[1]] + c[i[0]]
    c[i[0]] = 0
    print(ans)
  else:
    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())
d=dict()
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
ans=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    if b not in d:
        continue
    if c not in d:
        d[c]=0
    d[c]+=d[b]
    ans+=(c-b)*d[b]
    print(ans)
    d[b]=0


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

Expected output:
12
12
12


Actual output:
12


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=dict()
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
ans=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    if b not in d:
        d[b]=0
    if c not in d:
        d[c]=0
    d[c]+=d[b]
    ans+=(c-b)*d[b]
    print(ans)
    d[b]=0

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

N = int(input())
A = list(map(int, input().split()))
s = sum(A)
d = defaultdict(int)
for key in A:
    d[key] += 1
d[s] = s

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

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

Expected output:
0
-2
-2


Actual output:
0
-1
-1


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

N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
for key in A:
    d[key] += 1
d[sum] = sum(A)

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

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = []
c = 0
s = sum(A)
table = [0] * 100010




for i in A:
    table[i] += 1
for i in range(Q):
    B, C = map(int,input().split())
    
    
    c = table[B]
    s += (C - B) * c
    table[C] = table[B]
    table[B] = 0
    
        
        
        
        
        
    S.append(s)

        
        
        
    
    
    
        



for s in S:
    print(s)


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):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = []
c = 0
s = sum(A)
table = [0] * 100010




for i in A:
    table[i] += 1

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

        
        
        
    
    
    
        



for s in S:
    print(s)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

from  collections import Counter

dict_a = Counter(a)
s = sum(a)

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


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):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

from  collections import Counter

dict_a = Counter(a)
s = sum(a)

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

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
for i in resl:
    print(i)

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):
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 (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter


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

coun = Counter(A)


for i in range(Q):
  E= list(map(int, input().split( )))
  b, c = E[0], E[1]
  dis = c - b 
  Sum = Sum + dis*coun[b]
  print(Sum)
  coun[c] += coun[b]
  coun[b] == 0
  
  

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):
from collections import Counter


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

coun = Counter(A)


for _ in range(Q):
  b, c = map(int, input().split( ))
  Sum += (c-b)*coun[b]
  coun[c] += coun[b]
  coun[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()))
sumA = sum(A)

dic = Counter(A)

Q = int(input())

for _ in range(Q):
    b, c = map(int, input().split())
    if b in dic.keys():
        

        B = dic[b]
        
        if c in dic.keys():
            C = dic[c]
            dic[c] += dic[b]
            del dic[b]
        else:
            C = B
            dic[c] = dic[b]
            del dic[b]
        
        
        sumA += (C*c-B*b)
        
        
    
    
    print(sumA)

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

Expected output:
7
4
4


Actual output:
9
4
4


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

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

dic = Counter(A)

Q = int(input())

for _ in range(Q):
    b, c = map(int, input().split())
    if b in dic.keys():
        sumA += ((c-b)*dic[b])

        
        if c in dic.keys():
            
            
            dic[c] += dic[b]
            del dic[b]
        else:
            dic[c] = dic[b]
            del dic[b]
        
        
        
        
        
    
    
    print(sumA)

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
num = [0]*(10**5+1)
for i in a:
  num[i] += 1
sm = sum(a)
q = int(input())
for _ in range(q):
  x,y = map(int,input().split())
  nx = num[x]
  ny = num[y]
  sm = sm+x*ny+y*nx-x*nx-y*ny
  print(sm)
  num[x] = ny
  num[y] = nx

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

Expected output:
5
4


Actual output:
5
7


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
num = [0]*(10**5+1)
for i in a:
  num[i] += 1
sm = sum(a)
q = int(input())
for _ in range(q):
  x,y = map(int,input().split())
  nx = num[x]
  sm = sm+y*nx-x*nx
  print(sm)
  num[x] = 0
  num[y] += nx

Problem: p02630
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
dic = {}
ans = 0
for  x in a:
    if  x not in dic:
        dic[x] = 1
    else:
        dic[x]+=1
    ans += x

for _ in range(q):
    b,c=map(int,input().split())
    if b not in dic:continue
    ans += (c-b)*dic[b]
    if c not in dic:
        dic[c] = dic[b]
    else:
        dic[c]+=dic[b]
    dic[b]=0
    print(ans)

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

Expected output:
10


Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
dic = {}
ans = 0
for  x in a:
    if  x not in dic:
        dic[x] = 1
    else:
        dic[x]+=1
    ans += x

for _ in range(q):
    b,c=map(int,input().split())
    if b not in dic:
        print(ans)
        continue
    ans += (c-b)*dic[b]
    if c not in dic:
        dic[c] = dic[b]
    else:
        dic[c]+=dic[b]
    dic[b]=0
    print(ans)
Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    Q = int(input())
    BC = [list(map(int, input().split())) for i in range(Q)]

    for i in range(Q):
        B, C = tuple(BC[i])
        for j in range(N):
            if A[j] == B:
                A[j] = C
            if A[j] > B:
                break
        A = sorted(A)
        print(sum(A))


if __name__ == "__main__":
    main()


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

Expected output:
6
6
11


Actual output:
4
4
9


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 i in range(Q)]

    g = {}
    ans = 0
    for a in A:
        ans += a
        if a not in g:
            g[a] = 1
        else:
            g[a] += 1

    for i in range(Q):
        B, C = tuple(BC[i])
        if B in g:
            t = g.pop(B)
            ans += t * (C - B)
            if C in g:
                g[C] += t
            else:
                g[C] = t
        print(ans)


if __name__ == "__main__":
    main()

Problem: p02630
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
p = [list(map(int, input().split())) for _ in range(q)]
from collections import Counter
c = Counter(a)
for i in range(q):
    if p[i][0] in c:
        c[p[i][1]] += c[p[i][0]]
        c[p[i][0]] = 0
        print(c)
    ans = 0
    for i in c:
        ans += c[i] * i
    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:
Counter({4: 2, 2: 1, 3: 1, 0: 0})
13
Counter({4: 3, 2: 1, 0: 0, 3: 0})
14
Counter({4: 3, 2: 1, 0: 0, 3: 0})
14


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
p = [list(map(int, input().split())) for _ in range(q)]


counter = [0] * 1000000
for i in a:
    counter[i] += 1
 
ans = sum(a)
 
for _ in p:
    ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]
    counter[_[1]] += counter[_[0]]
    counter[_[0]] = 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())
S = []
c = 0
s = sum(A)
table = [0] * 100010




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

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):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = []
c = 0
s = sum(A)
table = [0] * 100010




for i in A:
    table[i] += 1

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

        
        
        
    
    
    
        



for s in S:
    print(s)