Problem:


Score : 400 points

Problem Statement

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.

Constraints

All values in input are integers.

 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5} 

 B_{i} \neq C_{i} 

Input

Input is given from Standard Input in the following format:

N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}

Output

Print Q integers S_{i} to Standard Output in the following format:

S_{1}
S_{2}
\vdots
S_{Q}

Note that S_{i} may not fit into a 32-bit integer.

Sample Input 1

4
1 2 3 4
3
1 2
3 4
2 4

Sample Output 1

11
12
16

Initially, the sequence A is 1,2,3,4.

After each operation, it becomes the following:

2, 2, 3, 4

2, 2, 4, 4

4, 4, 4, 4

Sample Input 2

4
1 1 1 1
3
1 2
2 1
3 5

Sample Output 2

8
4
4

Note that the sequence A may not contain an element whose value is B_{i}.

Sample Input 3

2
1 2
3
1 100
2 100
100 1000

Sample Output 3

102
200
2000



Sample input:
4
1 2 3 4
3
1 2
3 4
2 4


Sample output:
11
12
16

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    ans = []
    a = dict(collections.Counter(a))
    for _ in range(q):
        tmp = 0
        b, c = map(int, input().split())
        if b in a.keys():
            if c in a.keys():
                a[c] = a[b] + a[c]
            else:
                a[c] = a[b]
            del a[b]
        for key, value in a.items():
            tmp += key * value
        ans.append(tmp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
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(ans)
 cnt[x]+=cnt[y]

Submission status: Wrong Answer

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
q=int(input())
ans=0

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

Submission status: Wrong Answer

Solution code:
n=int(input())
#a,b=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
q=int(input())
dic={}
for a in al:
    dic[a]=dic.get(a,0)+1

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

for ans in ansl:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
array = []
replace = [0]*(10**5+1)
for i in A:
    replace[i] += 1
sum_s = sum(A)
for i in range(Q):
    m,n = [int(x) for x in input().split()]
    replace[n] += replace[m]

    diff = (n - m)*replace[n] - replace[m]*(n-m)
    sum_s += diff
    replace[m] = 0
    print(sum_s)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
numl=[0 for i in range(10**5+1)]
s=sum(a)
for aa in a:
  numl[aa-1]+=1

for qq in range(q):
  x,y=map(int,input().split())
  s+=numl[x-1]*(y-x)
  print(s)
  numl[y-1]+=numl[x-1]
  numl[x-1]=0
  print(numl)

Submission status: Wrong Answer

Solution code:
def main():
    N, *X = map(int, open(0).read().split())
    A = X[:N]
    Q = X[N]
    s = sum(A)
    B = {}
    for a in A:
        if a not in B:
            B[a] = 0
        B[a] += 1

    ans = []
    for i in range(Q):
        b, c = X[N + 1 + 2*i], X[N + 1 + 2*i + 1]
        if b in B:
            num = B[b]
            s += (c - b)*num
            if c not in B:
                B[c] = 0
            B[c] += num
        ans.append(str(s))
    print('\n'.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
read = lambda: list(map(int, input().split()))

n = int(input())
a = read()
q = int(input())
s = sum(a)
data = {}
for i in a:
    if i in data:
        data[i] += 1
    else:
        data[i] = 1

for _ in range(q):
    b, c = read()
    if b in data:
        s += (c - b) * data[b]
    else:
        data[b] = 0
    if c in data:
        data[c] += data[b]
        data[b] = 0
    else:
        data[c] = data[b]
    print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
q=int(input())
for _ in range(q):
    a,b=map(int,input().split())
    print(sum(l)-l.count(a)*a+b*l.count(a))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

d = defaultdict(int)

n = int(input())
a = [int(i) for i in input().split(" ")]
q = int(input())

operations = []

for i in range(q):
    temp = input().split(" ")
    operations.append((int(temp[0]), int(temp[1])))

for hoge in a:
    d[hoge] += 1

initial_sum = 0
for key, value in d.items():
    initial_sum += key * value

for op in operations:
    target, goto = op

    before = goto * d[goto] + target * d[target]
    d[goto] += d[target]
    after = goto * d[goto]


    diff = after - before
    
    initial_sum += diff
    print(initial_sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
q = int(input())
for i in range(q):
    b, c = map(str, input().split())
    for j in range(a.count(b)):
        a = a.replace(b, c)
    s = list(map(int, a.split()))
    print(sum(s))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L = [0] * 100001
for item in An:
    L[item] += 1

sum = sum(An)

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

Submission status: Wrong Answer

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

counter = dict(collections.Counter(a))
for i in range(q):
    s = 0
    try:
        counter[c[i]] += counter.get(b[i])
    except:
        counter.update({c[i]: int(counter.get(b[i])or 0)} )
    counter[b[i]] = 0    
    for key, val in counter.items():
        s += key * val
    print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
An = list(map(int, input().split()))
Q = int(input())

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


for i in range(Q):
    for j, name in enumerate(An):
        if An[j] == b[i]:
            An[j] = c[i]
    print(An)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
q=int(input())
before=[]
after=[]
for i in range(q):
    a,b=input().split()
    before.append(int(a))
    after.append(int(b))
    
su=sum(l)

for i in range(q):
  if before[i] in l:
    co=l.count(before[i])
    su=su+(after[i]-before[i])*co
    print(su)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans=''
for i in range(1,99):
    if N<=26**i:
        N-=1
        for j in range(i):
            ans += chr(ord('a')+N%26)
            N//=26
        break
    else:
        N -= 26**i
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
count = Counter(input().split())
ans = 0
for v, c in count.items():
    ans += int(v) * c
for i in range(int(input())):
    b, c = input().split()
    if b in count:
        ans -= count.get(b, 0) * int(b)
        count[c] = count[b] + count.get(c, 0)
        count[b] = 0
        ans += count.get(c, 0) * int(c)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
count = Counter(input().split())
ans = 0
for v, c in count.items():
    ans += int(v) * c
for i in range(int(input())):
    b, c = input().split()
    if b in count:
        ans -= count.get(b, 0) * int(b)
        ans += count.get(c, 0) * int(c)
        count[c] = count[b] + count.get(c, 0)
        count[b] = 0
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
count = Counter(input().split())
for i in range(int(input())):
    b, c = input().split()
    if b in count:
        count[c] = count[b] + count.get(c, 0)
        count[b] = 0
ans = 0
for v, c in count.items():
    ans += int(v) * c
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
a = input()
A = list(map(int,input().split()))
N = int(input())
dic = collections.Counter(A)

for i in range(N):
    ans = 0
    b,c = map(int,input().split())
    p = dic[b]
    dic[c] += p
    dic[b] = 0
    k = list(dic.keys())
    v = list(dic.values())
    for i in range(len(k)):
        if v[i]==0:
            break
        ans += k[i]*v[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
t=int(input())
import math
a=list(map(int,input().strip().split()))
q=int(input())
h=[0]*(100000+1)
sumi=0
for i in range(len(a)):
    h[a[i]]+=1
    sumi+=a[i]
    
for i in range(q):
    b,c=map(int,input().strip().split())
    sumi+=h[b]*(c-b)
    h[c]+=h[b]
    print(sumi)
        
        
        
    #a=list(map(int,input().strip().split()))

Submission status: Wrong Answer

Solution code:
n = int(input())
a =list(map(int,input().split()))
s =sum(a)
x = [0]*100001
for i in a:
    x[i] += 1

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(input())
a = list(map(int, input().split()))
'''
aa = ''.join(a)
aaa = str(aa)
#print(type(aa))
# print(a)
'''
aa = np.array(a)
q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    aa = np.where(aa == b, c, aa) 
    #print(aa)
    #aaa.replace(str(b), str(c))
    #print(aaa)

#ab = map(int, aa)
print(np.sum(aa))

Submission status: Wrong Answer

Solution code:
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]

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
a=sorted(a)
for _ in range(q):
    b,c=map(int,input().split())
    for i in range(n):
        if a[i]==b:
            a[i]=c
        elif a[i] > b:
            break
        else:
            pass    
    print(sum(a))

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_c =Counter(A)
Q = int(input())
S =[0]*Q
bc ={}
for i in range(Q):
    x,y = (int(i) for i in input().split())
    bc[x] =y
    #print(A_np)
sum_A =[0]*(Q+1)
sum_A[0] =sum(A)
ind =0
for k,v in bc.items():
    sum_A[ind+1] =sum_A[ind] -A_c[k] *k +A_c[k] *v
    A_c[v] +=A_c[k]
    A_c[k] =0
    #print(A_c)
    print(sum_A[ind +1])
    ind +=1

Submission status: Wrong Answer

Solution code:
import numpy as np

def run(n, seq, num, trials):
    count_dict = {i+1 : seq.count(i+1) for i in range(100000)}
    _sum = sum(k*v for k,v in count_dict.items())

    for i in range(num):
        b, c = trials[i]
        _val = count_dict[b]
        if _val == 0:
            continue
        _sum += (c-b)*_val
        print(_sum)
        count_dict[b] = 0
        count_dict[c] += _val

if __name__ == '__main__':
    n = int(input())
    seq = list(map(int, input().split()))
    num = int(input())
    trials = [map(int, input().split()) for _ in range(num)]
    run(n, seq, num, trials)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_c =Counter(A)
Q = int(input())
S =[0]*Q
bc ={}
for i in range(Q):
    x,y = (int(i) for i in input().split())
    bc[x] =y
    #print(A_np)
sum_A =[0]*(Q+1)
sum_A[0] =sum(A)
ind =0
for k,v in bc.items():
    sum_A[ind+1] =sum_A[ind] -A_c[k] *k +A_c[k] *v
    A_c[v] +=A_c[k]
    del A_c[k]
    #print(A_c)
    print(sum_A[ind +1])
    ind +=1

Submission status: Wrong Answer

Solution code:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_np =np.array(A,dtype=np.int64)
Q = int(input())
S =[0]*Q
for i in range(Q):
    b,c = (int(i) for i in input().split())
    A_np =np.where(A_np ==b,c,A_np)
    S[i] =np.sum(A_np)
    print(A_np)


print(*S,sep='\n')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
 
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
 
S = sum(A)
memory = [0] * 100001
for num in A:
    memory[num] += 1
for i in range(Q):
  S = S + memory[B[i]] * (C[i]- B[i])
  memory[C[i]] = memory[B[i]]
  memory[B[i]] = 0
  print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(input().split()) 
Q = int(input())
aLine = ""
for a in A:
  aLine += a
Rep = [list(input().split()) for i in range(Q)]
for i in range(Q):
  result = 0
  aLine = aLine.replace(Rep[i][0],Rep[i][1])
  for a in aLine:
    result += int(a)
  print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

cnt = Counter(a)

s = sum(cnt)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

cnt = Counter(a)

s = sum(cnt)

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

Submission status: Wrong Answer

Solution code:
#Replacing
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
u, count = np.unique(A,return_counts=True)
asum = A.sum()
for i in range(Q):
    B, C = list(map(int, input().split()))
    if B in u:
        posB = np.where(u==B)
        asum += int(count[posB]) * (C-B)
        print(u)
        print(count)
        if not (C in u):
            u[posB] = C
        else :
            posC = np.where(u==C)
            count[posC] += count[posB]
            u = np.delete(u,posB)
            count = np.delete(count,posB)
    # print(asum)
    # print(u)
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

arr = Counter(a)

s = sum(arr)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    for i in range(N):
        if A[i] == B:
            A[i] = C
            print(sum(A))

Submission status: Wrong Answer

Solution code:
import collections as c

n = int(input())

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

q = int(input())

s = sum(a)

cnt = c.Counter(a)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

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

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

        count[b] = 0

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
sum=sum(a)
a.sort()
a2,a3=[],[]
import bisect as bs

for i in set(a):
    a2.append(i)
    a3.append(a.count(i))

#print(sum)
#print(a2,a3)

from functools import lru_cache
@lru_cache(maxsize=None)
def idx(x):
    return bs.bisect_left(a2,x)

for _ in range(q):
    b,c=map(int,input().split())
    if b in a2:
        b_idx=idx(b)
        if a3[b_idx]!=0:
            if c in a2:
                c_idx=idx(c)
            else:
                bs.insort(a2,c)
                c_idx=idx(c)
                a3.insert(c_idx,0)
            sum+=(c-b)*a3[b_idx]
            a3[c_idx]+=a3[b_idx]
            a3[b_idx]=0
#        del a2[b_idx]
#        del a3[b_idx]
#    print(a2,a3)
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
a=list(map(int, input().split()))
Q = int(input())
num_a =[0]*100001
b=[]
c=[]
for i in range(Q):
  b1,c1=map(int, input().split())
  b.append(b1)
  c.append(c1)
for i in range(Q):
  if b[i] not in a:
    continue
  else:
    num_a[b[i]] = a.count(b[i])
num_b = []
for i in range(Q):
  if b[i] not in a:
    num_b.append(0)
  else:
    num_b.append(num_a[b[i]])
    num_a[c[i]] += num_a[b[i]]
    num_a[b[i]] = 0
sum = sum(a)
for i in range(Q):
  sum = sum - b[i]*num_b[i] +c[i]*num_b[i]
  print(sum)

Submission status: Wrong Answer

Solution code:
def xor_sum(ls):
  f=0
  for i in ls:
    f=f^i
  return f

n = int(input())
l = list(map(int,input().split()))
for i in range(n):
  print(xor_sum(l[:i]+l[i+1:]),end=" ")

Submission status: Wrong Answer

Solution code:
sum=0
dic={}
n=int(input())
lis=input()
lis=lis.split(' ')
def con(a,b):
    if b in dic:
        dic[b]=dic[b]+dic[a]
    else:
        dic[b]=dic[a]
for i in lis:
    sum=sum+int(i)
    if int(i) in dic:
        dic[int(i)]=dic[int(i)]+1
    else:
        dic[int(i)]=1
#print(dic)
#print(sum)
q=int(input())
for i in range(0,q):
    que=input()
    que=que.split()
    que[0]=int(que[0])
    que[1]=int(que[1])
    if que[0] in dic:
        if que[0]>que[1]:
            sum=sum-(que[0]-que[1])*dic[que[0]]
            con(que[0],que[1])
        else:
            sum=sum+(que[1]-que[0])*dic[que[0]]
            con(que[0],que[1])
    print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = sum(A)
Z = {}
for n in range(N):
    Z[A[n]] = 0
for n in range(N):
    Z[A[n]] += 1
D = []
Q = int(input())
for q in range(Q):
    x, y = map(int, input().split())
    if x in Z:
        C = C - x*Z[x]
        C = C + y*Z[x]
        D.append(C)
        if x == y:
            continue
        Z[y] = 1*Z[x]
        Z.pop(x)
    else:
        D.append(C)
for d in D:
    print(d)

Submission status: Wrong Answer

Solution code:
import collections

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

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

count = collections.Counter(A)
# count.append([0] * 10)
sumA = sum(A)

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = collections.Counter(list(map(int,input().split())))
q = int(input())
s = []

for i in range(q):
    b,c = map(int,input().split())
    if b in a:
        a[c] = a[b] + a[c]
        del a[b]
    s.append(sum(a))

for k in range(q):
    print(s[k])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = collections.Counter(list(map(int,input().split())))
q = int(input())
a

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int, input().split()))
q=int(input())
BC=[list(map(int,list(input().split()))) for _ in range(q)]

#数列Ａを操作するのは時間がかかるので、出現回数でカウントしていく。

count={}
for i in range(n):
  if A[i] in count:
    count[A[1]]+=1
  else:
    count[A[i]]=1
 
    
total=sum(A)
for i in range(q):
  if BC[i][0] in count:
    if BC[i][1] in count:
      count[BC[i][1]]+=count[BC[i][0]]
      total+=(count[BC[i][0]])*(BC[i][1]-BC[i][0])
    else:
      count[BC[i][1]]=count[BC[i][0]]
      total+=(count[BC[i][0]])*(BC[i][1]-BC[i][0])
    count[BC[i][0]]=0
  print(total)

Submission status: Wrong Answer

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

for i in a:
    num[i] += 1

s = sum(a)

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

Submission status: Wrong Answer

Solution code:
#input
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
array = [list(map(int, input().split())) for _ in range(Q)]
#variable
count = []
number = []
S = []
n = 0

A.sort()
while True:
    number.append(A[n])
    count.append(A.count(number[len(number)-1]))
    n = n + count[len(count)-1]
    if n >= N or count[0] == N:
        break


print(number)
print(count)
while len(S)  < Q :
    n = 0
    for i in range(len(number)):
        if number[i] == array[len(S)][0]:
            number[i] = array[len(S)][1]
        n = n + number[i] * count[i]
    S.append(n)
for i in S[0:]:
    print(i)

Submission status: Wrong Answer

Solution code:
#input
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
array = [list(map(int, input().split())) for _ in range(Q)]
#variable
count = []
number = []
S = []
n = 0

A.sort()
while True:
    number.append(A[n])
    count.append(A.count(number[len(number)-1]))
    n = n + count[len(count)-1]
    print(n)
    if n >= N or count[0] == N:
        break


print(number)
print(count)
while len(S)  < Q :
    n = 0
    for i in range(len(number)):
        if number[i] == array[len(S)][0]:
            number[i] = array[len(S)][1]
        n = n + number[i] * count[i]
    S.append(n)
for i in S[0:]:
    print(i)

Submission status: Wrong Answer

Solution code:
#input
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
array = [list(map(int, input().split())) for _ in range(Q)]
#variable
count = []
number = []
S = []
n = 0

A.sort()
while True:
    number.append(A[n])
    count.append(A.count(number[len(number)-1]))
    n = n + count[len(count)-1]
    print(n)
    if n >= N or count[0] == N:
        break


print(number)
print(count)
while len(S)  < Q :
    n = 0
    for i in range(len(number)):
        if number[i] == array[len(S)][0]:
            number[i] = array[len(S)][1]
        n = n + number[i] * count[i]
    S.append(n)
print(S)

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n, *i = map(int, open(0).read().split())
    a = i[:n]
    _ = i[n]
    d = Counter(a)
    s = sum(k * v for k, v in d.items())
    ans = []
    for b, c in zip(*[iter(i[n + 1:])] * 2):
        v, w = d.get(b), d.get(c)
        if v and w:
            d.pop(b)
            d[c] += v
            s += (c-b) * v
        elif v:
            d[c] = v
            s += (c-b) * v
        ans.append(s)

    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
q=int(input())
before=[]
after=[]
for i in range(q):
    a,b=input().split()
    before.append(int(a))
    after.append(int(b))
    
for i in range(q):
  print(before[i])
  print(after[i])
  l=[after[i] if j == before[i] else j for j in l]
  print(sum(l))

Submission status: Wrong Answer

Solution code:
from collections import *
from operator import mul

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


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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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])

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
q = int(input())
x = {}
for i in lis:
    if i not in x:
        x[i]=1
    else:
        x[i]+=1
total = sum(lis)
for i in range(q):
    a,b=map(int,input().split())
    diff = b-a
    if a in x:
        total += diff*x[a]
    else:
        print(total)
        continue
    if b in x:
        x[b]+=x[a]
    else:
        x[b]=0
        x[b]+=x[a]
    print(total)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
for i in range(q):
    b, c = map(int, input().split())
    if b in dic and c not in dic:
        dic[b] = dic[c]
        del dic[b]
    elif b in dic and c in dic:
        dic[c] += dic[b]
        del dic[b]
    sum_list = [x * y for (x, y) in dic.items()]
    print(sum(sum_list))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
D=dict()
s=0
for i in A:
  s+=i
  if i in D:
    D[i]+=1
  else:
    D[i]=1
for _ in range(Q):
  b,c=map(int,input().split())
  if b in D:
    s+=(c-b)*D[b]
    if c in D:
      D[c]+=D[b]
    else:
      D[c]=D[b]
  print(s)

Submission status: Wrong Answer

Solution code:
#import math
#import numpy as np
#import torch
#import torch.nn as nn
#import matplotlib.pyplot as plt
#from decimal import Decimal
#import itertools
import collections

N=int(input())
#N,K = map(int,input().split())
#B,W = map(int,input().split())
#T=int(input())
A = list(map(int,input().split()))
#S=str(input())
#A=[p for p in range(2*10**5)]
Q=int(input())
c=collections.Counter(A)
s=sum(A)
for i in range(Q):
    #print(A)
    B,C = map(int,input().split())
    print(c[B])
    if c[B]:
        s += (C-B)*c[B]
        c[C] += c[B]
        c[B] = 0

    print(s)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    l = {i:0 for i in range(1,100001)}
    for num in A:
        l[num] += 1

    s = sum(A)

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


if __name__ == '__main__':
    main()