TnT/Multi_CodeNet4Repair huggingface dataset:
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):
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second


#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
#define INF (int)1e9
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
int a[mxN];

int sum(vector<int> v)
{
    int s = 0;
    for (int i = 0; i < v.size(); ++i)
    {
        s += v[i];
    }
    return s;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vi v(n);
    for (auto &x : v)
        cin >> x;

    int t;
    cin >> t;

    int s = sum(v);
    map<int, int> m;
    for (auto x : v)
        if (m.find(x) != m.end())
            m[x] += 1;
        else
            m[x] = 1;
    while (t--)
    {
        int b, c;
        cin >> b >> c;
        if (m.find(c) != m.end())
            m[c] += m[b];
        else
            m[c] = m[b];
        s += ((c - b) * m[b]);
        m[b] = 0;
        cout << s << "\n";
    }

    return 0;
}

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)
    c[a] = 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):
from collections import Counter
import copy

N = int(input())

target_list = map(int, input().split())
trans_list = {}

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

check = []
check.append(Counter(target_list))
answer = []

for index, trans in trans_list.items():
    if trans[0] in check[index].keys():
        result = copy.deepcopy(check[index])
        if trans[1] in result:
            result[trans[1]] = result[trans[1]] + result.pop(trans[0])
        else:
            result[trans[1]] = result.pop(trans[0])
    else:
        result = copy.deepcopy(check[index])
    check.append(Counter(result))

for r in check:
    print(sum([x * y for x, y in r.items()]))


N = int(input())

target_list = map(int, input().split())
trans_list = {}

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

result = {}

for target in target_list:
    print(result)
    for key, trans in trans_list.items():
        if target == trans[0]:
            target = trans[1]

        if key in result:
            result[key] = result[key] + target
        else:
            result[key] = target


for r in result.values():
    print(r)


from collections import Counter

N = int(input())

target_list = list(map(int, input().split()))
check = Counter(target_list)
result = sum(target_list)


for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check:
        result = result + (check[B]) * (C - B)
        if C in check:
            check[C] = check[C] + check[B]
        else:
            check[C] = check[B]
        check[B] = 0
    print(result)


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

from collections import defaultdict
dic = defaultdict(int)
for a in A:
  dic[a] += 1 
  
ans = sum(A)
for i in range(q):  
  b,c = map(int,input().split())
  dic[c] += dic[b]
  diff = dic[c]*c-dic[b]*b
  ans += diff
  print(ans)  
  dic[b] = 0    

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

from collections import defaultdict
dic = defaultdict(int)
for a in A:
  dic[a] += 1 
  
ans = sum(A)
for i in range(q):  
  b,c = map(int,input().split())
  
  diff = dic[b]*c-dic[b]*b
  dic[c] += dic[b]
  ans += diff
  print(ans)  
  dic[b] = 0    

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):
# -*- coding: utf-8 -*-
n=int(input())
numlista=list(map(int,input().split()))

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

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

# -*- coding: utf-8 -*-
n=int(input())
numlista=map(int,input().split())

suma=0
for i in range(n):
  suma+=numlista[i]
#
#q=int(input())

#  b,c=int(input().split())
#  k=c-b
print(numlista)
print(suma)

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

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

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

Verdicts: Wrong Answer

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())
l=[int(i) for i in input().split()]
s=sum(l)
d={}
for i in range(n):
  if(l[i] in d):
    d[i]+=1
  else:
    d[i]=1
q=int(input())
for w in range(q):
  b,c=(int(i) for i in input().split())
  if(b in d):
    s-=((d[b]*b)+(d[b]*c))
    d[c]=d[b]
    d[b]=0
  print(s)

n=int(input())
l=[int(i) for i in input().split()]
s=sum(l)
d={}
for i in range(n):
  if(l[i] in d):
    d[l[i]]+=1
  else:
    d[l[i]]=1
q=int(input())
for w in range(q):
  b,c=(int(i) for i in input().split())
  if(b in d):
    s-=(d[b]*b)
    s+=(d[b]*c)
    if(c in d):
        d[c]+=d[b]
    else:
        d[c]=d[b]
    d[b]=0
  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):
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)


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)


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())
A = list(map(int,input().split()))
Q = int(input())

cnt_dict = {}


s = sum(A)

ans = 0

for item in A:
    if item not in cnt_dict:
        cnt_dict[item] = 0
    cnt_dict[item] += 1

for _ in range(Q):
    X,Y = map(int,input().split())

    if X not in cnt_dict:
        cnt_dict[X] = 0
    if Y not in cnt_dict:
        cnt_dict[Y] = 0

    s -= cnt_dict[X] * X
    s += cnt_dict[Y] * Y

    cnt_dict[X] += cnt_dict[Y]
    cnt_dict[Y] = 0

    print(s)








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

cnt_dict = {}


s = sum(A)

ans = 0

for item in A:
    if item not in cnt_dict:
        cnt_dict[item] = 0
    cnt_dict[item] += 1

for _ in range(Q):
    X,Y = map(int,input().split())

    if X not in cnt_dict:
        cnt_dict[X] = 0
    if Y not in cnt_dict:
        cnt_dict[Y] = 0

    s -= cnt_dict[X] * X
    s += cnt_dict[X] * Y

    cnt_dict[Y] += cnt_dict[X]
    cnt_dict[X] = 0


    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())
A = list(map(int, input().split()))

Q = int(input())

s = sum(A)

for i in range(Q):
    b, c = map(int, input().split())
    diff = c - A[b - 1]
    A[b - 1] = c
     diff
    print(s)


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

Q = int(input())

s = sum(A)

for i in range(Q):
    b, c = map(int, input().split())
    diff = c - A[b - 1]
    A[b - 1] = c
    s += diff
    print(s)


N = int(input())
A = list(map(int, input().split()))
ma = [0] * (100000 + 1)

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

Q = int(input())

s = sum(A)

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


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):
x = int(input())
ar = list(map(int, input().split()))
sum_val = sum(ar)

unique_val = dict()

for i in ar:
    if i in unique_val:
        unique_val[i] += 1
    else:
        unique_val[i] = 1

q = int(input())
while(q):
    a, b = map(int, input().split())
    if a in unique_val:
        value = (b-a)*unique_val[a]
        sum_val += value
        unique_val[b] = unique_val.pop(a)
        
    print(sum_val)
    q -= 1

print(sum_val)






x = int(input())
ar = list(map(int, input().split()))
sum_val = sum(ar)

unique_val = dict()

for i in ar:
    if i in unique_val:
        unique_val[i] += 1
    else:
        unique_val[i] = 1

q = int(input())
while(q):
    a, b = map(int, input().split())
    if a in unique_val:
        value = (b-a)*unique_val[a]
        sum_val += value
        if b in unique_val:
            unique_val[b] = unique_val[b] + unique_val.pop(a)
        else:
            unique_val[b] = unique_val.pop(a)
        print(unique_val)
        
    print(sum_val)
    q -= 1

print(sum_val)

x = int(input())
ar = list(map(int, input().split()))
sum_val = sum(ar)

unique_val = dict()

for i in ar:
    if i in unique_val:
        unique_val[i] += 1
    else:
        unique_val[i] = 1

q = int(input())
while(q):
    a, b = map(int, input().split())
    if a in unique_val:
        value = (b-a)*unique_val[a]
        sum_val += value
        if b in unique_val:
            unique_val[b] = unique_val[b] + unique_val.pop(a)
        else:
            unique_val[b] = unique_val.pop(a)
        
        
    print(sum_val)
    q -= 1






Verdicts: Wrong Answer

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


def main():
    n, *i = map(int, open(0).read().split())
    a = i[:n]　　＃数列Aのリスト
    _ = i[n]　　　＃Qのこと
    s = sum(a)　　＃数列Aの総和

    m = [0] * (10 ** 5 + 1)　　＃Aは1<A<10^5なのでラベル用リストを作成
    for x in a:　　　　　　　　　＃Aの個数をラベル化。リストmは個数を記録している
        m[x] += 1

    ans = []
    for b, c in zip(*[iter(i[n + 1:])] * 2):
        m[c] += m[b]　　　　　　＃ｃの個数にbの個数を足し算
        s += (c - b) * m[b]　　＃s:数列Aの総和に、(c-b)×(bの個数)を足し算
        m[b] = 0　　　　　　　　　＃bの個数はゼロに
        ans.append(s)　　　　　　＃リストansにSの変化を記録していく

    print("\n".join(map(str, ans)))


if __name__ == '__main__':
    main()

def main():
    n, *i = map(int, open(0).read().split())
    a = i[:n]
    _ = i[n]
    s = sum(a)

    m = [0] * (10 ** 5 + 1)
    for x in a:
        m[x] += 1

    ans = []
    for b, c in zip(*[iter(i[n + 1:])] * 2):
        m[c] += m[b]
        s += (c - b) * m[b]
        m[b] = 0
        ans.append(s)

    print("\n".join(map(str, ans)))

if __name__ == '__main__':
    main()

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

import collections
n=int(input())
a=list(map(int,input().split()))
q=int(input())
numl=collections.Counter(a)
s=sum(a)
for qq in range(q):
  x,y=map(int,input().split())
  s+=numl[x]*(y-x)
  print(s)
  numl[y]+=numl[x]
  numl[x]=0
  

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())
a = list(map(int, input().split()))
for i in range(n):
  dic[a[i]] += 1
q = int(input())
ans = [sum(a)]
for i in range(q):
  b, c = map(int, input().split())
  ans.append(ans[-1] + (c - b) * dic[b])
  dic[c] += dic[b]
  dic[b] = 0
for i in range(1, q + 1):
  print(ans[i])

k = [i for i in range(1, 10 ** 5 + 1)]
v = [0] * (10 ** 5)
dic = {key: val for key, val in zip(k, v)}
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  dic[a[i]] += 1
print(dic)
q = int(input())
ans = [sum(a)]
for i in range(q):
  b, c = map(int, input().split())
  ans.append(ans[-1] + (c - b) * dic[b])
  print(dic[b])
  print(dic[c])
  dic[c] += dic[b]
  dic[b] = 0
for i in range(1, q + 1):
  print(ans[i])

k = [i for i in range(1, 10 ** 5 + 1)]
v = [0] * (10 ** 5)
dic = {key: val for key, val in zip(k, v)}
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  dic[a[i]] += 1
q = int(input())
ans = [sum(a)]
for i in range(q):
  b, c = map(int, input().split())
  ans.append(ans[-1] + (c - b) * dic[b])
  dic[c] += dic[b]
  dic[b] = 0
for i in range(1, q + 1):
  print(ans[i])

Verdicts: 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=list(map(int,input().split()))
q=int(input())
for i in range(q):
  b,c = map(int,input().split())
  a=[c if i==b else i for i in a]
  print(a)
  print(sum(a))

from collections import Counter
n=input()
a=list(map(int,input().split()))
b=Counter(a)
n=int(input())
ans=sum(a)
for i in range(n):
    x,y=map(int,input().split())
    ans+=b[x]*(y-x)
    print(ans)
    b[y]+=b[x]
    b[x]=0

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

s = ','.join(map(str, a)) + ','
ans = []

for _ in range(q):
    b, c = map(str, input().split())
    s = s.replace(b+',', c+',')
    ans.append(s)
    
for i in ans:
    print(i[:-1])
    print(sum(int(str) for str in i[:-1].split(',')))
    

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

d = {}
t = 0
for i in a:
    if not i in d.keys():
        d[i] = 1
    else:
        d[i] += 1
    t += int(i)

q = int(input())

for _ in range(q):
    b, c = map(str, input().split())
    diff = 0
    if b in d.keys() and c in d.keys():
        diff = (int(c) - int(b)) * d[b]
        d[c] += d[b]
        d.pop(b)
    elif b in d.keys():
        diff = int(c) * d[b] - int(b) * d[b]
        d[c] = d[b]
        d.pop(b)
    t += diff
    print(t)
    

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

import collections as c

n = int(input())

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

q = int(input())

s = sum(a)

cnt = c.Counter(a)

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

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

from collections import Counter

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

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

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

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())
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(input())
index=np.array([i for i in range(10**5+1)])
List=np.array([0 for _ in range(10**5+1)])
for a in A:
    List[a]+=1
BList=np.array([0 for _ in range(10**5+1)])
for q in range(Q):
    B,C=map(int,input().split())
    BList[B]+=C-B
    print(np.sum(BList*List)+SUM)

import numpy as np
N=int(input())
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(input())
List=np.array([0 for _ in range(10**5+1)])
for a in A:
    List[a]+=1
for q in range(Q):
    B,C=map(int,input().split())
    SUM-=B*List[B]
    SUM+=C*List[B]
    List[C]+=List[B]
    List[B]=0
    print(SUM)

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())
a = list(map(int, input().split()))
q = int(input())
sums = sum(a)
d = {}

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

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

d = {}

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

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

n = int(input())
a = list(map(int, input().split()))
q = int(input())
sums = sum(a)
d = {}

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

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

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

a_c = Counter(a)



from collections import Counter
n = int(input())
a=list(map(int,input().split()))
q = int(input())
bc=[list(map(int,input().split())) for _ in range(q)]

a_c = Counter(a)
a_sum = sum(a)
for i in range(q):
    if bc[i][0] in a_c:
        a_sum += a_c[bc[i][0]] * (bc[i][1] - bc[i][0])
        if bc[i][1] in a_c:
            a_c[bc[i][1]] += a_c[bc[i][0]]
        else:
            a_c[bc[i][1]] = a_c[bc[i][0]]
        a_c[bc[i][0]] = 0
    else:
        a_sum = a_sum
    print(a_sum)


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())
listA=list(map(int, input().split()))
Q=int(input())

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

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


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

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

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


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


#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())
    if c[B]:
        s += (C-B)*c[B]
        c[C] += c[B]
        c[B] = 0

    print(s)


Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
# ABC171 E 

import itertools

n = int(input())
a_l = [list(format(int(x), "030b")) for x in input().split()]

for _d,_tp in enumerate(zip(*a_l)):
    if "1" not in _tp:
        continue
    if "0" not in _tp:
        continue
    else:
        _num = _tp.count("0")
        if _num % 2 == 1:
            for i in range(n):
                if a_l[i][_d] == "0":
                    a_l[i][_d] == "1"
                else:
                    a_l[i][_d] == "0"

print(*[int("".join(x), 2) for x in a_l])

# ABC171 E 

import itertools

n = int(input())
a_l = [list(format(int(x), "030b")) for x in input().split()]

for _d,_tp in enumerate(zip(*a_l)):
    if "1" not in _tp:
        continue
    if "0" not in _tp:
        continue
    else:
        _num = _tp.count("0")
        if _num % 2 == 1:
            for i in range(n):
                if a_l[i][_d] == "0":
                    a_l[i][_d] = "1"
                else:
                    a_l[i][_d] = "0"

print(*[int("".join(x), 2) for x in a_l])

Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
ans = 0
ans_list = []
for i in a:
  s = str(bin(i))
  s = s[2:]
  ans_list.append(int(s))
  ans += int(s)
z = []
for i in ans_list:
  z.append(ans - i)
f = []
for i in z:
  e = []
  for j in str(i):
    if int(j) % 2 == 0:
      j = 0
    if int(j) % 2 == 1:
      j = 1
    e.append(str(j))
  f.append(''.join(e))
h = []
for i in f:
  h.append(int(i, 2))
print(h)

n = int(input())
a = list(map(int, input().split()))
x = 0
for i in a:
  x ^= i
ans = [x^i for i in a]
print(' '.join(map(str, ans)))
  

Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

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

from itertools import combinations
  
perm = combinations(alist,len(alist)-1)

ans = []
for i in perm:
    xor = 0 
    for j in i:
        xor ^= j
    ans.append(xor)

print(" ".join(str(x) for x in ans))

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

s = 0
for i in alist:
    s ^= i

ans = []
for i in alist:
    ans.append(s ^ i)

print(" ".join(str(x) for x in ans))

Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
N = int(input())
a = [int(i) for i in input().split()]
ans = []
for x in a:
    s = '1'*(len(str(x)))
    ans.append(x^int(s))
print(*ans)

N = int(input())
a = [int(i) for i in input().split()]
ans = []
s = 0
for x in a:
    s = s^x
for x in a:
    ans.append(x^s)
print(*ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
import functools
N = int(input())
numbers = list(map(int,input().split()))
xor = ''
for i in range(len(numbers)):
    othersNumbers = numbers[:i] + numbers[i + 1:]
    currentXor = 0
    xor += str(functools.reduce(lambda x,y:x^y,othersNumbers)) + ' '
    
print(xor)

N = int(input())
numbers = list(map(int,input().split()))
xor = ''
for i in range(len(numbers)):
    othersNumbers = numbers[:i] + numbers[i + 1:]
    currentXor = 0
    for num in othersNumbers:
        currentXor ^= num
    xor += ' ' + str(currentXor) + ' '
print(xor)

N=int(input())
a=list(map(int,input().split()))
a_all=0
for i in range(N):
    a_all^=a[i]
ans=[]
for j in range(N):
    ans.append(a_all^a[j])
print(*ans)

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
allxor = 0
for i in range(n):
    allxor = allxor^a[i]
ans = ''
for i in range(n):
    ans= ans +str(allxor^a[i])+' '
print(ans)

n = int(input())
a = list(map(int, input().split()))
allxor = 0
ans = [0]*n
for i in range(n):
    allxor = allxor^a[i]
for i in range(n):
    ans[i] = allxor^a[i]
ansstr = " ".join(map(str,ans))
print(ansstr)

Verdicts: Time Limit Exceeded

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
    xor = 0
    for j in range(N):
        if i == j:
            xor ^= a[j]
    ans.append(xor)
print(*ans)

N = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(N):
    s ^= a[i]

ans = []
for i in range(N):
    ans.append(a[i] ^ s)
print(*ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
b = 0
for i in range(n):
    b ^= a[i]
ans = []
for i in range(n):
    ap = b ^ a[i]
    ans.append(ap)
print(*a)
print(*list(set(ans)))


n = int(input())
a = list(map(int, input().split()))
b = 0
for i in range(n):
    b ^= a[i]
ans = []
for i in range(n):
    ap = b ^ a[i]
    ans.append(ap)

print(*list(set(ans)))


n = int(input())
a = list(map(int, input().split()))
b = 0
for i in range(n):
    b ^= a[i]
ans = []
for i in range(n):
    ap = b ^ a[i]
    ans.append(ap)

print(*ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

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

xor_a = 0
for i in range(n):
  xor_a ^= a[i]

print(xor_a)

ans = []
for i in range(n):
  ans.append(a[i] ^ xor_a)

print(*ans)


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

xor_a = 0
for i in range(n):
  xor_a ^= a[i]

#print(xor_a)

ans = []
for i in range(n):
  ans.append(a[i] ^ xor_a)

print(*ans)


Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
def xor_operate(a_list):
    result = 0
    for a in a_list:
        result ^= int(a)
    return str(result)



if __name__ == "__main__":
    N = input()
    a_list = input()

    a_list = a_list.split(" ")

    i_list = []
    for i in range(len(a_list)):
        r_list = a_list[:i]+a_list[i+1:]
        i_list.append(xor_operate(r_list))
    return " ".join(i_list)
    


        



def xor_operate(a_list):
    result = 0
    for a in a_list:
        result ^= int(a)
    return result



if __name__ == "__main__":
    N = input()
    a_list = input()

    a_list = a_list.split(" ")

    bit_value = xor_operate(a_list)

    i_list = []
    for a in a_list:
        i_list.append(str(bit_value ^ int(a)))
    print(" ".join(i_list))
    


        



Verdicts: Runtime Error

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
N = int(input())
a = list(map(int, input().split()))
ans = []
s = 0
for i in range(N):
    s = s ^ a[i]

for i in range(N):
    tmp = s ^ a[i]
    ans.append(tmp)
    
print(ans)

N = int(input())
a = list(map(int, input().split()))
ans = []
s = 0
for i in range(N):
    s = s ^ a[i]

for i in range(N):
    tmp = s ^ a[i]
    ans.append(str(tmp))
    
ans = ' '.join(ans)    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
def main():
    _ = int(input())
    a = tuple(map(int, input().split()))

    res = 0
    for i in a:
        res ^= i
    ans = [res ^ j for j in a]
    for k in ans:
        print(ans)


if __name__ == "__main__":
    main()

def main():
    _ = int(input())
    a = tuple(map(int, input().split()))

    res = 0
    for i in a:
        res ^= i
    ans = tuple(res ^ i for i in a)
    print(*ans)


if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Accepted
Problem: There are N Snuke Cats numbered 1, 2, \ldots, N, where N is **even**.  Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.  Recently, they learned the operation called xor (exclusive OR).  What is xor?  For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:    * When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.   For example, 3~\textrm{xor}~5 = 6.  They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.  We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Submission attempts (in order):
N = int(input())
AS = list(map(int, input().split()))
print(*AS, sep=" ")


from functools import reduce
from operator import xor

N = int(input())
AS = list(map(int, input().split()))
total = reduce(xor, AS)
print(*[a ^ total for a in AS])


Verdicts: Wrong Answer

Accepted