TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:    * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;   * the dogs numbered 27,28,29,\cdots,701,702  were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;   * the dogs numbered 703,704,705,\cdots,18277,18278  were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;   * the dogs numbered 18279,18280,18281,\cdots,475253,475254  were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;   * the dogs numbered 475255,475256,\cdots  were respectively given the names `aaaaa`, `aaaab`, ...;   * and so on.  To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:  `a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`, `zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ..., `zzz`, `aaaa`, ...  Now, Roger asks you:  "What is the name for the dog numbered N?"

Submission attempts (in order):
n=int(input())
a=26
b=1
import string
array=list(string.ascii_lowercase)
while n>a:
  b+=1
  a+=26**b
if b==1:
  print(array[n+1])
else:
  c=b-1
  d=n-26**c
  for i in range(c-1):
    brray=[0]
    crray=[d]
    brray[i+1]=crray[i]//26**(c-i)
    crray[i+1]=crray[i]%26**(c-i)
  ans=array[brray[1]+1]
  if c>1:
    for j in range(2,c):
      ans=ans+brray[j]
  ans=ans+crray[c]
  print(ans)

n=int(input())
a=26
b=1
import math
import string
array=list(string.ascii_lowercase)
while n>a:
  b+=1
  a+=26**b
if b==1:
  print(array[n-1])
else:
  c=b-1
  d=n-a
  brray=[0]
  crray=[d]
  for i in range(c):
    brray.append(math.ceil(crray[i]/(26**(c-i))))
    crray.append(crray[i]%(26**(c-i)))
  ans=array[brray[1]-1]
  if c>1:
    for j in range(2,b):
      ans=ans+array[brray[j]-1]
  ans=ans+array[crray[c]-1]
  print(ans)

Verdicts: Runtime Error

Accepted
Problem: 1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:    * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;   * the dogs numbered 27,28,29,\cdots,701,702  were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;   * the dogs numbered 703,704,705,\cdots,18277,18278  were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;   * the dogs numbered 18279,18280,18281,\cdots,475253,475254  were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;   * the dogs numbered 475255,475256,\cdots  were respectively given the names `aaaaa`, `aaaab`, ...;   * and so on.  To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:  `a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`, `zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ..., `zzz`, `aaaa`, ...  Now, Roger asks you:  "What is the name for the dog numbered N?"

Submission attempts (in order):
n=int(input())
k=[]
def a(i):
    if i==0:
        return 26
    else:
        return i
while n>26:
    k+=[chr(96+a(n%26))]
    if n%26==0:
        n=n//26-1
    else:
        n//=26
k+=[chr(96+a(n))]
print(z+1,"".join(k[::-1]))

n=int(input())
k=[]
def a(i):
    if i==0:
        return 26
    else:
        return i
while n>26:
    k+=[chr(96+a(n%26))]
    if n%26==0:
        n=n//26-1
    else:
        n//=26
k+=[chr(96+a(n))]
print("".join(k[::-1]))

Verdicts: Runtime Error

Accepted
Problem: 1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:    * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;   * the dogs numbered 27,28,29,\cdots,701,702  were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;   * the dogs numbered 703,704,705,\cdots,18277,18278  were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;   * the dogs numbered 18279,18280,18281,\cdots,475253,475254  were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;   * the dogs numbered 475255,475256,\cdots  were respectively given the names `aaaaa`, `aaaab`, ...;   * and so on.  To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:  `a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`, `zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ..., `zzz`, `aaaa`, ...  Now, Roger asks you:  "What is the name for the dog numbered N?"

Submission attempts (in order):
n = int(input())
a = input().split()
q = int(input())

for i in range(q):
    stdins = input().split()
    for j in range(n):
        a[j] = a[j].replace(stdins[0], stdins[1])
    ans = sum([int(an) for an in a])
    print(ans)


def int2char(i):
    return chr(ord("a") + i - 1)

N = int(input())

ans = ""
while (True):
    N_lsb_int = ((N - 1) % 26) + 1
    N_next = int((N - N_lsb_int)/26)
    ans = int2char(N_lsb_int) + ans
    if N_next == 0:
        break
    N = N_next

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:    * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;   * the dogs numbered 27,28,29,\cdots,701,702  were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;   * the dogs numbered 703,704,705,\cdots,18277,18278  were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;   * the dogs numbered 18279,18280,18281,\cdots,475253,475254  were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;   * the dogs numbered 475255,475256,\cdots  were respectively given the names `aaaaa`, `aaaab`, ...;   * and so on.  To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:  `a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`, `zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ..., `zzz`, `aaaa`, ...  Now, Roger asks you:  "What is the name for the dog numbered N?"

Submission attempts (in order):
n = int(input())

ans = ""

while(n > 0):
    tmp = n % 26
    if tmp > 0:
        ans += chr((tmp - 1) + ord('a'))
    else:
        ans += 'z'
        n -= 1
    n /= 26
    if n == 0:
        break

print(ans[::-1])


n = int(input())

ans = ""

al = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
      'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

while n > 0:
    tmp = n % 26
    if tmp > 0:
        ans += al[tmp-1]
    else:
        ans += 'z'
        n -= 1
    n /= 26
    if n == 0:
        break

print(ans[::-1])


n = int(input())

ans = ""

while(n > 0):
    tmp = n % 26
    if tmp > 0:
        ans += chr((tmp - 1) + ord('a'))
    else:
        ans += 'z'
        n -= 1
    n /= 26

print(ans[::-1])


n = int(input())

ans = ""

al = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
      'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

while n > 0:
    tmp = n % 26
    if tmp > 0:
        ans += al[tmp-1]
    else:
        ans += 'z'
        n = n - 1
    n = n // 26

print(ans[::-1])


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:    * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;   * the dogs numbered 27,28,29,\cdots,701,702  were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;   * the dogs numbered 703,704,705,\cdots,18277,18278  were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;   * the dogs numbered 18279,18280,18281,\cdots,475253,475254  were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;   * the dogs numbered 475255,475256,\cdots  were respectively given the names `aaaaa`, `aaaab`, ...;   * and so on.  To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:  `a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`, `zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ..., `zzz`, `aaaa`, ...  Now, Roger asks you:  "What is the name for the dog numbered N?"

Submission attempts (in order):
n=int(input())
mlist=[]

for i in range(15):
  mm=n%26 
  m=mm if mm >0 else 26
  n = n//26
  mlist.insert(0,m)
  if n<26:
    m=n
    mlist.insert(0,m)
    break
  else:
    pass

mlist_alph=[chr(i+96) for i in mlist]
print(''.join(mlist_alph))
  

n=int(input())
mlist=[]

for i in range(11):
  m=n%26
  n = n//26
  mlist.insert(0,m)
  if n<26:
    m=n
    mlist.insert(0,m)
    break
  else:
    pass
mlist_alph=[chr(i+96) for i in mlist]
print(''.join(mlist_alph))

n=int(input())
mlist=[]

for i in range(11):
  mm=n%26 
  m=mm if mm >0 else 26
  n = n//26
  mlist.insert(0,m)
  if n<26:
    m=n
    mlist.insert(0,m)
    break
  else:
    pass

mlist_alph=[chr(i+96) for i in mlist]
print(''.join(mlist_alph))
  

n=int(input())
mlist=[]

for i in range(15):
  mm=n%26 
  m=mm if mm >0 else 26
  n = n//26
  mlist.insert(0,m)
  if n<26:
    m=n if n >0 else 26
    mlist.insert(0,m)
    break
  else:
    pass

mlist_alph=[chr(i+96) for i in mlist]
print(''.join(mlist_alph))

n=int(input())
mlist=[]

for i in range(15):
  mm=n%26 
  m=mm if mm >0 else 26
  n = n//26
  mlist.insert(0,m)
  if n<26:
    mm=n%26 
    m=mm if mm >0 else 26
    mlist.insert(0,m)
    break
  else:
    pass

mlist_alph=[chr(i+96) for i in mlist]
print(''.join(mlist_alph))
  

n=int(input())
name=""
for i in range(15):
  n=n-1
  name=name+chr(97+n%26)
  n=n//26
  if n==0:
    break
print(name[::-1])

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:    * the dogs numbered 1,2,\cdots,26 were respectively given the names `a`, `b`, ..., `z`;   * the dogs numbered 27,28,29,\cdots,701,702  were respectively given the names `aa`, `ab`, `ac`, ..., `zy`, `zz`;   * the dogs numbered 703,704,705,\cdots,18277,18278  were respectively given the names `aaa`, `aab`, `aac`, ..., `zzy`, `zzz`;   * the dogs numbered 18279,18280,18281,\cdots,475253,475254  were respectively given the names `aaaa`, `aaab`, `aaac`, ..., `zzzy`, `zzzz`;   * the dogs numbered 475255,475256,\cdots  were respectively given the names `aaaaa`, `aaaab`, ...;   * and so on.  To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:  `a`, `b`, ..., `z`, `aa`, `ab`, ..., `az`, `ba`, `bb`, ..., `bz`, ..., `za`, `zb`, ..., `zz`, `aaa`, `aab`, ..., `aaz`, `aba`, `abb`, ..., `abz`, ..., `zzz`, `aaaa`, ...  Now, Roger asks you:  "What is the name for the dog numbered N?"

Submission attempts (in order):
N = int(input())
n = []
while N > 0:
  r = N%26
  if r == 0: r = 26
  # print(96+r)
  n.append(chr(96+r))
  N //= 26
n.reverse()
for nn in n:
  print(nn, end="")

N = int(input())
ans = ''
while N > 0:
  N -= 1
  ans += chr(ord('a')+N%26)
  N //= 26
print(ans[::-1])

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
input()
a=list(map(int,input().split()))
b=int(input())
for i in range(b):
  c,d=map(int,input().split())
  a=[d if j==c else j for j in a]
print(' '.join(map(str, a)))

input()
a=list(map(int,input().split()))
b=int(input())
for i in range(b):
  c,d=map(int,input().split())
  a=[d if j==c else j for j in a]
  print(' '.join(map(str, a)))

from sys import stdin
input=stdin.readline
input()
a=input().strip()
b=int(input())
for i in range(b):
  n,m=map(int,input().split())
  a.replace(str(n),str(m))
  print(sum(a))

input()
a=list(map(int,input().split()))
b=int(input())
for i in range(b):
  c,d=map(int,input().split())
  a=[d if j==c else j for j in a]
print(' '.join(map(str, a)))

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)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
n = int(input())
a = input().split()
alist = set()
adic = {}
for i in a:
    if int(i) in alist:
        adic[int(i)] = adic[int(i)] + 1
    else:
        alist.add(int(i))
        adic[int(i)] = 1

q = int(input())
ans = []

for i in range(q):
    s = input().split()
    b = int(s[0])
    c = int(s[1])
    if b in alist:
        if not(c in alist):
            adic[c] = 0
            alist.add(c)
        adic[c] = adic[c] + adic[b]
        adic[b] = 0
        su = 0
        for j in adic:
            su += j * adic[j]
    ans.append(su)

print(ans)

n = int(input())
a = input().split()
alist = set()
adic = {}
for i in a:
    if int(i) in alist:
        adic[int(i)] = adic[int(i)] + 1
    else:
        alist.add(int(i))
        adic[int(i)] = 1

q = int(input())
ans = []


for i in range(q):
    s = input().split()
    b = int(s[0])
    c = int(s[1])
    if b in alist:
        if not(c in alist):
            adic[c] = 0
            alist.add(c)
        adic[c] = adic[c] + adic[b]
        adic[b] = 0
        su = 0
        for j in adic:
            su += j * adic[j]
    #ans.append(sum(adic.values()))
    ans.append(su)
    #tt.append(adic)
    #print(adic)

print(ans)
#print(tt)

n = int(input())
a = input().split()
alist = set()
adic = {}
su = 0

for i in a:
    su += int(i)
    if int(i) in alist:
        adic[int(i)] = adic[int(i)] + 1
    else:
        alist.add(int(i))
        adic[int(i)] = 1

q = int(input())
ans = []

for i in range(q):
    s = input().split()
    b = int(s[0])
    c = int(s[1])
    if b in alist:
        if not(c in alist):
            adic[c] = 0
            alist.add(c)
        adic[c] = adic[c] + adic[b]
        su = su + (c * adic[b]) - (b * adic[b])
        adic[b] = 0

    ans.append(su)
for i in range(len(ans)):
    print(ans[i])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
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]]
	ans[c[i]] += ans[b[i]]
	ans[b[i]] = 0
	print(s)

from collections import Counter

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

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

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

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)

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)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    x = dic.get(b)
    if x == None:
        l.append(sum)
        continue
    if b < c:
        sum += (c - b) * x
    else:
        sum -= (b- c) * x
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]
    print(dic)    

for s in l:
    print(s)

import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)
print(A, dic, sum)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    if dic.get(b) == None:
        continue
    if b < c:
        sum += (c - b) * dic[b]
    else:
        sum -= (b- c) * dic[b]
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]
    print(dic)    


for s in l:
    print(s)

import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    x = dic.get(b)
    if x == None:
        l.append(sum)
        continue
    if b < c:
        sum += (c - b) * x
    else:
        sum -= (b - c) * x
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]

for s in l:
    print(s)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
from collections import Counter
dicy = {}
def swap(a,b):
	tmp = 0
	try:
		tmp = dicy.pop(a)
	except Exception:
		tmp = 0

	try:
		dicy[b] += tmp
	except Exception:
		dicy[b] = tmp

	return (int(b)-int(a)) * tmp
  

max = input()
dicy = dict(Counter(input().split(' ')))
result = 0
for v,k in dicy.items():
	result += int(v)*int(k)
print(result)
num_oper = int(input())
for i in range(num_oper):
	a,b = input().split(' ')
	diff = swap(a,b)
	result += diff
	print(result)

from collections import Counter
dicy = {}
def swap(a,b):
	tmp = 0
	try:
		tmp = dicy.pop(a)
	except Exception:
		tmp = 0

	try:
		dicy[b] += tmp
	except Exception:
		dicy[b] = tmp

	return (int(b)-int(a)) * tmp
  

max = input()
dicy = dict(Counter(input().split(' ')))
result = 0
for v,k in dicy.items():
	result += int(v)*int(k)
num_oper = int(input())
for i in range(num_oper):
	a,b = input().split(' ')
	diff = swap(a,b)
	result += diff
	print(result)

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
n = int(input())
alist = [int(s) for s in input().split(" ")]
adict = {}
ans = 0
for a in alist:
  ans += a
  if a in adict:
    adict[a] += 1
  else:
    adict[a] = 1
q = int(input())
bclist = []
for _ in range(q):
  b, c = [int(s) for s in input().split(" ")]
  bclist.append([b, c])

for b, c in bclist:
  if c in adict and b in adict:
    ans += c * (adict[c] + adict[b]) - b * adict[b]
    adict[c] += adict[b]
    del adict[b]
  elif b in adict:
    ans += (c - b) * adict[b]
    adict[c] = adict[b]
    del adict[b]
  print(ans)

n = int(input())
alist = [int(s) for s in input().split(" ")]
adict = {}
ans = 0
for a in alist:
  ans += a
  if a in adict:
    adict[a] += 1
  else:
    adict[a] = 1
q = int(input())
bclist = []
for _ in range(q):
  b, c = [int(s) for s in input().split(" ")]
  bclist.append([b, c])

for b, c in bclist:
  if c in adict and b in adict:
    ans += (c - b) * adict[b]
    adict[c] += adict[b]
    del adict[b]
  elif b in adict:
    ans += (c - b) * adict[b]
    adict[c] = adict[b]
    del adict[b]
  print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
import numpy as np

N = int(input())
lis = np.zeros(10**5)

As = np.array(input().split()).astype(np.int64)
NUM = As.sum()

for n in As:
  lis[n-1] += 1

Q = int(input())
for q in range(Q):
  B, C = map(int, input().split())
  nnn = lis[B-1]
  lis[B-1] = 0
  lis[C-1] += nnn
  NUM = NUM - B*nnn + C*nnn
  print(NUM)

import numpy as np

N = int(input())
lis = np.zeros(10**5)

As = np.array(input().split()).astype(np.int64)
NUM = As.sum()

for n in As:
  lis[n-1] += 1

Q = int(input())
for q in range(Q):
  B, C = map(int, input().split())
  nnn = lis[B-1]
  lis[B-1] = 0
  lis[C-1] += nnn
  NUM = NUM - B*nnn + C*nnn
  print(int(NUM))

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
R = lambda: map(int, input().split())
R()
a = [0] * 100001
s = 0
for x in R():
  s += x
  a[x] += 1
q, = R()
for _ in range(q):
  b, c = R()
  s += (c - b) * a[b]
  print(s)
  a[c]+=d[b]
  a[b] = 0


R = lambda: map(int, input().split())
R()
a = [0] * 100001
s = 0
for x in R():
  s += x
  a[x] += 1
q, = R()
for _ in range(q):
  b, c = R()
  s += (c - b) * a[b]
  print(s)
  a[c]+=a[b]
  a[b] = 0


Verdicts: Runtime Error

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
N = int(input())
num_list = list(map(int,input().split()))
q = int(input())

num_list.sort()

for i in range(q):
  query = list(map(int,input().split()))
  for j in range(len(num_list)):
    if num_list[j] == query[0]:
      num_list[j] = query[1]
    if num_list[j] > query[0]:
      break
  print(sum(num_list))

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

table = [0] * 100001

c = 0
s = 0

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

print(su,s)

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)


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

table = [0] * 100001

c = 0
s = 0
 
for i in A:
    table[i] += 1
    sum += i
    
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)


N = int(input())
num_list = list(map(int,input().split()))
q = int(input())

for i in range(len(num_list)):
  ans += num_list[i]

for j in range(q):
  query = list(map(int,input().split()))
  cnt = num_list.count(query)
  ans += (query[1] - query[0]) * cnt
  print(ans)

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

table = [0] * 100001

c = 0
s = 0

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

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)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
import collections
N = int(input())

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

# print(c)

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:
        # print(i)
        s += i * c[i]
    print(s)    

import collections
N = int(input())

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

# print(c)
v = 0

for i in c:
    # print(i)
    v += i * c[i]
# print(v)    

Q = int(input())


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

    # s=0
    
    #     # print(i)
    
    print(v)    
    

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
n = int(input())
arr = list(map(int,input().split()))
t = int(input())
while t:
    t-=1
    k,r = map(int,input().split())
    arr.sort()
    if k in arr:
        for i in range(n):
            if arr[i]>k:
                break
            if arr[i]==k:
                arr[i]=r
            
    print(arr)
    print(sum(arr))

n = int(input())
arr = list(map(int,input().split()))
t = int(input())
su = sum(arr)
print(su)
while t:
    t-=1
    k,r = map(int,input().split())
    p = arr.count(k)
    su += (r-k)*p
    print(su)

n = int(input())
arr = list(map(int, input().split()))
su = sum(arr)
lst = [0]*100001
q = int(input())
for i in arr:
    lst[i] += 1
for _ in range(q):
    b, c = map(int, input().split())
    su += (c - b) * lst[b]
    print(su)
    lst[c] += lst[b]
    lst[b] = 0


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
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())
    dic[B] = 1
    dic[C] = 0
    sums += dic[B] * (C - B)
    print(sums)


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)


Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
l = [0] * 10**5
tot = 0
for i in range(N) :
    l[A[i]]+=1
    tot += A[i]
for i in range(Q):
    s0 = S[i][0]
    s1 = S[i][1]
    tot += s1 * (l[s0] + l[s1]) - (s0 * l[s0] + s1*l[s1])
    l[s1] += l[s0]
    l[s0] = 0
    print(tot)

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]

l = [0] * 10**6
tot = 0
for i in range(N) :
    l[A[i]]+=1
    tot += A[i]
for i in range(Q):
    s0 = S[i][0]
    s1 = S[i][1]
    tot += s1 * (l[s0] + l[s1]) - (s0 * l[s0] + s1*l[s1])
    l[s1] += l[s0]
    l[s0] = 0
    print(tot)

Verdicts: Runtime Error

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = []
c = 0
s = sum(A)
table = [0] * 100010
# A = pd.Series(A)
# for a in A:
#     print(a)

for i in A:
    table[i] += 1
for i in range(Q):
    B, C = map(int,input().split())
    # if B in A:
    
    c = table[B]
    s += (C - B) * c
    table[C] = table[B]
    table[B] = 0
    # print(s)
        
        # string = ",".join(A)
        # string_new = string.replace(B,C)
        # A =  string_new.split(",")
        
    S.append(s)

        # A.replace(B, C,c)
        # while B in A:
        
    # for a in A:
    #     print(a)
    # else:
        # S.append(s)



for s in S:
    print(s)


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = []
c = 0
s = sum(A)
table = [0] * 100010
# A = pd.Series(A)
# for a in A:
#     print(a)

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

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = []
c = 0
s = sum(A)
table = [0] * 100010
# A = pd.Series(A)
# for a in A:
#     print(a)

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

for i in range(Q):
    B, C = map(int,input().split())
    # if B in A:
    
    c = table[B]
    s += (C - B) * c
    table[C] += table[B]
    table[B] = 0
    # print(s)
        
        # string = ",".join(A)
        # string_new = string.replace(B,C)
        # A =  string_new.split(",")
        
    S.append(s)

        # A.replace(B, C,c)
        # while B in A:
        
    # for a in A:
    #     print(a)
    # else:
        # S.append(s)



for s in S:
    print(s)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
from collections import Counter


def solve(string):
    n, *aqbc = map(int, string.split())
    a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:]
    s = sum(a)
    t = Counter(a)
    ans = []
    for b, c in zip(*[iter(bc)] * 2):
        t[c] += t[b]
        t[b] = 0
        s += (c - b) * t[b]
        ans.append(s)
    return "\n".join(map(str, ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


from collections import Counter


def solve(string):
    n, *aqbc = map(int, string.split())
    a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:]
    s = sum(a)
    t = Counter(a)
    ans = []
    for b, c in zip(*[iter(bc)] * 2):
        if b in t.keys():
            s += (c - b) * t[b]
            t[b], t[c] = 0, t[b] + t[c]
        ans.append(s)
    return "\n".join(map(str, ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
ans_count = []
count = collections.Counter(a)
for i in range(q):
  num = count[bc[i][0]]
  count[bc[i][0]] = 0
  count[bc[i][1]] += num
  ans_count.append(count)

for ans in ans_count:
  total = 0
  for key, value in zip(count.keys(), count.values()):
    total += int(key) * int(value)
  print(total)

import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
ans_count = []
total = 0
for i in range(n):
  total += a[i]

count = collections.Counter(a)
for i in range(q):
  num = count[bc[i][0]]
  count[bc[i][0]] = 0
  count[bc[i][1]] += num
  total += (bc[i][1] - bc[i][0]) * num
  print(total)

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
n = int(input())
list_a = list(map(int, input().split()))

list_a.sort()

counts = []

for i in range(0, 100000):
    if (i+1) in list_a:
        counts.append(list_a.count(i))
    else:
        counts.append(0)

q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)


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

list_a.sort()

counts = []

for i in range(0, 100000):
    if (i+1) in list_a:
        counts.append(list_a.count(i+1))
    else:
        counts.append(0)

print(counts)

q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)


import numpy as np

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

counts = np.zeros(100000, dtype=int)

ans = 0

for i in range(len(list_a)):
    counts[list_a[i]-1] += 1
    ans += list_a[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())

    ans += counts[b-1] * (c - b)

    counts[c-1] += counts[b-1]
    counts[b-1] = 0

    print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
import numpy as np
from numba import njit

n=int(input())
a=np.array(list(map(int, input().split())))
q=int(input())
a_sum= np.sum(a)


@njit
def func(a,b,c,a_sum):
  count=np.count_nonzero(a==b)
  a[a==b]=c
  a_sum += count*(c-b)
  return a,a_sum
  
for i in range(q):
  b,c=map(int, input().split())
  a,a_sum=func(a,b,c,a_sum)
  print(a_sum)

import collections

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

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


Verdicts: Time Limit Exceeded

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
from collections import Counter

def Replacing():

    Num = int(input())

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

    Sum = sum(value_A)
    Counter_value = Counter(value_A)

    NumB = int(input())

    for i in range(NumB):
        value_B = list(map(int,input().split()))

        Sum += (value_B[1] - value_B[0])*Counter_value(value_B[0])
        Counter_value[Ci] += Counter_value[Bi]
        Counter_value[Bi] = 0

        print(Sum)

if __name__ == '__main__':
    Replacing()


from collections import Counter

def Replacing():

    Num = int(input())

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

    Sum = sum(value_A)
    Counter_value = Counter(value_A)

    NumB = int(input())

    for i in range(NumB):
        value_B = list(map(int,input().split()))

        Sum += (value_B[1] - value_B[0])*Counter_value(value_B[0])
        Counter_value[value_B[1]] += Counter_value[value_B[0]]
        Counter_value[value_B[0]] = 0

        print(Sum)

if __name__ == '__main__':
    Replacing()


from collections import Counter

def Replacing():

    Num = int(input())

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

    Sum = sum(value_A)
    Counter_value = Counter(value_A)

    NumB = int(input())

    for i in range(NumB):
        value_B = list(map(int,input().split()))

        Sum += (value_B[1] - value_B[0])*Counter_value(value_B[0])
        Counter_value[Ci] += Counter_value[Bi]
        Counter_value[Bi] = 0

        print(Sum)

if __name__ == '__main__':
    Replacing()


from collections import Counter

def Replacing():

    Num = int(input())

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

    Sum = sum(value_A)
    Counter_value = Counter(value_A)

    NumB = int(input())

    for i in range(NumB):
        value_B = list(map(int,input().split()))

        Sum += (value_B[1] - value_B[0])*Counter_value[value_B[0]]
        Counter_value[value_B[1]] += Counter_value[value_B[0]]
        Counter_value[value_B[0]] = 0

        print(Sum)

if __name__ == '__main__':
    Replacing()


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
n = int(input())
A = [int(x) for x in input().split()]
sumA = sum(A)
counter = [0]*(10**5+1)
for i in range(n):
    counter[A[i]] += 1

print(counter[:30])
q = int(input())

queue = [list(map(int,input().split())) for i in range(q)]

for b,c in queue:    
    b_cnt = counter[b]
    sumA -= (b*b_cnt)
    counter[b] = 0
    c_cnt = counter[c]
    sumA += c*(b_cnt)
    counter[c] = b_cnt+c_cnt
    print(sumA)
    

n = int(input())
A = [int(x) for x in input().split()]
sumA = sum(A)
counter = [0]*(10**5+1)
for i in range(n):
    counter[A[i]] += 1

q = int(input())

queue = [list(map(int,input().split())) for i in range(q)]

for b,c in queue:    
    b_cnt = counter[b]
    sumA -= (b*b_cnt)
    counter[b] = 0
    sumA += c*(b_cnt)
    counter[c] += b_cnt
    print(sumA)
    

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
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:
        print(sum - (b - c) * dic[b])
    else:
        print(sum)


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):
    if b in dic:
        b, c = map(int, input().split())
        print(sum - (b - c) * dic[b])


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()]
for i in range(q):
    b, c = map(int, input().split())
    print(sum(sum_list) - (b - c) * dic[b])


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)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
def sum_dict(d, sum, b, c):
    val = 0
    if b in d:
        val = d[b]
        sum -= (b * val)
        del d[b]
        d[c] = d.get(c, 0) + val
        sum += (c * val)
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, b, c)
    print(s)

def sum_dict(d, sum, b, c):
    val = 0
    if b in d:
        val = d[b]
        sum -= (b * val)
        del d[b]
        d[c] = d.get(c, 0) + val
        sum += (c * val)
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, s, b, c)
    print(s)

Verdicts: Runtime Error

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
n = int(input())
num = list(map(int,input().strip().split()))
s = sum(num)
num_dict = {}
for i in num:
  if i in num_dict:
    num_dict[i] += 1
  else:
    num_dict[i] = 1
q = int(input())
for i in range(q):
  b,c = map(int,input().strip().split())
  if b in num_dict:
    num_dict[c] = num_dict[b]
    del num_dict[b]
    if b > c:
      s = s - (b-c)*num_dict[c]
      print(s)
    else:
      s = s + (c-b)*num_dict[c]
      print(s)
  else:
    print(s)
  

n = int(input())
num = list(map(int,input().strip().split()))
s = sum(num)
num_dict = {}
for i in num:
  if i in num_dict:
    num_dict[i] += 1
  else:
    num_dict[i] = 1
q = int(input())
for i in range(q):
  b,c = map(int,input().strip().split())
  if c in num_dict:
    if b in num_dict:
      k = num_dict[b]
      num_dict[c] += num_dict[b]
      del num_dict[b]
      if b > c:
        s = s - (b-c)*k
        print(s)
      else:
        s = s + (c-b)*k
        print(s)
    else:
      print(s)
  else:
    if b in num_dict:
      k = num_dict[b]
      num_dict[c] = num_dict[b]
      del num_dict[b]
      if b > c:
        s = s - (b-c)*k
        print(s)
      else:
        s = s + (c-b)*k
        print(s)
    else:
      print(s)
  
  

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
N = int(input())
print(int(N*(N-1)/2))

N = int(input())
a = list(map(int,input().split()))
Q = int(input())
bc = [[int(i) for i in input().split()] for j in range(Q)]
 
counter = [0] * 1000000
for i in a:
    counter[i] += 1

ans = sum(a)
 
for _ in bc:
    ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]
    counter[_[1]] += counter[_[0]]
    counter[_[0]] = 0
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.  You will now successively do the following Q operations:    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Submission attempts (in order):
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()

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

Verdicts: Wrong Answer

Accepted