Problem p02630 (python)

Fixed submission:
import collections

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

CNT = collections.Counter(A)
ANS = []
ans = sum(A)

for i in range(q):
    b, c = map(int, input().split())
    t = CNT[b]
    ans +=(c - b) * t
    ANS.append(ans)
    CNT[c] += t
    CNT[b] = 0

for i in ANS:
    print(i)

Buggy submission (verdict: Runtime Error):
import collections

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

CNT = collections.Counter(A)
ANS = []
ans = sum(A)

for i in range(q):
    b, c = map(int, input().split())
    t = CNT[b]
    ans +=(c - b) * t
    ANS.append(ans)
    CNT[c] += t
    CNT[b] = 0

for i in ANS:
    print(i)

Buggy submission (verdict: Runtime Error):
import collections

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

cnt = collections.Counter(A)
ANS = []
base = sum(A)

for i in range(q):
    b, c = map(int, input().split())
    t = CNT[b]
    ans = base + (c - b) * t
    ANS.append(ans)
    CNT[c] += t
    CNT[b] = 0
    base = ans

for i in ANS:
    print(i)

Buggy submission (verdict: Runtime Error):
import collections
n = map(int, input().split())
A = list(map(int, input().split()))
q = map(int, input().split())
 
cnt = collections.Counter(A)
ANS = []
base = sum(A)

for i in range(q):
  b,c = map(int, input().split())
  ans = base + (c-b) * cnt[b]
  ANS.append(ans)
  cnt[c] += cnt[b]
  cnt[b] = 0
  base = ans

for i in ANS:
  print(i)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)    
ANS = []
 
for i in range(N):
    base += A[i]

for i in range(Q):
  b,c = map(int, input().split())
  ans = base + (c-b) * cnt[b]
  ANS.append(ans)
  cnt[c] += cnt[b]
  cnt[b] = 0
  base = ans

for i in ANS:
  print(i)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)    
ANS = []
 
for i in range(N):
    base += A[i]

for i in range(Q):
  b,c = map(int, input().split())
  ans = base + (c-b) * cnt[b]
  ANS.append(ans)
  cnt[c] += cnt[b]
  cnt[b] = 0
  base = ans

print(ANS)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)    
Ans = []
 
for i in range(N):
    base += A[i]

for i in range(Q):
  b,c = map(int, input().split())
  ans = base + (c-b) * cnt[b]
  Ans.append(ans)
  cnt[c] += cnt[b]
  cnt[b] = 0
  base = ans

print(Ans)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)    
Ans = []
 
for i in range(N):
    base += A[i]

for i in range(Q):
  b ,c = map(int, input().split())
  Ans.append(base + (c-b) * cnt[b])
  cnt[c] += cnt[b]
  cnt[b] = 0
  base = Ans[i]

print(Ans)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)    
Ans = []
 
for i in range(N):
    base += A[i]

for i in range(Q):
  b ,c = map(int, input().split())
  Ans.append(Ans[i] + (c-b) * cnt[b])
  cnt[c] += cnt[b]
  cnt[b] = 0

print(Ans)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)
 
for i in range(N):
    base += A[i]
    
Ans = []
Ans.append(base + (C[0]-B[0]) * cnt[B[0]])
 
for i in range(Q-1):
  b ,c = map(int, input().split())
  Ans.append(Ans[i] + (c-b) * cnt[b])
  cnt[c] += cnt[b]
  cnt[b] = 0

print(Ans)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
base = 0
cnt = collections.Counter(A)
 
for i in range(N):
    base += A[i]

Ans = []
Ans.append(base + (C[0]-B[0]) * cnt[B[0]])
 
for i in range(Q-1):
    if cnt[B[i+1]] != 0:
        Ans.append(Ans[i] + (C[i+1]-B[i+1]) * cnt[B[i+1]])
        for j in range(i+1):
            Ans[i+1] += B.count(C[j]) * (C[i+1] - C[j])
    else:
        Ans.append(Ans[i])

print(Ans)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
B = list(map(int, input().split()))
C = list(map(int, input().split()))

base = 0
cnt = collections.Counter(A)

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

Ans = []
Ans.append(base + (C[0]-B[0]) * cnt[B[0]])

for i in range(Q-1):
    if cnt[B[i+1]] != 0:
        Ans.append(Ans[i] + (C[i+1]-B[i+1]) * cnt[B[i+1]])
        for j in range(i+1):
            Ans[i+1] += B.count(C[j]) * (C[i+1] - C[j])
    else:
        Ans.append(Ans[i])

print(Ans)

Buggy submission (verdict: Runtime Error):
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
B, C = list(map(int, input().split())),list(map(int, input().split()))

base = 0
cnt = collections.Counter(A)

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

Ans = []
Ans.append(base + (C[0]-B[0]) * cnt[B[0]])

for i in range(Q-1):
    if cnt[B[i+1]] != 0:
        Ans.append(Ans[i] + (C[i+1]-B[i+1]) * cnt[B[i+1]])
        for j in range(i+1):
            Ans[i+1] += B.count(C[j]) * (C[i+1] - C[j])
    else:
        Ans.append(Ans[i])

print(Ans)