problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p02630 | u570039786 | 2,000 | 1,048,576 | 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. | ['import numpy as np\nimport sys\nimport bisect\n\nreadline = sys.stdin.readline\n\n\nN = int(input())\nA = np.array(readline().split(), np.int64)\nA_sort = np.sort(A)\nQ = int(input())\nBC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)\n# BC[N][0,1]\n\n\nfor q in range(Q):\n # A = [BC[q][1] if x==BC[q][0] else x for x in A]\n \n # b = np.copy(A)\n\n # print(sum(A))\n print(A)\n\n', 'import numpy as np\nimport sys\nimport bisect\n\nreadline = sys.stdin.readline\n\n\nN = int(input())\nA = np.array(readline().split(), np.int64)\nA_sort = np.sort(A)\nQ = int(input())\nBC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)\n# BC[N][0,1]\n\n\nfor q in range(Q):\n # A = [BC[q][1] if x==BC[q][0] else x for x in A]\n \n # b = np.copy(A)\n\n print(sum(A))\n\n', 'import numpy as np\nimport sys\n\nreadline = sys.stdin.readline\n\nN = int(input())\nA = np.array(readline().split(), np.int64)\nQ = int(input())\nBC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)\n# BC[N][0,1]\n\nprint(N)\n\n"""\nfor q in range(Q):\n A = [BC[q][1] if x==BC[q][0] else x for x in A]\n print(sum(A))\n """', 'import numpy as np\nimport sys\nimport bisect\n\nreadline = sys.stdin.readline\n\n\nN = int(input())\nA = np.array(readline().split(), np.int64)\nA_sort = np.sort(A)\nQ = int(input())\nBC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)\n# BC[N][0,1]\n\n\nfor q in range(Q):\n # A = [BC[q][1] if x==BC[q][0] else x for x in A]\n \n # b = np.copy(A)\n\n # print(sum(A))\n print(N)\n\n', 'import numpy as np\nimport sys\nfrom bisect import bisect_right, bisect_left\n\nreadline = sys.stdin.readline\n\n\nN = int(input())\nA = np.array(readline().split(), np.int64)\nnum_array = np.zeros(10**5, np.int64)\nfor n in A:\n num_array[n-1] += 1\n\n# A_sort = np.sort(A)\nA_sum = sum(A)\nQ = int(input())\nBC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)\n# BC[N][0,1]\n\n\nfor q in range(Q):\n # A = [BC[q][1] if x==BC[q][0] else x for x in A]\n \n \n\n \n\n plus_num = BC[q][1] - BC[q][0]\n plus_multiple = num_array[BC[q][0] - 1]\n \n num_array[BC[q][1]- 1] += num_array[BC[q][0] - 1]\n num_array[BC[q][0] - 1] = 0\n\n A_sum = A_sum + plus_num*plus_multiple\n print(A_sum)\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s061356421', 's160483226', 's173119993', 's910245378', 's508102396'] | [45056.0, 44908.0, 44220.0, 44908.0, 44576.0] | [2209.0, 2207.0, 298.0, 340.0, 805.0] | [591, 576, 347, 591, 1291] |
p02630 | u572179584 | 2,000 | 1,048,576 | 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. | ['n = int(input())\nl = list(map(int, input()))\nq = int(input())\ncount = 0\n\nfor i in range(q):\n\tcount = 0\n\tb, c = map(int, input().split())\n\tfor a in l:\n\t\tif a == b:\n\t\t\tl[count] = c\n\t\tprint(sum(l))\n\t\tcount++\n', 'import collections\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nnum = collections.Counter(A)\n\nS = sum(A)\nslist = []\n\nfor i in range(Q):\n\tB, C = map(int, input().split())\n\tnumb = num[B]\n\tS += (C - B) * numb\n\tnum[C] += numb\n\tnum[B] = 0\n\tslist.append(S)\n\n[print(i) for i in slist]'] | ['Runtime Error', 'Accepted'] | ['s092000230', 's102143252'] | [8724.0, 27164.0] | [27.0, 356.0] | [205, 304] |
p02630 | u580273604 | 2,000 | 1,048,576 | 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. | ['import numpy as np\nN=int(input())\nA=list(map(int,input().split()))\nA=sorted(A)\nQ=int(input())\nB=[0]*Q;C=[0]*Q\nfor i in range(Q):\n B[i],C[i]=map(int,input().split())\n#print(A)\nD=[0]*10**5;W=[0]*10**5\nfor i in range(10**5):\n D[i]=A.count(i+1)\n W[i]=i+1\n\nfor i in range(Q):\n D[C[i]-1]+=D[B[i]-1]\n D[B[i]-1]=0\n print(int(np.average(D, weights=W)*10**5*(10**5+1)//2))', 'import collections\nN=int(input())\nA=list(map(int,input().split()))\nA=sorted(A)\nQ=int(input())\nB=[0]*Q;C=[0]*Q\nfor i in range(Q):\n B[i],C[i]=map(int,input().split())\n\nD = collections.Counter(A)\ns=sum(A)\nfor i in range(Q):\n s=s-B[i]*D[B[i]]\n D[C[i]]+=D[B[i]]\n s=s+C[i]*D[B[i]]\n D[B[i]]=0\n print(s)'] | ['Wrong Answer', 'Accepted'] | ['s226662127', 's815493654'] | [40852.0, 30068.0] | [2206.0, 399.0] | [374, 301] |
p02630 | u585963734 | 2,000 | 1,048,576 | 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. | ['import numpy as np\n\nN=int(input())\nA=list(map(int, input().split()))\nQ=int(input())\nB,C=map(int, input().split())\nrep=[i for i, x in enumerate(A) if x == B]\nfor i in range(len(rep)):\n A[rep[i]]=C\nans=np.cumsum(A)\nprint(ans[1])\n\nfor _ in range(Q-1):\n B,C=map(int, input().split())\n rep=[i for i, x in enumerate(A) if x == B]\n for i in range(len(rep)):\n A[rep[i]]=C\n ans+=(C-B)*len(rep)\n print(ans[1])', 'mod=pow(10,5)+2\nN=int(input())\nnum=[0]*mod\nans=0\nA=list(map(int, input().split()))\nfor i in range(N):\n num[A[i]]+=1\n ans+=A[i]\nQ=int(input())\nfor i in range(Q):\n B,C=map(int, input().split())\n cnt=num[B]\n num[C]+=num[B]\n num[B]=0\n ans+=(C-B)*cnt\n print(ans)'] | ['Runtime Error', 'Accepted'] | ['s217023354', 's100281029'] | [38600.0, 21832.0] | [2206.0, 492.0] | [424, 281] |
p02630 | u586662847 | 2,000 | 1,048,576 | 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. | ['def resolve():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n\n C = Counter(A)\n ANS = 0\n for i in C:\n ANS += i * C[i]\n\n for _ in range(Q):\n B, X = map(int, input().split())\n ANS += X * C[B]\n C[X] += C[B]\n\n ANS -= B * C[B]\n del(C[B])\n print(ANS)\n\nresolve()', 'from collections import Counter\n\n\ndef resolve():\n N = int(input())\n A = list(input().split())\n Q = int(input())\n\n C = Counter(A)\n ANS = 0\n for i in C:\n ANS += i * C[i]\n\n for _ in range(Q):\n B, X = map(int, input().split())\n ANS += X * C[B]\n C[X] += C[B]\n\n ANS -= B * C[B]\n del(C[B])\n print(ANS)\n\nresolve()', 'from collections import Counter\n\n\ndef resolve():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n\n C = Counter(A)\n ANS = 0\n for i in C:\n ANS += i * C[i]\n\n for _ in range(Q):\n B, X = map(int, input().split())\n ANS += X * C[B]\n C[X] += C[B]\n\n ANS -= B * C[B]\n del(C[B])\n print(ANS)\n\nresolve()'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s446494142', 's823601600', 's424545645'] | [21024.0, 21312.0, 24252.0] | [49.0, 53.0, 590.0] | [351, 375, 385] |
p02630 | u593019570 | 2,000 | 1,048,576 | 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. | ['n = int(input())\n\na = input()\n#print(a)\nq = int(input())\n\nb = []\nfor _ in range(q):\n b.append(input().split())\n#print(b)\nfor i in range(q):\n a.replace(b[i][0],b[i][1],100000)\n c = 0\n d = a.split(" ")\n #print(d)\n for j in range(len(d)):\n c += int(d[j])\n print(c)\n', 'n = int(input())\n\na = list(map(int,input().split()))\n#print(a)\nq = int(input())\nz = [0 for i in range(100001)]\nfor i in range(len(a)):\n z[a[i]] += 1\nx = sum(a)\nb = []\nfor _ in range(q):\n b.append(list(map(int,input().split())))\n#print(b)\n\n\nfor i in range(q):\n x += (b[i][1] - b[i][0]) * z[b[i][0]]\n z[b[i][1]] += z[b[i][0]]\n z[b[i][0]] = 0\n print(x)'] | ['Wrong Answer', 'Accepted'] | ['s170407238', 's686861004'] | [54168.0, 32920.0] | [2207.0, 382.0] | [290, 367] |
p02630 | u596681540 | 2,000 | 1,048,576 | 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. | ["n = int(input())\n\na_list = [int(i) for i in input().split()]\nq = int(input())\n\nary = [0 for _ in range((10 ** 5)+1)]\n\nfor i in a_list:\n ary[i] += i\n\n\nfor _ in range(q):\n b, c = map(int, input().split())\n print('BC', b, c)\n ary[c] += (ary[b]/b)*c\n ary[b] = 0\n ans = int(sum(ary))\n print(ans)\n", 'n = int(input())\n\na_list = [int(i) for i in input().split()]\nq = int(input())\n\nary = [0 for _ in range((10**5) + 1)]\n\nfor i in a_list:\n ary[i] += 1\n\nans = []\n\nf_ans = sum(a_list)\nfor _ in range(q):\n b, c = map(int, input().split())\n f_ans += (c-b)*ary[b]\n ary[c] += ary[b]\n ary[b] = 0\n\n ans.append(f_ans)\n\nfor a in ans:\n print(a)\n'] | ['Wrong Answer', 'Accepted'] | ['s418835217', 's518812892'] | [20632.0, 20496.0] | [2206.0, 311.0] | [312, 351] |
p02630 | u596743351 | 2,000 | 1,048,576 | 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. | ['K = int(input())\nS = len(input())\n\nM = 10**9 + 7\n\nF = [1]\nIF = [1]\nfor i in range(1, K + S + 1):\n F.append((F[-1] * i) % M)\n IF.append((IF[-1] * pow(i, M - 2, M)) % M)\n\ndef nCr(n, r):\n return (F[n] * IF[r] * IF[n-r]) % M\n\nans = 0\nfor i in range(K + 1):\n ans = (ans + nCr(i + S - 1, S - 1) * pow(25, i, M) * pow(26, K - i, M)) % M\nprint(ans)\n', 'N = int(input())\nA = list(map(int, input().split()))\ncnt = [0] * (100001)\nans = sum(A)\nfor a in A:\n cnt[a] += 1\nQ = int(input())\nfor _ in range(Q):\n b, c = map(int, input().split())\n ans += (c - b) * cnt[b]\n cnt[c] += cnt[b]\n cnt[b] = 0\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s654513424', 's953449822'] | [59740.0, 20980.0] | [2207.0, 482.0] | [353, 267] |
p02630 | u602773379 | 2,000 | 1,048,576 | 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. | ['A=[0]*(10**5+1)\nfor i in a:\n\tA[i]+=1\n\nfor bc in BC:\n\tdiff= bc[1]-bc[0]\n\tSUM+=diff*A[bc[0]]\n\tA[bc[1]]+=A[bc[0]]\n\tA[bc[0]]-=A[bc[0]]\n\tprint(SUM)', '\ndef input_array():\n\treturn list(map(int,input().split()))\n\nn=int(input())\na=input_array()\nq=int(input())\nBC=[input_array() for _ in range(q)]\nSUM=sum(a)\n\nA=[0]*(10**5+1)\nfor i in a:\n\tA[i]+=1\n\nfor bc in BC:\n\tdiff= bc[1]-bc[0]\n\tSUM+=diff*A[bc[0]]\n\tA[bc[1]]+=A[bc[0]]\n\tA[bc[0]]-=A[bc[0]]\n\tprint(SUM)'] | ['Runtime Error', 'Accepted'] | ['s064445328', 's918470666'] | [9392.0, 32128.0] | [26.0, 343.0] | [142, 336] |
p02630 | u606374450 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\na = [0] * (10 ** 5 + 1)\nans = sum(A)\n\nfor i in range(N):\n a[A[i]] += 1\n\nfor i in range(Q):\n B, C = map(int, input().split())\n a[C] += a[B]\n a[B] = 0\n ans += a[B] * (C - B)\n print(ans)\n', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\na = [0] * (10 ** 5 + 1)\nans = sum(A)\n\nfor i in range(N):\n a[A[i]] += 1\n\nfor i in range(Q):\n B, C = map(int, input().split())\n ans += a[B] * (C - B)\n a[C] += a[B]\n a[B] = 0\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s921812575', 's259009887'] | [21056.0, 21128.0] | [470.0, 469.0] | [273, 273] |
p02630 | u608007704 | 2,000 | 1,048,576 | 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. | ['import numpy as np\n\nN=int(input())\nA=list(map(int,input().split()))\nAdic={}\nfor i in A:\n if Adic.get(i)==None:\n Adic[i]=1\n else:\n Adic[i]+=1\nQ=int(input())\nope=[]\n\nfor i in range(Q):\n ope.append(list(map(int,input().split())))\n\nA=np.array(A)\n\nsum=0\nfor key,value in Adic.items():\n sum+=key*value\nfor b,c in ope:\n if Adic.get(b)!=None:\n if Adic.get(c)==None:Adic[c]=0\n sum-=b*Adic[b]\n Adic[c]+=Adic.pop(b)\n sum+=c*Adic[c]\n print(sum)\n else:\n print(sum)', 'import numpy as np\n\nN=int(input())\nA=list(map(int,input().split()))\nAdic={}\nfor i in A:\n if Adic.get(i)==None:\n Adic[i]=1\n else:\n Adic[i]+=1\nQ=int(input())\nope=[]\n\nfor i in range(Q):\n ope.append(list(map(int,input().split())))\n\nA=np.array(A)\n\nsum=0\nfor key,value in Adic.items():\n sum+=key*value\nfor b,c in ope:\n if Adic.get(b)!=None:\n if Adic.get(c)==None:Adic[c]=0\n sum=sum-b*Adic[b]+c*Adic[b]\n Adic[c]+=Adic.pop(b)\n print(sum)\n else:\n print(sum)'] | ['Wrong Answer', 'Accepted'] | ['s431173738', 's410765896'] | [53960.0, 54044.0] | [457.0, 475.0] | [481, 475] |
p02630 | u617953889 | 2,000 | 1,048,576 | 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. | ['#D more faster method than above see it ..........\nl = lambda : list(map(int,input().split().strip()))\nn = int(input())\na = l\nt = [0]*(10**5+1)\ns = 0\nfor i in a:\n s += i\n t[i] += 1\nq = int(input())\nfor _ in range(q):\n b,c = l\n s += (c-b)*t[b]\n t[c] += t[b]\n t[b] = 0\n print(s)\n', '#D\nfrom collections import defaultdict\nn = int(input())\na = list(map(int,input().split()))\nmp = defaultdict(int)\nfor i in a:\n mp[i] += 1\nq = int(input())\nfor _ in range(q):\n print(mp)\n s = 0 \n b,c=map(int,input().split())\n if c in mp:\n mp[c] = mp[c]+mp[b]\n mp.pop(b)\n elif b in mp:\n mp[c] = mp.pop(b)\n \n for i in mp:\n s += (mp[i])*i\n print(s)\n ', '#D more faster method than above see it ..........\nl = lambda : list(map(int,input().strip().split()))\nn = int(input())\na = l()\nt = [0]*(10**5+1)\ns = 0\nfor i in a:\n s += i\n t[i] += 1\nq = int(input())\nfor _ in range(q):\n b,c = l()\n s += (c-b)*t[b]\n t[c] += t[b]\n t[b] = 0\n print(s)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s467373278', 's783281467', 's517940461'] | [9548.0, 89628.0, 20732.0] | [33.0, 2345.0, 523.0] | [328, 408, 332] |
p02630 | u618363477 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nfor i in range(Q):\n B, C = map(int, input().split())\n for i in range(N):\n if A[i] == B:\n A[i] = C\n print(sum(A))\n', 'from collections import Counter\n \nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\n \ncnt = Counter(a)\n \ns = sum(a)\n \nfor i in range(q):\n\tb, c = map(int, input().split())\n\ts = s - b*cnt[b]\n\ts = s + c*cnt[b]\n\tcnt[c] += cnt[b]\n\tcnt[b] = 0\n\tprint(s)'] | ['Wrong Answer', 'Accepted'] | ['s833029611', 's771478424'] | [20836.0, 24016.0] | [2206.0, 591.0] | [218, 266] |
p02630 | u618532828 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nB=[]\nC=[]\n\nfor _ in range(q):\n bi, ci = list(map(int, input().split()))\n B.append(bi)\n C.append(ci)\n\ndic = {}\nfor i in A:\n dic[i] = dic.get(i,0) + 1\n\nsum = sum(A)\n\nfor i in range(Q):\n sum += dic[B[i]] * (C[i] -B[i])\n dic[C[i]] += dic[B[i]]\n dic[B[i]] = 0\n print(sum)', 'N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nB=[]\nC=[]\n\nfor _ in range(Q):\n bi, ci = list(map(int, input().split()))\n B.append(bi)\n C.append(ci)\n\ndic = {}\nfor i in A:\n dic[i] = dic.get(i,0) + 1\n\nsum = sum(A)\n\nfor i in range(Q):\n sum += dic.get(B[i], 0) * (C[i] -B[i])\n dic[C[i]] = dic.get(C[i], 0) + dic.get(B[i], 0)\n dic[B[i]] = dic.get(B[i], 0)\n dic[B[i]] = 0\n print(sum)'] | ['Runtime Error', 'Accepted'] | ['s148714632', 's917447007'] | [20960.0, 29788.0] | [49.0, 404.0] | [359, 424] |
p02630 | u629350026 | 2,000 | 1,048,576 | 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. | ['n=int(input())\na=list(map(int,input().split()))\nq=int(input())\ntemp=sum(a)\nimport collections\nca=collections.Counter(a)\nprint(ca)\nfor i in range(q):\n b,c=map(int,input().split())\n ba=ca[b]\n temp=temp-b*ba+c*ba\n ca[b]=ca[b]-ba\n ca[c]=ca[c]+ba\n', 'n=int(input())\na=list(map(int,input().split()))\nq=int(input())\ntemp=sum(a)\nimport collections\nca=collections.Counter(a)\nfor i in range(q):\n b,c=map(int,input().split())\n ba=ca[b]\n temp=temp-b*ba+c*ba\n print(temp)\n ca[b]=ca[b]-ba\n ca[c]=ca[c]+ba\n'] | ['Wrong Answer', 'Accepted'] | ['s588779164', 's898668935'] | [25260.0, 24024.0] | [344.0, 591.0] | [247, 251] |
p02630 | u633203155 | 2,000 | 1,048,576 | 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. | ["import collections\n\ndef calc_sum(c):\n sum_val = 0\n for key, val in c.items():\n sum_val += key * val\n return sum_val\n\nN = int(input())\narr = list(map(int, input().split()))\nQ = int(input())\n\nactions = []\n\nfor i in range(Q):\n B, C = map(int, input().split())\n actions.append({'B':B, 'C':C})\n\nc = collections.Counter(arr)\nsum_val = calc_sum(c)\n\nfor i in range(Q):\n B = actions[i]['B']\n C = actions[i]['C']\n if B in c:\n c[C] += c[B]\n sum_val += c[C] * C - c[B] * B\n c.pop(B)\n\n print(sum_val)", "import collections\n\ndef calc_sum(c):\n sum_val = 0\n for key, val in c.items():\n sum_val += key * val\n return sum_val\n\nN = int(input())\narr = list(map(int, input().split()))\nQ = int(input())\n\nactions = []\n\nfor i in range(Q):\n B, C = map(int, input().split())\n actions.append({'B':B, 'C':C})\n\nc = collections.Counter(arr)\nsum_val = calc_sum(c)\n\nfor i in range(Q):\n B = actions[i]['B']\n C = actions[i]['C']\n if B in c:\n c[C] += c[B]\n sum_val += c[B] * C - c[B] * B\n c.pop(B)\n\n print(sum_val)"] | ['Wrong Answer', 'Accepted'] | ['s294168996', 's077960755'] | [50160.0, 50144.0] | [417.0, 419.0] | [542, 542] |
p02630 | u638456847 | 2,000 | 1,048,576 | 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. | ['import sys\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\n\ndef main():\n N = int(readline())\n A = [int(i) for i in readline().split()]\n\n d = dict()\n for a in A:\n if a in d:\n d[a] += 1\n else:\n d[a] = 1\n\n total = sum(A)\n ans = []\n Q = int(readline())\n for _ in range(Q):\n b, c = map(int, readline().split())\n if b in d:\n if c in d:\n d[c] += d[b]\n else:\n d[c] = d[b]\n\n total += (c - b) * d[b]\n ans.append(total)\n d.pop(b)\n\n else:\n ans.append(total)\n\n print("\\n".join(map(str, ans)))\n\n\nif __name__ == "__main__":\n main()\n', 'import sys\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\n\ndef main():\n N = int(readline())\n A = [int(i) for i in readline().split()]\n\n d = dict()\n for a in A:\n if a in d:\n d[a] += 1\n else:\n d[a] = 1\n\n total = sum(A)\n ans = []\n Q = int(readline())\n for _ in range(Q):\n b, c = map(int, readline().split())\n if b in d:\n if c in d:\n d[c] += d[b]\n else:\n d[c] = d[b]\n\n total += (c - b) * d[b]\n ans.append(total)\n d.pop(b)\n\n else:\n ans.append(total)\n\n print("\\n".join(map(str, ans)))\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s484263595', 's755938507'] | [147480.0, 26624.0] | [3597.0, 177.0] | [740, 736] |
p02630 | u647087591 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int, input().split()))\nq = int(input())\n\nl = {}\nans = []\nfor e in a:\n l[e] = l[e] + 1 if l.get(e) else 1\n\nsum = 0\nfor k, v in l.items():\n sum += k * v\n\nfor _ in range(q):\n b, c = map(int, input().split())\n if b in l:\n sum += (c - b) * l[b]\n ans.append(sum)\n\nfor sum in ans:\n print(sum)', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\n\nl = [0] * 100001\nfor i in a:\n l[i] += 1\n\ns = sum(a)\n\nfor _ in range(q):\n b, c = map(int, input().split())\n s += (c - b) * l[b]\n l[c] += l[b]\n l[b] = 0\n print(s)\n'] | ['Wrong Answer', 'Accepted'] | ['s533286505', 's286683585'] | [21020.0, 20840.0] | [311.0, 476.0] | [340, 250] |
p02630 | u653931433 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nB = []\nC = []\n \nfor _ in range(Q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n \nS = sum(A)\nmemory = [0] * 100001\nfor num in A:\n memory[num] += 1\nfor i in range(Q):\n S = S + memory[B[i]] * (C[i]- B[i])\n memory[C[i]] = memory[B[i]]\n memory[B[i]] = 0\n print(S)\n ', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nB = []\nC = []\n \nfor _ in range(Q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n \nS = sum(A)\nmemory = [0] * 100001\nfor num in A:\n memory[num] += 1\nfor i in range(Q):\n S = S + memory[B[i]] * (C[i]- B[i])\n print(S)\n memory[C[i]] += memory[B[i]]\n memory[B[i]] = 0\n \n '] | ['Wrong Answer', 'Accepted'] | ['s855017473', 's218150234'] | [22260.0, 22080.0] | [326.0, 314.0] | [362, 366] |
p02630 | u655048024 | 2,000 | 1,048,576 | 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. | ['N = int(input())\na = list(map(int,input()))\nq = int(input())\nfor i in range(q):\n summ = 0\n b,c = map(int,input().split())\n for i in range(N):\n if(a[i]==b):\n a[i] = c\n summ += a[i]\n print(summ)\n', 'N = int(input())\na = list(map(int,input().split()))\nq = int(input())\nnum = []\nsumm = 0\nfor i in range(10**5):\n num.append(0)\nfor i in range(N):\n num[a[i]-1] += 1\n summ += 1\nfor i in range(q):\n b,c = map(int,input().split())\n summ += (c-b)*a[b-1]\n a[c-1] += a[b-1]\n a[b-1] = 0\n print(summ)\n', 'N = int(input())\na = list(map(int,input().split()))\nq = int(input())\nnum = []\nsumm = 0\nfor i in range(10**5):\n num.append(0)\nfor i in range(N):\n num[a[i]-1] += 1\n summ += a[i]\nfor i in range(q):\n b,c = map(int,input().split())\n summ += (c-b)*a[b-1]\n a[c-1] += a[b-1]\n a[b-1] = 0\n print(summ)\n', 'N = int(input())\na = list(map(int,input().split()))\nq = int(input())\nnum = []\nsumm = 0\nfor i in range(10**5):\n num.append(0)\nfor i in range(N):\n num[a[i]-1] += 1\n summ += a[i]\nfor i in range(q):\n b,c = map(int,input().split())\n summ += (c-b)*num[b-1]\n num[c-1] += num[b-1]\n num[b-1] = 0\n print(summ)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s125085095', 's420673665', 's869699229', 's014444958'] | [10600.0, 20896.0, 21128.0, 20940.0] | [441.0, 518.0, 556.0, 510.0] | [208, 297, 300, 308] |
p02630 | u657786757 | 2,000 | 1,048,576 | 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. | ['import sys\nimport numpy as np\nimport math \nimport collections\nfrom collections import deque\nfrom collections import defaultdict\nfrom copy import deepcopy\nfrom itertools import accumulate \ndef input(): return sys.stdin.readline().rstrip()\nfrom functools import lru_cache \n\ndef main():\n n = int(sys.stdin.readline())\n a = list(map(int,sys.stdin.readline().split()))\n q = int(sys.stdin.readline())\n queue = [list(map(int,sys.stdin.readline().split())) for _ in range(q)]\n count = collections.Counter(a)\n print(count)\n print(list(count))\n for b, c in queue:\n if b in count:\n if c in count:\n count[c] += count[b]\n del count[b]\n else:\n count[c] = count[b]\n del count[b]\n ans = 0\n for k in count:\n ans += k * count[k]\n print(ans) \n \n \n return 0\n\nif __name__ == "__main__":\n main()', 'import sys\nimport numpy as np\nimport math \nimport collections\nfrom collections import deque\nfrom collections import defaultdict\nfrom copy import deepcopy\nfrom itertools import accumulate \ndef input(): return sys.stdin.readline().rstrip()\nfrom functools import lru_cache \n\ndef main():\n n = int(sys.stdin.readline())\n a = list(map(int,sys.stdin.readline().split()))\n q = int(sys.stdin.readline())\n queue = [list(map(int,sys.stdin.readline().split())) for _ in range(q)]\n count = collections.Counter(a)\n #print(count)\n #print(list(count))\n ans = 0\n for k in count:\n ans += k * count[k]\n for b, c in queue:\n if b in count:\n if c in count:\n count[c] += count[b]\n ans += (c - b) * count[b]\n del count[b]\n else:\n count[c] = count[b]\n ans += (c - b) * count[b]\n\n del count[b]\n print(ans)\n \n \n return 0\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s035006862', 's521573743'] | [60444.0, 55036.0] | [2207.0, 352.0] | [1002, 1076] |
p02630 | u658915215 | 2,000 | 1,048,576 | 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. | ['N=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\n\nbase=sum(A)\n\nfrom collections import Counter\n\nad=Counter(A)\n\nfor _ in range(Q):\n b,c=map(int.input().split())\n if ad[b]!=0:\n base+=(c-b)*ad[b]\n ad[c]+=ad[b]\n ad[b]=0\n print(base)', 'from collections import Counter\nn = int(input())\nA = list(map(int, input().split()))\nC = Counter(A)\nans = sum(A)\nq = int(input())\nfor i in range(q):\n b, c = map(int, input().split())\n if c not in C.keys():\n C[c] = 0\n if b in C.keys():\n ans += (c-b)*C[b]\n C[c] += C[b]\n C[b] = 0\n print(ans)\n '] | ['Runtime Error', 'Accepted'] | ['s333006222', 's141926884'] | [20864.0, 21396.0] | [60.0, 573.0] | [272, 334] |
p02630 | u662430503 | 2,000 | 1,048,576 | 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. | ['def main():\n n = int(input())\n a = list(map(int,input().split()))\n q = int(input())\n for _ in range(q):\n b, c = map(int, input().split())\n sum=0\n for i in range(0,n):\n if(a[i]==b):\n a[i]=c\n sum+=a[i]\n print(sum)\nmain()', 'import collections\ndef main():\n n = int(input())\n a = list(map(int,input().split()))\n ans=sum(a)\n counter = collections.Counter(a)\n q = int(input())\n for _ in range(q):\n b, c = map(int, input().split())\n num=counter[b]\n counter[b]=0\n counter[c]+=num\n ans+=(c-b)*num\n print(ans)\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s354814645', 's103918117'] | [20540.0, 24004.0] | [2206.0, 541.0] | [253, 308] |
p02630 | u664015993 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nd = dict()\ns = 0\nfor num in a:\n if num in d:\n d[num] += 1\n else:\n d[num] = 1\n s += num\nfor i in range(q):\n B, C = list(map(int, input().split()))\n if B in d:\n if C in d:\n d[C] += d[B]\n else:\n d[C] = d[B]\n s += (C-B)*d[B]\n s[B] = 0\n print(s)', 'n = int(input())\na = input().split()\nq = int(input())\nd = dict()\ns = 0\nfor num in a:\n if num in d:\n d[num] += 1\n else:\n d[num] = 1\n s += int(num)\nfor i in range(q):\n B, C = input().split()\n if B in d:\n if C in d:\n d[C] += d[B]\n else:\n d[C] = d[B]\n s += (int(C)-int(B))*d[B]\n d[B] = 0\n print(s)\n'] | ['Runtime Error', 'Accepted'] | ['s897426329', 's840812421'] | [20580.0, 20956.0] | [73.0, 522.0] | [344, 328] |
p02630 | u674588203 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\n\nN=int(input())\nA=list(map(int,input().split()))\nc=Counter(A)\ncommons=c.most_common()\n\nans=0\n\ndic={}\nfor common in commons:\n dic[common[0]]=common[1]\n ans+=common[0]*common[1]\n# print(dic)\n# print(ans)\n\nQ=int(input())\nfor i in range(Q):\n b,c=map(int,input().split())\n ans+=(c-b)*dic[b]\n dic[b]=0\n dic[c]+=dic[b]\n # print(dic)\n print(ans)\n', 'from collections import Counter\n\nN=int(input())\nA=list(map(int,input().split()))\nc=Counter(A)\ncommons=c.most_common()\n\nans=0\n\ndic={}\nfor common in commons:\n dic[common[0]]=common[1]\n ans+=common[0]*common[1]\n# print(dic)\n# print(ans)\n\nQ=int(input())\nfor i in range(Q):\n b,c=map(int,input().split())\n if b not in dic:\n print(ans)\n continue\n else:\n pass\n if c not in dic:\n ans+=(c-b)*dic[b]\n print(ans)\n dic[c]=dic[b]\n dic[b]=0\n continue\n else:\n pass\n ans+=(c-b)*dic[b]\n dic[c]+=dic[b]\n dic[b]=0\n print(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s178305841', 's536007772'] | [25160.0, 25404.0] | [87.0, 553.0] | [394, 602] |
p02630 | u686036872 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\n\nN = int(input())\n\nA = list(map(int, input().split()))\nc = Counter(A)\nS = sum(A)\n\nQ = int(input())\nfor _ in range(Q):\n x, y = map(int, input().split())\n S += (c[x]*(y-x))\n print(S)\n c[y] = c[x]\n c[x] = 0', 'from collections import Counter\n\nN = int(input())\n\nA = list(map(int, input().split()))\nc = Counter(A)\nS = sum(A)\n\nQ = int(input())\nfor _ in range(Q):\n x, y = map(int, input().split())\n S += (c[x]*(y-x))\n print(S)', 'from collections import Counter\n\nN = int(input())\n\nA = list(map(int, input().split()))\nc = Counter(A)\nS = sum(A)\n\nQ = int(input())\nfor _ in range(Q):\n x, y = map(int, input().split())\n S += (c[x]*(y-x))\n print(S)\n c[y] += c[x]\n c[x] = 0'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s427593900', 's525685491', 's073971231'] | [23940.0, 21444.0, 23936.0] | [569.0, 480.0, 553.0] | [250, 221, 251] |
p02630 | u686174642 | 2,000 | 1,048,576 | 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. | ['n=int(input())\narr=[int(i) for i in input().strip().split(" ")]\nt=int(input())\ndic={}\nsum_array=0\nfor i in arr:\n dic[i]=dic.get(i,0)+1\n sum_array+=i\n \n\nfor _ in range(t):\n a,b=[int(i) for i in input().split(" ")]\n if b in dic:\n dic[b]+=dic[a]\n else:\n dic[b]=dic[a]\n \n sum_array+=dic[a]*(b-a)\n print(dic,sum_array)\n dic[a]=0', 'n=int(input())\narr=[int(i) for i in input().strip().split(" ")]\nt=int(input())\ndic={}\nsum_array=0\nfor i in arr:\n dic[i]=dic.get(i,0)+1\n sum_array+=i\n \n\nfor _ in range(t):\n a,b=[int(i) for i in input().split(" ")]\n if a not in dic:\n print(sum_array)\n continue\n if b in dic:\n dic[b]+=dic[a]\n else:\n dic[b]=dic[a]\n \n sum_array+=dic[a]*(b-a)\n print(sum_array)\n dic[a]=0'] | ['Runtime Error', 'Accepted'] | ['s062262697', 's619975814'] | [20892.0, 21124.0] | [557.0, 544.0] | [367, 426] |
p02630 | u687553041 | 2,000 | 1,048,576 | 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. | ["import sys\n\nif __name__ == '__main__':\n n = int(sys.stdin.readline().rstrip())\n A = list(map(lambda x: int(x), sys.stdin.readline().split()))\n q = int(sys.stdin.readline().rstrip())\n B, C = [], []\n for i in range(q):\n b, c = list(map(lambda x: int(x), sys.stdin.readline().split()))\n B.append(b)\n C.append(c)\n\n for i in range(q):\n summ = 0\n for a in A:\n if a == B[i]:\n summ += C[i]\n else:\n summ += a\n print(summ)\n\n", "import sys\nimport numpy as np\n\nif __name__ == '__main__':\n n = int(sys.stdin.readline().rstrip())\n A = list(map(lambda x: int(x), sys.stdin.readline().split()))\n q = int(sys.stdin.readline().rstrip())\n dic = {}\n for a in A:\n dic[a] = dic.get(a, 0) + 1\n\n # keys = list(dic.keys())\n # values = list(dic.values())\n \n summ = sum([k*v for k, v in dic.items()])\n for i in range(q):\n b, c = list(map(lambda x: int(x), sys.stdin.readline().split()))\n\n diff = c*dic.get(b,0) - b*dic.get(b,0)\n dic[c] = dic.get(c, 0) + dic.get(b, 0)\n dic[b] = 0\n summ += diff\n print(summ)"] | ['Wrong Answer', 'Accepted'] | ['s265964134', 's048872305'] | [22088.0, 40768.0] | [2206.0, 428.0] | [526, 685] |
p02630 | u692054751 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\nN = int(input())\nA = [int(s) for s in input().split()]\nQ = int(input())\n\nd = Counter(A)\ntotal = sum(A)\n\nfor _ in range(Q):\n b, c = [int(s) for s in input().split()]\n if d[b]:\n total += (c - b) * d[b]\n d[c] = d[b]\n d[b] = 0\n print(total)\n\n', 'from collections import Counter\nN = int(input())\nA = [int(s) for s in input().split()]\nQ = int(input())\n\nd = Counter(A)\ntotal = sum(A)\n\nfor _ in range(Q):\n b, c = [int(s) for s in input().split()]\n if d[b]:\n total += (c - b) * d[b]\n d[c] = d[b] + (d[c] if d[c] else 0)\n d[b] = 0\n print(total)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s169616959', 's862721079'] | [21476.0, 21472.0] | [524.0, 531.0] | [300, 324] |
p02630 | u693025087 | 2,000 | 1,048,576 | 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. | ['# -*- coding: utf-8 -*-\nimport collections\nN = int(input())\nA = list(map(int, input().split()))\nA_amount = collections.Counter(A)\n\nresult = sum(A)\n\nQ = int(input())\nfor q in range(Q):\n B, C = map(int, input().split())\n\tB_elem = A_amount.get(B, None)\n if B_elem is not None:\n C_elem = A_amount.get(C, None)\n if C_elem is not None:\n A_amount.pop(B_elem)\n A_amount[C] = (C, B_elem[1]+C_elem[1])\n else:\n A_amount.pop(B_elem)\n A_amount[C] = (C, B_elem[1])\n\n result += (C-B)*B_elem[1]\n \n print(result)', '# -*- coding: utf-8 -*-\nimport collections\nN = int(input())\nA = list(map(int, input().split()))\nA_amount = collections.Counter(A)\n\nresult = sum(A)\n\nQ = int(input())\nfor q in range(Q):\n B, C = map(int, input().split())\n\tB_elem = A_amount.get(B, None)\n if B_elem is not None:\n C_elem = A_amount.get(C, None)\n if C_elem is not None:\n A_amount.pop(B_elem)\n A_amount[C] = (C, B_elem[1]+C_elem[1])\n else:\n A_amount.pop(B_elem)\n A_amount[C] = (C, B_elem[1])\n\n result += (C-B)*B_elem[1]\n \n print(result)', '# -*- coding: utf-8 -*-\ndef find(tuple_list, num, top_idx):\n length = len(tuple_list)\n\n if length == 0:\n return top_idx, False\n\n if length == 1:\n hikaku = tuple_list[0][0]\n if num == hikaku:\n return top_idx, True\n elif num < hikaku:\n return top_idx-1, False\n elif num > hikaku:\n return top_idx, False\n \n if length == 2:\n hikaku1 = tuple_list[0][0]\n hikaku2 = tuple_list[1][0]\n if num == hikaku1:\n return top_idx, True\n elif num == hikaku2:\n return top_idx+1, True\n elif num < hikaku1:\n return top_idx-1, False\n elif hikaku1 < num < hikaku2:\n return top_idx, False\n elif hikaku2 < num:\n return top_idx+1, False\n\n place = int(length/2)\n hikaku = tuple_list[place][0]\n if num == hikaku:\n return top_idx+place, True\n elif num < hikaku:\n return find(tuple_list[:place], num, top_idx)\n elif num > hikaku:\n return find(tuple_list[place+1:], num, top_idx+place+1)\n\n\nN = int(input())\nA = list(map(int, input().split()))\nA_amount = list(collections.Counter(A).items())\nA_amount = list(sorted(A_amount, key=lambda x:x[0]))\n\nresult = sum(A)\n\nQ = int(input())\nfor q in range(Q):\n B, C = map(int, input().split())\n B_idx, is_B_exist = find(A_amount, B, 0)\n if is_B_exist:\n old_tuple = A_amount[B_idx]\n C_idx, is_C_exist = find(A_amount, C, 0)\n if is_C_exist:\n new_tuple = (C, A_amount[B_idx][1]+A_amount[C_idx][1])\n A_amount[C_idx] = new_tuple\n A_amount_before = A_amount[:B_idx]\n A_amount_after = A_amount[B_idx+1:]\n A_amount_before.extend(A_amount_after)\n A_amount = A_amount_before\n else:\n new_tuple = (C, A_amount[B_idx][1])\n if B_idx < C_idx:\n A_amount_1 = A_amount[:B_idx]\n A_amount_2 = A_amount[B_idx+1:C_idx+1]\n A_amount_3 = A_amount[C_idx+1:]\n A_amount_1.extend(A_amount_2)\n A_amount_1.append(new_tuple)\n A_amount_1.extend(A_amount_3)\n else:\n A_amount_1 = A_amount[:C_idx+1]\n A_amount_2 = A_amount[C_idx+1:B_idx]\n A_amount_3 = A_amount[B_idx+1:]\n A_amount_1.append(new_tuple)\n A_amount_1.extend(A_amount_2)\n A_amount_1.extend(A_amount_3)\n A_amount = A_amount_1\n \n result += (C-B)*old_tuple[1]\n \n print(result)', '# -*- coding: utf-8 -*-\nimport collections\nN = int(input())\nA = list(map(int, input().split()))\nA_amount = dict(collections.Counter(A))\n\nresult = sum(A)\n\nQ = int(input())\nfor q in range(Q):\n B, C = map(int, input().split())\n B_elem = A_amount.get(B, None)\n if B_elem is not None:\n C_elem = A_amount.get(C, None)\n if C_elem is not None:\n A_amount.pop(B)\n A_amount[C] = B_elem+C_elem\n else:\n A_amount.pop(B)\n A_amount[C] = B_elem\n\n result += (C-B)*B_elem\n print(A_amount)\n\n print(result)', '# -*- coding: utf-8 -*-\nimport collections\nN = int(input())\nA = list(map(int, input().split()))\nA_amount = dict(collections.Counter(A))\n\nresult = sum(A)\n\nQ = int(input())\nfor q in range(Q):\n B, C = map(int, input().split())\n B_elem = A_amount.get(B, None)\n if B_elem is not None:\n C_elem = A_amount.get(C, None)\n if C_elem is not None:\n A_amount.pop(B)\n A_amount[C] = B_elem+C_elem\n else:\n A_amount.pop(B)\n A_amount[C] = B_elem\n\n result += (C-B)*B_elem\n\n print(result)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s087422022', 's156106157', 's270675484', 's645342132', 's568624308'] | [8800.0, 9052.0, 21260.0, 147816.0, 21256.0] | [29.0, 25.0, 54.0, 2459.0, 519.0] | [583, 583, 2570, 572, 552] |
p02630 | u693716675 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = [int(i) for i in input().split()]\nq = int(input())\n\nans = sum(a)\nnumbers = [0]*(10**5+1)\nfor _ in range(q):\n b,c = [int(i) for i in input().split()]\n nb = numbers[b]\n ans += (c-b)*nb\n print(ans)\n numbers[b] = 0\n numbers[c] += nb ', 'n = int(input())\na = [int(i) for i in input().split()]\nq = int(input())\n\nans = sum(a)\nnumbers = [0]*(10**5+1)\nfor v in a:\n numbers[v] += 1\n\nfor _ in range(q):\n b,c = [int(i) for i in input().split()]\n nb = numbers[b]\n ans += (c-b)*nb\n print(ans)\n numbers[b] = 0\n numbers[c] += nb '] | ['Wrong Answer', 'Accepted'] | ['s390349565', 's779090442'] | [20384.0, 20960.0] | [484.0, 497.0] | [271, 304] |
p02630 | u696444274 | 2,000 | 1,048,576 | 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. | ['n = int(input())\n# w = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nq = int(input())\n#p = list(map(int, input().split()))\n#a = list(map(int, input().split()))\n\nbc = [list(map(int, input().split())) for i in range(q)]\n# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))\na_count = collections.Counter(a)\na_list = dict(list(a_count.items()))\n#print(a_list)\ntotal = sum(a)\nfor b, c in bc:\n if b in a_list:\n total += (c-b)*a_list[b]\n num = a_list[b]\n a_list[b] = 0\n if c in a_list:\n a_list[c] += num\n else:\n a_list[c] = num\n \n print(total)\n', 'import collections\nn = int(input())\n# w = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nq = int(input())\n#p = list(map(int, input().split()))\n#a = list(map(int, input().split()))\n\nbc = [list(map(int, input().split())) for i in range(q)]\n# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))\na_count = collections.Counter(a)\na_list = dict(list(a_count.items()))\n#print(a_list)\ntotal = sum(a)\nfor b, c in bc:\n if b in a_list:\n total += (c-b)*a_list[b]\n num = a_list[b]\n a_list[b] = 0\n if c in a_list:\n a_list[c] += num\n else:\n a_list[c] = num\n \n print(total)\n'] | ['Runtime Error', 'Accepted'] | ['s457938247', 's843659915'] | [31372.0, 43236.0] | [229.0, 373.0] | [784, 803] |
p02630 | u696684809 | 2,000 | 1,048,576 | 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. | ['import math\n\nn = int(input())\na = [0]*10**7\nx = math.sqrt(10)\nb = math.floor(x)\nl = 0\nfor i in range(1,n+1):\n x = math.sqrt(i)\n b = math.floor(x)\n for j in range(1,b+1):\n if(i%j==0 and i//j == j):\n a[i-1] +=1\n elif(i%j==0):\n a[i-1] +=2\nfor k in range(n):\n l = l + a[k]*(k+1)\nprint(l)\n \n', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nr = [0]*(10**5+10)\nfor i in range(n):\n r[a[i]] +=1\nb = [0]*q\nc = [0]*q\nfor i in range(q):\n b[i],c[i] = map(int,input().split())\ns = 0\nfor m in range(n):\n s += a[m] \nfor ii in range(q):\n s = s + (c[ii]-b[ii])*r[b[ii]]\n r[c[ii]] +=r[b[ii]]\n r[b[ii]]=0\n print(s)'] | ['Wrong Answer', 'Accepted'] | ['s284861014', 's405653547'] | [87236.0, 22232.0] | [2208.0, 344.0] | [306, 336] |
p02630 | u698919163 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int,input().split()))\n\nnum_count = [0]*(10**5+1)\ntmp_sum = sum(A)\nfor i in A:\n num_count[i] += 1\n\nfor q in range(int(input()):\n B,C = map(int,input().split())\n gain = C*(num_count[B])\n loss = B*(num_count[B])\n num_count[C] += num_count[B]\n num_count[B] = 0\n tmp_sum = tmp_sum + gain - loss\n print(tmp_sum)\n', 'N = int(input())\nA = list(map(int,input().split()))\n\nnum_count = [0]*(10**5+1)\ntmp_sum = sum(A)\nfor i in A:\n num_count[i] += 1\n\nfor q in range(int(input())):\n B,C = map(int,input().split())\n gain = C*(num_count[B])\n loss = B*(num_count[B])\n num_count[C] += num_count[B]\n num_count[B] = 0\n tmp_sum = tmp_sum + gain - loss\n print(tmp_sum)\n'] | ['Runtime Error', 'Accepted'] | ['s973811241', 's438796316'] | [8888.0, 20948.0] | [22.0, 494.0] | [360, 361] |
p02630 | u698977701 | 2,000 | 1,048,576 | 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. | ['n = int(input())\narr = list(map(int, input().split()))\n\nsu = sum(arr)\n\nq = int(input())\nfor i in range(q):\n\tb,c = map(int, input().split())\n si = su -b + c\n print(si)\n', 'def ad(a,bank):\n\tif a not in bank:\n\t\tbank[a] = 1\n\telse:\n\t\tbank[a] += 1\n\ndef rp(a,b,bank):\n\tans = 0\n\tif a in bank:\n\t\tt = bank[a]\n\t\tans = t\n\t\tbank[a] = 0\n\t\tif b not in bank:\n\t\t\tbank[b] = t\n\t\telse:\n\t\t\tbank[b] += t\n\t\t\n\treturn ans\n# your code goes here\nn = int(input())\narr = list(map(int, input().split()))\n\nbank = dict()\nsu = 0\n\nfor a in arr:\n\tad(a,bank)\n\tsu += a\n\nq = int(input())\nfor i in range(q):\n\tb,c = map(int, input().split())\n\tt = rp(b,c,bank)\n\tif b in bank:\n\t\tsu = su - (t*b) + (t*c)\n\t\n\tprint(su)\n'] | ['Runtime Error', 'Accepted'] | ['s827917664', 's988910755'] | [8968.0, 20860.0] | [22.0, 546.0] | [173, 503] |
p02630 | u703823201 | 2,000 | 1,048,576 | 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. | ['mport sys\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\n\nfor q in range(Q):\n b, c = map(int, input().split())\n for n in range(N):\n if b == A[n]:\n A[n] = c\n print(sum(A))', 'import collections\nN = int(input())\nA = list(map(int, input().split()))\ncnt = collections.Counter(A)\nQ = int(input())\nans = []\ns = sum(A)\nfor _ in range(Q):\n b, c = map(int, input().split())\n n = cnt[b]\n if b in cnt:\n cnt[c] += cnt[b]\n del cnt[b]\n s += (c-b)*n\n print(s)'] | ['Runtime Error', 'Accepted'] | ['s046286485', 's779646092'] | [9012.0, 21400.0] | [26.0, 563.0] | [221, 299] |
p02630 | u706414019 | 2,000 | 1,048,576 | 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. | [' = int(input())\nA = list(map(int,(input().split())))\nQ = int(input())\nnum_list = [0]*(N+1)\ns = []\nfor i in range(N):\n num_list[A[i]] += 1\nfor _ in range(Q):\n s_s = 0\n B,C = map(int,(input().split()))\n num_list[C] += num_list[B]\n num_list[B] = 0\n for j in range(N+1):\n s_s += (j)*num_list[j]\n s.append(s_s)\nfor i in range(Q):\n print(s[i])\n', 'import sys,collections\ninput = sys.stdin.readline\n\nN=input().rstrip()\nA=list(map(int,input().split()))\nAc = collections.Counter(A)\nQ = int(input())\nfor i in range(Q):\n B,C = list(map(int,input().split()))\n nb = Ac[B]\n Ac[C] += Ac[B]\n Ac[B] = 0\n\n if i==0:\n ans = 0\n for key,val in Ac.items():\n ans += key*val\n else:\n ans +=nb*C - nb*B\n \n print(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s844558609', 's239818821'] | [8900.0, 24128.0] | [27.0, 281.0] | [369, 404] |
p02630 | u718949306 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\nC = sum(A)\nZ = {}\nfor n in range(N):\n Z[A[n]] = 0\nfor n in range(N):\n Z[A[n]] += 1\nD = []\nQ = int(input())\nfor q in range(Q):\n x, y = map(int, input().split())\n if x in Z:\n C = C - x*Z[x]\n C = C + y*Z[x]\n D.append(C)\n if x == y:\n continue\n Z[y] = 1*Z[x]\n Z.pop(x)\n else:\n D.append(C)\nfor d in D:\n print(d)\n', 'N = int(input())\nA = list(map(int, input().split()))\nC = sum(A)\nZ = {}\nfor n in range(N):\n Z[A[n]] = 0\nfor n in range(N):\n Z[A[n]] += 1\nD = []\nQ = int(input())\nfor q in range(Q):\n x, y = map(int, input().split())\n if x in Z:\n C = C - x*Z[x]\n C = C + y*Z[x]\n D.append(C)\n if y in Z:\n Z[y] += 1*Z[x]\n else:\n Z[y] = Z[x]\n Z.pop(x)\n else:\n D.append(C)\nfor d in D:\n print(d)\n'] | ['Wrong Answer', 'Accepted'] | ['s648156291', 's544362290'] | [21828.0, 21668.0] | [329.0, 333.0] | [437, 459] |
p02630 | u723792785 | 2,000 | 1,048,576 | 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. | ['import collections\nimport random\ninp = list(range(1, 100001))\ndic = dict(collections.Counter(inp))\nwa = 0\nfor i, j in dic.items():\n\twa += i * j\nse = set(dic.keys())\nfor i in range(int(input())):\n\ta = random.randrange(1, 10001)\n\tb = random.randrange(1, 10001)\n\tif a in se:\n\t\twa += dic[a] * (b-a)\n\t\tif b in se:\n\t\t\tpass\n\t\telse:\n\t\t\tdic[b] = 0\n\t\tse.add(b)\n\t\tdic[b] += dic[a]\n\t\tdic[a] = 0\n\tprint(wa)', 'import collections\nN = int(input())\ninp = list(map(int,input().split()))\ndic = dict(collections.Counter(inp))\nwa = 0\nfor i, j in dic.items():\n\twa += i * j\nse = set(dic.keys())\nfor i in range(int(input())):\n\ta, b = map(int,input().split())\n\tif a in se:\n\t\twa += dic[a] * (b-a)\n\t\tif b in se:\n\t\t\tpass\n\t\telse:\n\t\t\tdic[b] = 0\n\t\tse.add(b)\n\t\tdic[b] += dic[a]\n\t\tdic[a] = 0\n\tprint(wa)'] | ['Wrong Answer', 'Accepted'] | ['s778637774', 's832386181'] | [25632.0, 23488.0] | [312.0, 523.0] | [393, 373] |
p02630 | u730449065 | 2,000 | 1,048,576 | 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. | ['n = int(input())\n\nl = list(map(int, input().split()))\n\nsort(l)\n\nm = int(input())\n\nfor i in range(m):\n a,b = map(int, input().split())\n \n l = [b if j == a else j for j in l]\n\n print(sum(l))', '#from collections import defaultdict\n\nn = int(input())\ncnt =[0]*1000000\n\nl = list(map(int, input().split()))\n\nfor i in l:\n cnt[i] += 1\n \nsums = sum(l)\n \nm = int(input())\n\nfor i in range(m):\n a,b = map(int, input().split())\n \n diff = (b-a)*cnt[a]\n sums += diff\n print(sums)\n \n cnt[b] += cnt[a]\n cnt[a] = 0'] | ['Runtime Error', 'Accepted'] | ['s211453281', 's355577834'] | [20824.0, 28636.0] | [42.0, 508.0] | [200, 337] |
p02630 | u751277549 | 2,000 | 1,048,576 | 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. | ['import numpy as np\n\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nsumA = sum(A)\ncnt_num = np.zeros(10**5 + 1)\n\nfor i in A:\n cnt_num[i] += 1\n\nfor i in range(Q):\n B, C = map(int, input().split())\n sumA += (C - B) * cnt_num[B]\n print(sumA)\n cnt_num[C] += cnt_num[B]\n cnt_num[B] = 0', 'import numpy as np\n\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nsumA = sum(A)\ncnt_num = np.zeros(10**5 + 1)\n\nfor i in A:\n cnt_num[i] += 1\n\nfor i in range(Q):\n B, C = map(int, input().split())\n sumA += (C - B) * cnt_num[B]\n print(int(sumA))\n cnt_num[C] += cnt_num[B]\n cnt_num[B] = 0\n '] | ['Wrong Answer', 'Accepted'] | ['s429225450', 's937402815'] | [38392.0, 38740.0] | [734.0, 724.0] | [322, 332] |
p02630 | u756609156 | 2,000 | 1,048,576 | 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. | ['n = int(input())\nm = {}\ntot = 0\nfor a in map(int,input().split()):\n tot += m\n if a not in m:\n m[a]=0\n m[a] += 1\nq = int(input())\nfor step in range(q):\n b,c = map(int,input().split())\n if c not in m:\n m[c] = 0\n if b in m:\n m[c] += m[b]\n tot += m[b]*(c-b)\n m[b] = 0\n print(tot)\n\n', 'n = int(input())\nm = {}\ntot = 0\nfor a in map(int,input().split()):\n tot += a\n if a not in m:\n m[a]=0\n m[a] += 1\nq = int(input())\nfor step in range(q):\n b,c = map(int,input().split())\n if c not in m:\n m[c] = 0\n if b in m:\n m[c] += m[b]\n tot += m[b]*(c-b)\n m[b] = 0\n print(tot)'] | ['Runtime Error', 'Accepted'] | ['s822540892', 's789964303'] | [17048.0, 21832.0] | [35.0, 559.0] | [299, 297] |
p02630 | u763534217 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nb = []\nc = []\nfor i in range(q):\n _ = list(map(int, input().split()))\n c.append(_[1])\n b.append(_[0])\n\ns = sum(a)\n\n\nhist = {}\nfor i in range(n):\n if a[i] in hist:\n hist[a[i]] += 1\n else:\n hist[a[i]] = 1\nprint(hist)\n\nfor i in range(q):\n diff = c[i] - b[i]\n if b[i] in hist:\n s += hist[b[i]]*diff\n print(s)\n if c[i] in hist:\n hist[c[i]] += hist[b[i]]\n else:\n hist[c[i]] = hist[b[i]]\n del hist[b[i]]\n else:\n print(s)\n # print(hist)\n', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nb = []\nc = []\nfor i in range(q):\n _ = list(map(int, input().split()))\n c.append(_[1])\n b.append(_[0])\n\ns = sum(a)\n\n\nhist = {}\nfor i in range(n):\n if a[i] in hist:\n hist[a[i]] += 1\n else:\n hist[a[i]] = 1\n# print(hist)\n\nfor i in range(q):\n diff = c[i] - b[i]\n if b[i] in hist:\n s += hist[b[i]]*diff\n print(s)\n if c[i] in hist:\n hist[c[i]] += hist[b[i]]\n del hist[b[i]]\n else:\n hist[c[i]] = hist[b[i]]\n del hist[b[i]]\n else:\n print(s)\n # print(hist)\n'] | ['Wrong Answer', 'Accepted'] | ['s701129220', 's598241200'] | [89852.0, 26880.0] | [2348.0, 368.0] | [637, 666] |
p02630 | u763550415 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n count = A.count(B)\n if count >0:\n A.remove(B)\n A.extend([C]*count)\n print(sum(A))', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\ncnt = [0]*(10**5+1)\n\ns = sum(A)\nfor i in A:\n cnt[i] += 1\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n s += (C-B)*cnt[B]\n print(s)\n cnt[C] += cnt[B]\n cnt[B] = 0'] | ['Wrong Answer', 'Accepted'] | ['s162792026', 's140836161'] | [219764.0, 20868.0] | [2211.0, 484.0] | [216, 245] |
p02630 | u766566560 | 2,000 | 1,048,576 | 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. | ['# ans\n\nN = int(input())\nA = list(map(int, input().split()))\ncnt = [0] * 100000\nfor i in range(A):\n cnt[i] += 1\nQ = int(input())\nS = sum(A)\n\nfor i in range(Q):\n B, C = map(int, input().split())\n diff = (C - B) * cnt[B]\n S += diff\n print(S)\n cnt[C] += cnt[B]\n cnt[B] = 0', '# ans\n\nN = int(input())\nA = list(map(int, input().split()))\ncnt = [0] * 100001\nfor i in A:\n cnt[i] += 1\nQ = int(input())\nS = sum(A)\n\nfor i in range(Q):\n B, C = map(int, input().split())\n diff = (C - B) * cnt[B]\n S += diff\n print(S)\n cnt[C] += cnt[B]\n cnt[B] = 0'] | ['Runtime Error', 'Accepted'] | ['s848048229', 's293916582'] | [20916.0, 20880.0] | [51.0, 496.0] | [275, 268] |
p02630 | u779293207 | 2,000 | 1,048,576 | 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. | ["H,W,K=map(int,input().split())\nc=[list(input()) for i in range(H)]\nb=0\nfor i in range(H):\n b+=c[i].count('#')\nif b==K:\n print(1)\n exit()\n \nelse:\n a=K-b\n count=0\n hc=[]\n wc=[]\n for i in range(2 ** H):\n h=['0']*H \n for j in range(H):\n if ((i >> j) & 1):\n h[H- 1 - j] = '1'\n hc.append(h)\n for i in range(2 ** W):\n w=['0']*W\n for j in range(W):\n if ((i >> j) & 1):\n w[W- 1 - j] = '1'\n wc.append(w)\n \n for k in range(len(hc)):\n for l in range(len(wc)):\n c1=list(c)\n for m in range(H):\n if hc[k][m]=='0':\n c1[m]='.'\n for n in range(W):\n if wc[l][n]=='0' and c1[m][n]=='#':\n c1[m][n]=c1[m][n].replace('#','.')\n for i in range(H):\n b+=c1[i].count('#')\n print(c1)\n if b==a:\n count+=1\n \nprint(count)\n \n \n ", 'import collections\n\nN=int(input())\nA=list(map(int, input().split()))\nQ=int(input())\ncountA=collections.Counter(A)\nans=sum(A)\n\nfor i in range(Q):\n B,C=map(int, input().split())\n b=countA[B]\n ans=ans+(C-B)*b\n print(ans)\n countA[B]=0\n countA[C]+=b\n\n'] | ['Runtime Error', 'Accepted'] | ['s526231979', 's640979628'] | [9304.0, 24012.0] | [23.0, 547.0] | [874, 264] |
p02630 | u788608806 | 2,000 | 1,048,576 | 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. | ['\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nnizi = [0] * (max(A)+1)\nfor i in range(len(A)):\n print(A[i], A)\n nizi[A[i]] += 1\nsumall = sum(A)\nfor q in range(Q):\n B, C = map(int, input().split())\n sumall += (C-B) * nizi[B]\n nizi[C] =+ nizi[B]\n nizi[B] = 0\n print(sumall)', '\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nnizi = [0] * (max(A)+1)\nfor i in range(len(A)):\n # print(A[i], A)\n nizi[A[i]] += 1\nsumall = sum(A)\nfor q in range(Q):\n B, C = map(int, input().split())\n sumall += (C-B) * nizi[B]\n nizi[C] =+ nizi[B]\n nizi[B] = 0\n print(sumall)', '\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nnizi = [0] * (10**5)\nfor i in range(len(A)):\n # print(A[i], A)\n nizi[A[i]] += 1\nsumall = sum(A)\nfor q in range(Q):\n B, C = map(int, input().split())\n sumall += (C-B) * nizi[B]\n nizi[C] =+ nizi[B]\n nizi[B] = 0\n print(sumall)', '\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nnizi = [0] * (10**5+1)\nfor i in range(len(A)):\n # print(A[i], A)\n nizi[A[i]] += 1\nsumall = sum(A)\nfor q in range(Q):\n \n B, C = map(int, input().split())\n sumall += (C-B) * nizi[B]\n nizi[C] += nizi[B]\n nizi[B] = 0\n print(sumall)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s092582411', 's448793420', 's764671157', 's788455093'] | [145816.0, 20964.0, 21200.0, 21068.0] | [2364.0, 488.0, 484.0, 510.0] | [317, 319, 316, 336] |
p02630 | u790905630 | 2,000 | 1,048,576 | 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. | ['def main():\n N = int(input())\n A = input()\n Q = input()\n\n answer = sum(list(map(int, A.split())))\n A = A.replace(" ", "")\n\n operateList = (open(0).read().split("\\n"))[:-1]\n\n for operate in operateList:\n B, C = operate.split()\n numB = A.count(B)\n\n answer = answer + (int(C) - int(B)) * numB\n print(answer)\n\n A = A.replace(B, C)\n\nif __name__ == "__main__":\n main()', 'def main():\n N = int(input())\n A = input()\n Q = input()\n\n answer = sum(list(map(int, A.split())))\n A = A.replace(" ", "")\n\n operateList = (open(0).read().split("\\n"))[:-1]\n print(operateList)\n\n for operate in operateList:\n B, C = operate.split()\n numB = A.count(B)\n\n answer = answer + (int(C) - int(B)) * numB\n print(answer)\n\n A = A.replace(B, C)\n\nif __name__ == "__main__":\n main()', 'def main():\n N = int(input())\n A = input()\n Q = input()\n\n answer = sum(list(map(int, A.split())))\n A = A.replace(" ", "")\n\n operateList = (open(0).read().split("\\n"))[:-1]\n\n for operate in operateList:\n try:\n B, C = operate.split()\n numB = A.count(B)\n\n answer = answer + (int(C) - int(B)) * numB\n print(answer)\n\n A = A.replace(B, C)\n\n except:\n pass\n\nif __name__ == "__main__":\n main()', 'def main():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n\n answer = sum(A)\n numNumberList = [0] * 100000\n \n for i in range(Q):\n B, C = list(map(int, input().split()))\n answer = answer + (int(C) - int(B)) * numNumberList[B]\n\n numNumberList[C] = numNumberList[C] + numNumberList[B]\n numNumberList[B] = 0\n\n print(answer)\n\nif __name__ == "__main__":\n main()', 'import sys\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n\n answer = sum(A)\n setA = set(A)\n numNumberList = [0] * 100001\n\n for Ai in A:\n numNumberList[Ai] = numNumberList[Ai] + 1 \n\n for i in range(Q):\n B, C = list(map(int, sys.stdin.readline().split()))\n answer = answer + (int(C) - int(B)) * numNumberList[B]\n\n numNumberList[C] = numNumberList[C] + numNumberList[B]\n numNumberList[B] = 0\n\n print(answer)\n\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s106703621', 's178900291', 's274982217', 's321032857', 's399022993'] | [32864.0, 32752.0, 32864.0, 20820.0, 20860.0] | [2207.0, 2207.0, 2207.0, 444.0, 207.0] | [421, 444, 488, 444, 551] |
p02630 | u798093965 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int,input().split()))\nq = int(input())\nb = [0] * q\nc = [0] * q\nans = sum(a)\nnumber = [0] * 100000\nfor i in range(q):\n b[i],c[i] = map(int,input().split())\nfor i in range(n):\n number[a[i]] += 1\nfor i in range(q):\n if number[b[i]] > 0:\n ans += (c[i] - b[i]) * number[b[i]]\n number[c[i]] = number[b[i]] \n number[b[i]] = 0\n print(ans)', 'n = int(input())\na = list(map(int,input().split()))\nq = int(input())\nb = [0] * q\nc = [0] * q\nans = sum(a)\nnumber = [0] * 100001\nfor i in range(q):\n b[i],c[i] = map(int,input().split())\n\nfor i in range(n):\n number[a[i]] += 1\n\nfor i in range(q):\n if number[b[i]] > 0:\n ans += (c[i] - b[i]) * number[b[i]]\n number[c[i]] += number[b[i]] \n number[b[i]] = 0\n print(ans)'] | ['Runtime Error', 'Accepted'] | ['s328323791', 's953622881'] | [22108.0, 21948.0] | [247.0, 290.0] | [396, 399] |
p02630 | u800058906 | 2,000 | 1,048,576 | 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. | ['n=int(input())\na=list(map(int,input().split()))\nq=int(input())\nbc=[list(map(int,input().split())) for i in range(q)]\n\nasum=sum(a) \nd={}\n\nfor i in a:\n if i in d:\n d[i]+=1\n else:\n d[i]=1\n\nfor b,c in bc:\n print(b)\n print(c)\n if b in d:\n asum+=d[b]*(c-b)\n if c in d:\n d[c]+=d[b]\n else:\n d[c]=d[b]\n d[b]=0\n print(asum)', 'n=int(input())\na=list(map(int,input().split()))\nq=int(input())\nbc=[list(map(int,input().split())) for i in range(q)]\n\nasum=sum(a) \nd={}\n\nfor i in a:\n if i in d:\n d[i]+=1\n else:\n d[i]=1\n\nfor b,c in bc:\n if b in d:\n asum+=d[b]*(c-b)\n if c in d:\n d[c]+=d[b]\n else:\n d[c]=d[b]\n d[b]=0\n print(asum)'] | ['Wrong Answer', 'Accepted'] | ['s474697469', 's787743261'] | [35720.0, 35828.0] | [412.0, 358.0] | [379, 357] |
p02630 | u806976856 | 2,000 | 1,048,576 | 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. | ['n=int(input())\na=list(map(int,input().split()))\nq=int(input())\nnum=[0]*(10**5+1)\nans=sum(a)\nfor i in a:\n num[i]+=1\nfor i in range(q):\n b,c=map(int,input().split())\n ans=ans+(c-b)*num[b-1][0]\n num[c-1][0]+=num[b-1][0]\n num[b-1][0]=0\n print(ans)\n ', 'n=int(input())\na=list(map(int,input().split()))\nq=int(input())\nnum=[0]*(10**5+1)\nans=sum(a)\nfor i in a:\n num[i]+=1\nfor i in range(q):\n b,c=map(int,input().split())\n ans=ans+(c-b)*num[b]\n num[c]+=num[b]\n num[b]=0\n print(ans)\n \n '] | ['Runtime Error', 'Accepted'] | ['s305956686', 's725559838'] | [20888.0, 20968.0] | [64.0, 489.0] | [266, 251] |
p02630 | u809714729 | 2,000 | 1,048,576 | 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. | ['import collections\nN = int(input())\nA = list(map(int, input().split()))\nindices = collections.defaultdict(list)\nfor i, a in enumerate(A):\n indices[a].append(i)\nQ = int(input())\nfor _ in range(Q):\n B, C = map(int, input().split())\n print(B, C)\n for i in indices[B]:\n indices[C].append(i)\n A[i] = C\n print(sum(A))', 'N = int(input())\nA = map(int, input.split())\nindices = collections.defaultdict(list)\nfor i, a in enumerate(A):\n indices[a].append(i)\nQ = int(input())\nfor _ in Q:\n B, C = map(int, input.split())\n for i in indices[B]:\n indices[C].append(i)\n A[i] = C\n print(sum(A))', 'import collections\nN = int(input())\nA = list(map(int, input().split()))\ncount = collections.defaultdict(int)\ncurrSum = 0\nfor a in A:\n count[a] += 1\n currSum += a\nQ = int(input())\nfor _ in range(Q):\n B, C = map(int, input().split())\n currSum += (count[B] * (C - B))\n count[C] += count[B]\n count[B] = 0\n print(currSum)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s116397815', 's637997957', 's464276560'] | [139844.0, 9016.0, 23852.0] | [2210.0, 25.0, 532.0] | [322, 272, 323] |
p02630 | u811817592 | 2,000 | 1,048,576 | 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. | ['n=int(input())\na=list(map(int,input().split()))\nq=int(input())\ndic={}\nfor i in range(len(a)):\n dic.setdefault(a[i],1)\n dic[a[i]]+=1\nanswer=sum(a)\nfor i in range(q):\n b,c=map(int,input().split())\n dic.setdefault(b,0)\n dic.setdefault(c,dic[b])\n dic[c]+=dic[b]\n answer=answer+dic[b]*c-dic[b]*b\n print(answer)', 'a=list(map(int,input().split()))\nq=int(input())\ndic={}\nfor i in range(len(a)):\n dic.setdefault(a[i],1)\n dic[a[i]]+=1\nanswer=sum(a)\nfor i in range(q):\n b,c=map(int,input().split())\n dic.setdefault(b,0)\n dic.setdefault(c,0)\n dic[c]+=dic[b]\n answer=answer+dic[b]*c-dic[b]*b\n dic[b] = 0\n print(answer)', 'a=list(map(int,input().split()))\nq=int(input())\ndic={}\nfor i in range(len(a)):\n dic.setdefault(a[i],1)\n dic[a[i]]+=1\nanswer=sum(a)\nfor i in range(q):\n b,c=map(int,input().split())\n dic.setdefault(b,0)\n dic.setdefault(c,0)\n dic[c]+=dic[b]\n answer=answer+dic[b]*c-dic[b]*b\n dic[b] = 0\n print(answer)', 'n=int(input())\na=list(map(int,input().split()))\nq=int(input())\ndic={}\nfor i in range(len(a)):\n dic.setdefault(a[i],1)\n dic[a[i]]+=1\nanswer=sum(a)\nfor i in range(q):\n b,c=map(int,input().split())\n dic.setdefault(b,0)\n dic.setdefault(c,0)\n dic[c]+=dic[b]\n answer=answer+dic[b]*c-dic[b]*b\n dic[b] = 0\n print(answer)', 'n=int(input())\na=list(map(int,input().split()))\nq=int(input())\ndic={}\nfor i in range(len(a)):\n dic.setdefault(a[i],1)\n dic[a[i]]+=1\nanswer=sum(a)\nfor i in range(q):\n b,c=map(int,input().split())\n dic.setdefault(b,0)\n dic.setdefault(c,dic[b])\n dic[c]+=dic[b]\n answer=answer+dic[b]*c-dic[b]*b\n dic[b] = 0\n print(answer)', 'n=int(input())\na=list(map(int,input().split()))\nq=int(input())\ndic={}\nfor i in range(len(a)):\n if a[i] in dic:\n dic[a[i]]+=1\n else:\n dic.setdefault(a[i],1)\nanswer=sum(a)\nfor i in range(q):\n b,c=map(int,input().split())\n if b not in dic:\n dic.setdefault(b,0)\n elif c not in dic:\n dic.setdefault(c,dic[b])\n else:\n dic[c]+=dic[b]\n answer=answer+dic[b]*c-dic[b]*b\n dic[b] = 0\n print(answer)'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s070350609', 's337050603', 's678804862', 's780798440', 's841695920', 's611041890'] | [88424.0, 10792.0, 10708.0, 23624.0, 23508.0, 23876.0] | [2669.0, 29.0, 28.0, 564.0, 567.0, 573.0] | [325, 320, 320, 339, 340, 448] |
p02630 | u815878613 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\n\nimport sys\n\nreadline = sys.stdin.buffer.readline\n\ndef solver(int N, list A, int Q, list BC):\n d = Counter(A)\n\n sub_s = sum(A)\n\n for b, c in BC:\n sub_s += d[b] * (c - b)\n d[c] += d[b]\n d[b] = 0\n\n print(sub_s)\n\n\ndef run():\n N = int(readline())\n A = list(map(int, readline().split()))\n\n Q = int(readline())\n BC = [list(map(int, readline().split())) for _ in range(Q)]\n\n solver(N, A, Q, BC)\n\nrun()\n', 'import sys\nfrom collections import Counter\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN = int(readline())\nA = tuple(map(int, readline().split()))\nQ = int(readline())\nBC = map(int, read().split())\n\nd = Counter(A)\n\nsub_s = sum(A)\n\nfor b, c in zip(BC, BC):\n sub_s += d[b] * (c - b)\n d[c] += d[b]\n d[b] = 0\n\n print(sub_s)\n'] | ['Runtime Error', 'Accepted'] | ['s842188111', 's178639204'] | [8840.0, 34688.0] | [29.0, 245.0] | [479, 394] |
p02630 | u823885866 | 2,000 | 1,048,576 | 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. | ['import sys\nimport collections\n\nri = lambda: int(sys.stdin.readline())\nrm = lambda: map(int, sys.stdin.buffer.readline().split())\nrl = lambda: list(map(int, sys.stdin.readline().split()))\n\nn = ri()\na = rl()\nil = list(set(a))\nli = collections.Counter(a)\nq = ri()\nres = []\nbc = [rm() for _ in range(q)]\nfor vvv in bc:\n b, c = vvv\n if b in il:\n if c in il:\n li[c] += li[b]\n else:\n li[c] = li[b]\n il.append(c)\n li[b] = 0\n il.remove(b)\n ans = 0\n for k, v in li.items():\n ans += k*v\n res.append(ans)\nfor aaa in res:\n print(aaa)\n\n', 'import sys\nimport collections\n\nri = lambda: int(sys.stdin.readline())\nrm = lambda: map(int, sys.stdin.buffer.readline().split())\nrl = lambda: list(map(int, sys.stdin.readline().split()))\n\nn = ri()\na = rl()\nil = list(set(a))\nli = collections.Counter(a)\nq = ri()\nres = []\nfor _ in range(q):\n b, c = rm()\n if b in il:\n if c in il:\n li[c] += li[b]\n else:\n li[c] = li[b]\n il.append(c)\n li[b] = 0\n il.remove(b)\n ans = 0\n for k, v in li.items():\n ans += k*v\n res.append(ans)\nfor aaa in res:\n print(aaa)\n\n', 'import sys\nimport collections\n\nri = lambda: int(sys.stdin.readline())\nrm = lambda: map(int, sys.stdin.buffer.readline().split())\nrl = lambda: list(map(int, sys.stdin.readline().split()))\n\nn = ri()\na = rl()\nil = list(set(a))\nli = collections.Counter(a)\nq = ri()\nfor _ in range(q):\n b, c = rm()\n if b in il:\n if c in il:\n li[c] += li[b]\n else:\n li[c] = li[b]\n il.append(c)\n li[b] = 0\n il.remove(b)\n ans = 0\n for k, v in li.items():\n ans += k*v\n print(ans)\n\n', 'import sys\nri = lambda: int(sys.stdin.readline())\nrm = lambda: map(int, sys.stdin.readline().split())\nrl = lambda: list(map(int, sys.stdin.readline().split()))\n\nn = ri()\na = rl()\nt = sum(a)\ncnt_li = [0]*10**5\nfor i in a:\n cnt_li[i-1] += 1\n\nfor _ in range(ri()):\n b, c = rm()\n t += (c-b)*cnt_li[b-1]\n print(t)\n cnt_li[c-1] += cnt_li[b-1]\n cnt_li[b-1] = 0'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s097255856', 's270924542', 's406328462', 's883449196'] | [58492.0, 21240.0, 21160.0, 20172.0] | [2207.0, 2206.0, 2206.0, 206.0] | [608, 583, 538, 371] |
p02630 | u826785572 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\n\nans = sum(a)\nA = Counter(a).most_common()\nd = [0] * 10**5+10\nfor i in range(len(A)):\n d[A[i][0]] = A[i][1]\n\nB = []\nC = []\nfor i in range(q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n\nfor i in range(q):\n d[C[i]] += d[B[i]]\n cnt = d[B[i]]\n ans += (C[i]-B[i])*cnt\n print(ans)\n d[B[i]] = 0', 'from collections import Counter\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\n\nans = sum(a)\nA = Counter(a).most_common()\nd = [0] * (10**5+10)\nfor i in range(len(A)):\n d[A[i][0]] = A[i][1]\n\nB = []\nC = []\nfor i in range(q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n\nfor i in range(q):\n d[C[i]] += d[B[i]]\n cnt = d[B[i]]\n ans += (C[i]-B[i])*cnt\n print(ans)\n d[B[i]] = 0'] | ['Runtime Error', 'Accepted'] | ['s533941462', 's518534744'] | [21236.0, 27696.0] | [89.0, 370.0] | [434, 436] |
p02630 | u830054172 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\n\nN = int(input())\nA = list(map(int, input().split()))\nsumA = sum(A)\n\ndic = Counter(A)\n\nQ = int(input())\n\nfor _ in range(Q):\n b, c = map(int, input().split())\n if b in dic.keys():\n ans = sumA+(dic[b]*(c-b))\n\n B = dic[b]\n if c in dic.keys():\n dic[c] += dic[b]\n del dic[b]\n else:\n dic[c] = dic[b]\n del dic[b]\n \n sumA += (dic[c]*c-B*b)\n \n # print(dic)\n print(ans)', 'from collections import Counter\n\nN = int(input())\nA = list(map(int, input().split()))\n\ncnt = [0 for _ in range(100005)]\nfor i in range(N):\n cnt[A[i]] += 1\n\nsumA = sum(A)\n\n# print(sumA)\n\nQ = int(input())\nfor _ in range(Q):\n b, c = map(int, input().split())\n \n if cnt[b]:\n sumA += (c-b)*cnt[b]\n cnt[c] += cnt[b]\n cnt[b] = 0\n print(sumA)\n'] | ['Runtime Error', 'Accepted'] | ['s428690393', 's618819284'] | [21464.0, 21292.0] | [576.0, 483.0] | [500, 371] |
p02630 | u833238721 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\nS = sum(A)\nL = [0] * 100001\nfor i in A:\n L[i] += 1\nQ = int(input())\nfor i in range(Q):\n B, C = map(int, input().split())\n S += (C - B) * L[B]\n L[C] += Ct[B]\n L[B] = 0\n print(S)', 'N = int(input())\nA = list(map(int, input().split()))\nS = sum(A)\nL = [0] * 100001\nfor i in A:\n L[i] += 1\nQ = int(input())\nfor i in range(Q):\n B, C = map(int, input().split())\n S += (C - B) * L[B]\n L[C] += L[B]\n L[B] = 0\n print(S)'] | ['Runtime Error', 'Accepted'] | ['s447750960', 's913659896'] | [20992.0, 20684.0] | [58.0, 459.0] | [247, 246] |
p02630 | u833738197 | 2,000 | 1,048,576 | 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. | ["import numpy as np\nn = int(input())\nA = list(map(int,input().split()))\nq = int(input())\nBC = [list(map(int,input().split())) for _ in range(q)]\nA = np.array(A)\n \ndef main(A,BC):\n for bc in BC:\n A = np.where(A==bc[0],bc[1],A)\n print(max(A))\n \nif __name__ == '__main__':\n main(A,BC)", 'import numpy as np\nfrom numba import njit\n\nn = int(input())\nA = list(map(int,input().split()))\nq = int(input())\nBC = [list(map(int,input().split())) for _ in range(q)]\nA = np.array(A)\n\nans = sum(A)\n\n\na_num = [0]*10**5\nfor a in A:\n a_num[a-1]+=1\n\nfor bc in BC:\n change = bc[1]-bc[0]\n ans += change*a_num[bc[0]-1]\n a_num[bc[1]-1] += a_num[bc[0]-1]\n a_num[bc[0]-1] = 0\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s023039085', 's092120221'] | [49740.0, 114164.0] | [2207.0, 836.0] | [307, 432] |
p02630 | u842033632 | 2,000 | 1,048,576 | 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. | ['\nimport numpy as np\nN = int(input())\nA = np.array(list(map(int, input().split())))\nQ = int(input())\nu, count = np.unique(A,return_counts=True)\nasum = A.sum()\nfor i in range(Q):\n B, C = list(map(int, input().split()))\n if B in u:\n posB = np.where(u==B)\n asum += int(count[posB]) * (C-B)\n print(u)\n print(count)\n if not (C in u):\n u[posB] = C\n else :\n posC = np.where(u==C)\n count[posC] += count[posB]\n u = np.delete(u,posB)\n count = np.delete(count,posB)\n # print(asum)\n # print(u)\n print(count)\n', '\nimport numpy as np\nN = int(input())\nA = np.array(list(map(int, input().split())))\nQ = int(input())\nu, count = np.unique(A,return_counts=True)\nL = np.zeros(10**5,int)\nfor i in range(len(u)):\n L[u[i]-1] = count[i]\nasum = A.sum()\nfor i in range(Q):\n B, C = list(map(int, input().split()))\n asum += L[B-1] * (C-B)\n L[C-1] += L[B-1]\n L[B-1] = 0\n print(asum)\n'] | ['Wrong Answer', 'Accepted'] | ['s665524812', 's141491861'] | [38888.0, 38660.0] | [2218.0, 781.0] | [617, 382] |
p02630 | u849341325 | 2,000 | 1,048,576 | 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. | ['import bisect\n\nN = int(input())\nA = list(map(int,input().split()))\n\nQ = int(input())\n\nA.sort()\nB = list(set(A))\nX = [[0 for j in range(2)] for i in range(len(B))]\nfor i in range(len(B)):\n b=bisect.bisect_left(A,B[i])\n c=bisect.bisect_right(A,B[i])\n num = c - b \n X[i][0] = B[i]\n X[i][1] = num\n\nM = [0 for j in range(Q)]\nN = [0 for j in range(Q)]\nfor i in range(Q):\n M[i],N[i] = map(int,input().split())\nB_len = len(B)\nans = int()\nfor i in range(Q):\n x = M[i]\n y = N[i]\n ans = 0\n jg = False\n for j in range(B_len):\n if X[j][0] == y:\n jg = True\n jgx = j\n for j in range(B_len):\n if X[j][0] == x:\n X[j][0] = y\n if jg == True:\n X[j][1] += X[jgx][1]\n X[jgx][0] = 0\n B_len = B_len-1\n for j in range(B_len):\n ans += X[j][0] * X[j][1]\n print(ans)\n #print(X)\n \n\n', 'import bisect\n\nN = int(input())\nA = list(map(int,input().split()))\n\nQ = int(input())\n\nA.sort()\nB = list(set(A))\nX = [[0 for j in range(2)] for i in range(len(B))]\nfor i in range(len(B)):\n b=bisect.bisect_left(A,B[i])\n c=bisect.bisect_right(A,B[i])\n num = c - b \n X[i][0] = B[i]\n X[i][1] = num\n\nM = [0 for j in range(Q)]\nN = [0 for j in range(Q)]\nfor i in range(Q):\n M[i],N[i] = map(int,input().split())\n\nans = int()\nfor i in range(Q):\n x = M[i]\n y = N[i]\n ans = 0\n jg = False\n for j in range(len(B)):\n if X[j][0] == y:\n jg = True\n jgx = j\n for j in range(len(B)):\n if X[j][0] == x:\n X[j][0] = y\n if jg = True:\n X[j][1] += X[jgx][1]\n X[jgx][0] = 0\n ans += X[j][0] * X[j][1]\n print(ans)\n #print(X)\n \n\n', 'N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nBC = [list(map(int,input().split())) for i in range(Q)]\nB, C = [list(i) for i in zip(*BC)]\n#print(B,C,BC)\n\ndic = {}\nfor a in A:\n dic[a] = dic.get(a,0) + 1\nprint(dic)\n\nans = sum(A)\nfor q in range(Q):\n ans = ans + (C[q]-B[q]) * dic.get(B[q],0)\n dic[C[q]] = dic.get(B[q],0) + dic.get(C[q],0)\n del dic[B[q]]\n print(ans)\n\n', 'N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nBC = [map(int,input().split()) for _ in range(Q)]\nB, C = [i for i in zip(*BC)]\n#print(B,C)\n\ndic = {}\nfor a in A:\n dic[a] = dic.get(a,0) + 1\n\nans = sum(A)\nfor q in range(Q):\n bc = C(q) - B(q)\n ans = ans + bc * dic.get(B(q),0)\n dic[C(q)] = dic.get(C(q),0) + dic.get(B(q),0)\n dic[B(q)] = 0\n print(ans)\n', 'N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nBC = [map(int,input().split()) for _ in range(Q)]\nB, C = [i for i in zip(*BC)]\n#print(B,C)\n\ndic = {}\nfor a in A:\n dic[a] = dic.get(a,0) + 1\n\nans = sum(A)\nfor q in range(Q):\n bc = C[q] - B[q]\n ans = ans + bc * dic.get(B[q],0)\n dic[C[q]] = dic.get(C[q],0) + dic.get(B[q],0)\n dic[B[q]] = 0\n print(ans)\n'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s411172054', 's426669450', 's483498834', 's517091886', 's614442758'] | [27844.0, 9052.0, 40156.0, 69712.0, 73440.0] | [2206.0, 24.0, 296.0, 382.0, 532.0] | [836, 774, 391, 374, 374] |
p02630 | u856819253 | 2,000 | 1,048,576 | 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. | ['import sys\n\ndef L(): return sys.stdin.readline().rstrip()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI():return list(map(int,sys.stdin.readline().rstrip().split()))\ndef LS():return list(sys.stdin.readline().rstrip().split())\n\nimport re\ndef solver(N,A,Q,BC):\n\n for b,c in BC:\n #print(A,\':\',b,\'->\',c)\n bef = \'[\\s]*\'+str(b)\n aft = \' \'+str(c)\n #print("bef,aft=",bef,aft)\n A = re.sub(bef, aft, A)\n #A = A.replace(\' \'+str(b), \' \'+str(c))\n #print(A)\n print(sum(map(int,A.split())))\n\n\ndef main():\n N = I()\n #A = LI()\n A = L()\n Q = I()\n BC = []*Q\n BC = [LI() for _ in range(Q)]\n\n print("N,Q=",N,Q)\n print("A=",A)\n print("BC=",BC)\n\n solver(N,A,Q,BC)\n\nif __name__ == \'__main__\':\n main()\n', "import sys\n\ndef L(): return sys.stdin.readline().rstrip()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI():return list(map(int,sys.stdin.readline().rstrip().split()))\ndef LS():return list(sys.stdin.readline().rstrip().split())\n\nimport collections\n\ndef solver(N,A,Q,BC):\n T = sum(map(int,A))\n #print(T)\n\n Nums = collections.Counter(A)\n #print(Nums)\n for b,c in BC:\n diff = c - b\n\n T += Nums[b] * diff\n print(T)\n\n Nums[c] += Nums[b]\n Nums[b] = 0\n\n\ndef main():\n N = I()\n A = LI()\n Q = I()\n BC = []*Q\n BC = [LI() for _ in range(Q)]\n\n solver(N,A,Q,BC)\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s315636313', 's400070715'] | [48048.0, 40440.0] | [2242.0, 285.0] | [781, 665] |
p02630 | u857657465 | 2,000 | 1,048,576 | 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. | ['n = int(input())+1\na = list(map(int, input().split()))\ncnt = []\n\nfor i in range(100005):\n cnt.append(0)\nsum = 0\nfor i in range(n):\n cnt[i] = a.count(i)\n sum += i * cnt[i]\n\nq = int(input())\nans = []\n\nfor i in range(q):\n b, c = map(int, input().split())\n sum += (c-b)*cnt[b]\n cnt[c] += cnt[b]\n cnt[b] = 0\n ans.append(sum)', 'n = int(input())+1\na = list(map(int, input().split()))\ncnt = []\nfor i in range(100005):\n cnt.append(0)\nsum = 0\n\n\n\nfor i in a:\n cnt[i] += 1\nfor i in range(100005):\n sum += i * cnt[i]\n\nq = int(input())\nans = []\nfor i in range(q):\n b, c = map(int, input().split())\n sum += (c-b)*cnt[b]\n cnt[c] += cnt[b]\n cnt[b] = 0\n ans.append(sum)\n\nfor i in ans:\n print(i)'] | ['Wrong Answer', 'Accepted'] | ['s959376350', 's430337006'] | [20860.0, 20608.0] | [2206.0, 307.0] | [343, 474] |
p02630 | u860002137 | 2,000 | 1,048,576 | 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. | ["from collections import defaultdict\nfrom collections import Counter\nfrom numba import jit\n\nn = int(input())\na = list(map(int, input().split()))\narr = defaultdict(int)\nq = int(input())\nbc = []\nfor _ in range(q):\n b, c = map(int, input().split())\n bc.append((b, c))\n\n\n@jit('void(i8, i8[:], i8[:], i8, i8[:])')\ndef solve(n, a, arr, q, bc):\n for k, v in Counter(a).items():\n arr[k] = v\n\n q = int(input())\n\n for b, c in bc:\n arr[c] += arr[b]\n arr[b] = 0\n print(sum([x * y for x, y in arr.items()]))\n\n\nsolve(n, a, arr, q, bc)", "from collections import defaultdict\nfrom collections import Counter\nfrom numba import jit\n\nn = int(input())\na = list(map(int, input().split()))\narr = defaultdict(int)\nq = int(input())\nbc = []\nfor _ in range(q):\n b, c = map(int, input().split())\n bc.append((b, c))\n\n\n@jit('void(i8, i8[:], i8[:], i8, i8[:])')\ndef solve(n, a, arr, q, bc):\n for k, v in Counter(a).items():\n arr[k] = v\n\n q = int(input())\n\n for b, c in bc:\n arr[c] += arr[b]\n arr[b] = 0\n print(sum([x * y for x, y in arr.items()]))", 'from collections import defaultdict\nfrom collections import Counter\nfrom numba import jit\n\nn = int(input())\na = list(map(int, input().split()))\narr = defaultdict(int)\nq = int(input())\nbc = []\nfor _ in range(q):\n b, c = map(int, input().split())\n bc.append((b, c))\n\n\n@jit\ndef solve(n, a, arr, q, bc):\n for k, v in Counter(a).items():\n arr[k] = v\n\n q = int(input())\n\n for b, c in bc:\n arr[c] += arr[b]\n arr[b] = 0\n print(sum([x * y for x, y in arr.items()]))\n\n\nsolve(n, a, arr, q, bc)', 'from collections import defaultdict\nfrom collections import Counter\n\nn = int(input())\na = list(map(int, input().split()))\narr = defaultdict(int)\nfor k, v in Counter(a).items():\n arr[k] = v\nq = int(input())\nbc = []\nfor _ in range(q):\n b, c = map(int, input().split())\n bc.append((b, c))\n\nwhole = sum([x * y for x, y in arr.items()])\n\nfor b, c in bc:\n arr[c] += arr[b]\n tmp = arr[b]\n arr[b] = 0\n whole += (c - b) * tmp\n print(whole)'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s506051459', 's678512503', 's753081502', 's506457043'] | [136336.0, 126728.0, 136564.0, 36052.0] | [1254.0, 1748.0, 1190.0, 414.0] | [562, 536, 525, 454] |
p02630 | u864202285 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\ndata = [0] * 100001\n\ndef my_sum(d):\n retval = 0\n\n for i in range(len(d)):\n if d[i] == 0:\n continue\n retval += d[i] * i\n return retval\n\nfor i in A:\n data[i] += 1\n\nsum_val = my_sum(data)\n\nfor i in range(Q):\n B, C = map(int,input().split())\n\n sum_val = sum_val - (data[B] * B) + ((data[C] + data[B]) * C)\n\n data[C] += data[B]\n data[B] = 0\n\n print(sum_val)\n', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\ndata = [0] * 100001\n\ndef my_sum(d):\n retval = 0\n\n for i in range(len(d)):\n if d[i] == 0:\n continue\n retval += d[i] * i\n return retval\n\nfor i in A:\n data[i] += 1\n\nsum_val = my_sum(data)\n\nfor i in range(Q):\n B, C = map(int,input().split())\n\n sum_val = sum_val - (data[B] * B) + (data[B] * C)\n\n data[C] += data[B]\n data[B] = 0\n\n print(sum_val)\n'] | ['Wrong Answer', 'Accepted'] | ['s156185207', 's719800149'] | [20752.0, 20804.0] | [488.0, 489.0] | [476, 464] |
p02630 | u867069435 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\n\nn = int(input())\ncount = Counter(input().split())\nans = 0\nfor v, c in count.items():\n ans += int(v) * c\nfor i in range(int(input())):\n b, c = input().split()\n if b in count:\n ans -= count.get(b, 0) * int(b)\n count[c] = count[b] + count.get(c, 0)\n count[b] = 0\n ans += count.get(c, 0) * int(c)\n print(ans)', 'from collections import Counter\n\nn = int(input())\ncount = Counter(input().split())\nfor i in range(int(input())):\n b, c = input().split()\n if b in count:\n count[c] = count[b] + count.get(c, 0)\n count[b] = 0\nans = 0\nfor v, c in count.items():\n ans += int(v) * c\nprint(ans)', 'from collections import Counter\n\nn = int(input())\ncount = Counter(input().split())\nans = 0\nfor v, c in count.items():\n ans += int(v) * c\nfor i in range(int(input())):\n b, c = input().split()\n if b in count:\n ans -= count.get(b, 0) * int(b)\n prev = count.get(c, 0)\n count[c] = count[b] + count.get(c, 0)\n count[b] = 0\n ans += (count.get(c, 0) - prev) * int(c)\n print(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s303737846', 's929784409', 's526585918'] | [20388.0, 20520.0, 20620.0] | [535.0, 252.0, 556.0] | [377, 293, 417] |
p02630 | u883040023 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int,input().split()))\nans = sum(a)\n\nimport collections\ncca = collections.Counter(a)\n\nfor i in range(int(input())):\n b,c = map(int,input().split())\n num = cca[b]\n cca[b] = 0\n cca[c] += num \n \n print(ans - num*(b-c))', 'n = int(input())\na = list(map(int,input().split()))\nans = sum(a)\n\nimport collections\ncca = collections.Counter(a)\n\nfor i in range(int(input())):\n b,c = map(int,input().split())\n num = cca[b]\n cca[b] = 0\n cca[c] += num \n ans -= num*(b-c)\n \n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s032219823', 's054193531'] | [23968.0, 24156.0] | [568.0, 569.0] | [262, 271] |
p02630 | u886310677 | 2,000 | 1,048,576 | 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. | ['#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define F first\n#define S second\n\n\n#define all(c) c.begin(), c.end()\n#define rall(c) c.end(), c.begin()\n#define INF (int)1e9\n#define MOD 1000000007\ntypedef long long ll;\ntypedef vector<int> vi;\ntypedef pair<int, int> pi;\ntypedef map<int, int> MPII;\ntypedef set<int> SETI;\n\nconst int mxN = 2e5;\nint a[mxN];\n\nint sum(vector<int> v)\n{\n int s = 0;\n for (int i = 0; i < v.size(); ++i)\n {\n s += v[i];\n }\n return s;\n}\n\nint main()\n{\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n int n;\n cin >> n;\n vi v(n);\n for (auto &x : v)\n cin >> x;\n\n int t;\n cin >> t;\n\n int s = sum(v);\n map<int, int> m;\n for (auto x : v)\n if (m.find(x) != m.end())\n m[x] += 1;\n else\n m[x] = 1;\n while (t--)\n {\n int b, c;\n cin >> b >> c;\n if (m.find(c) != m.end())\n m[c] += m[b];\n else\n m[c] = m[b];\n s += ((c - b) * m[b]);\n m[b] = 0;\n cout << s << "\\n";\n }\n\n return 0;\n}', 'from collections import Counter\nn = int(input())\nar = list(map(int, input().split()))\n\nt = int(input())\nc = Counter(ar)\ns = sum(ar)\nfor i in range(t):\n a, b = list(map(int, input().split()))\n if b in c:\n c[b] += c[a]\n else:\n c[b] = c[a]\n s += ((b-a)*c[a])\n print(s)\n c[a] = 0\n'] | ['Runtime Error', 'Accepted'] | ['s950867203', 's832924020'] | [8932.0, 24012.0] | [24.0, 590.0] | [1099, 308] |
p02630 | u891516200 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\nimport copy\n\nN = int(input())\n\ntarget_list = map(int, input().split())\ntrans_list = {}\n\nfor i in range(int(input())):\n trans_list[i] = list(map(int, input().split()))\n\ncheck = []\ncheck.append(Counter(target_list))\nanswer = []\n\nfor index, trans in trans_list.items():\n if trans[0] in check[index].keys():\n result = copy.deepcopy(check[index])\n if trans[1] in result:\n result[trans[1]] = result[trans[1]] + result.pop(trans[0])\n else:\n result[trans[1]] = result.pop(trans[0])\n else:\n result = copy.deepcopy(check[index])\n check.append(Counter(result))\n\nfor r in check:\n print(sum([x * y for x, y in r.items()]))\n', 'N = int(input())\n\ntarget_list = map(int, input().split())\ntrans_list = {}\n\nfor i in range(int(input())):\n trans_list[i] = list(map(int, input().split()))\n\nresult = {}\n\nfor target in target_list:\n print(result)\n for key, trans in trans_list.items():\n if target == trans[0]:\n target = trans[1]\n\n if key in result:\n result[key] = result[key] + target\n else:\n result[key] = target\n\n\nfor r in result.values():\n print(r)\n', 'from collections import Counter\n\nN = int(input())\n\ntarget_list = list(map(int, input().split()))\ncheck = Counter(target_list)\nresult = sum(target_list)\n\n\nfor index in range(int(input())):\n B, C = map(int, input().split())\n if B in check:\n result = result + (check[B]) * (C - B)\n if C in check:\n check[C] = check[C] + check[B]\n else:\n check[C] = check[B]\n check[B] = 0\n print(result)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s186771128', 's474149436', 's570040014'] | [145932.0, 129260.0, 21440.0] | [2211.0, 2389.0, 553.0] | [707, 481, 442] |
p02630 | u898967808 | 2,000 | 1,048,576 | 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. | ['n =int(input())\nA = list(map(int,input().split()))\nq = int(input())\n\nfrom collections import defaultdict\ndic = defaultdict(int)\nfor a in A:\n dic[a] += 1 \n \nans = sum(A)\nfor i in range(q): \n b,c = map(int,input().split())\n dic[c] += dic[b]\n diff = dic[c]*c-dic[b]*b\n ans += diff\n print(ans) \n dic[b] = 0 ', 'n =int(input())\nA = list(map(int,input().split()))\nq = int(input())\n\nfrom collections import defaultdict\ndic = defaultdict(int)\nfor a in A:\n dic[a] += 1 \n \nans = sum(A)\nfor i in range(q): \n b,c = map(int,input().split())\n \n diff = dic[b]*c-dic[b]*b\n dic[c] += dic[b]\n ans += diff\n print(ans) \n dic[b] = 0 '] | ['Wrong Answer', 'Accepted'] | ['s638529518', 's738087346'] | [24000.0, 23844.0] | [566.0, 557.0] | [316, 319] |
p02630 | u900968659 | 2,000 | 1,048,576 | 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. | ['# -*- coding: utf-8 -*-\nn=int(input())\nnumlista=list(map(int,input().split()))\n\nstra=str()\nfor i in numlista:\n stra+=str(i)\n\nsuma=0\nfor i in range(n):\n suma+=numlista[i]\n#\nq=int(input())\nfor i in range(q):\n b,c=map(int,input().split())\n k=c-b\n o=stra.count(str(b))\n suma+=k*o\n print(suma)', '# -*- coding: utf-8 -*-\nn=int(input())\nnumlista=map(int,input().split())\n\nsuma=0\nfor i in range(n):\n suma+=numlista[i]\n#\n#q=int(input())\n\n# b,c=int(input().split())\n# k=c-b\nprint(numlista)\nprint(suma)', '# -*- coding: utf-8 -*-\nn=int(input())\nnumlista=list(map(int,input().split()))\nimport collections\nnumkosuu=collections.Counter(numlista)\nsuma=0\nfor i in numlista:\n suma+=i\nq=int(input())\nfor i in range(q):\n b,c=map(int,input().split())\n\n suma+=(c-b)*numkosuu[b]\n\n numkosuu[c]+=numkosuu[b]\n numkosuu[b]=0\n print(suma)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s699072619', 's950931196', 's029901326'] | [20836.0, 17104.0, 23784.0] | [2206.0, 36.0, 549.0] | [341, 245, 384] |
p02630 | u901144784 | 2,000 | 1,048,576 | 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. | ['n=int(input())\nl=[int(i) for i in input().split()]\ns=sum(l)\nd={}\nfor i in range(n):\n if(l[i] in d):\n d[i]+=1\n else:\n d[i]=1\nq=int(input())\nfor w in range(q):\n b,c=(int(i) for i in input().split())\n if(b in d):\n s-=((d[b]*b)+(d[b]*c))\n d[c]=d[b]\n d[b]=0\n print(s)', 'n=int(input())\nl=[int(i) for i in input().split()]\ns=sum(l)\nd={}\nfor i in range(n):\n if(l[i] in d):\n d[l[i]]+=1\n else:\n d[l[i]]=1\nq=int(input())\nfor w in range(q):\n b,c=(int(i) for i in input().split())\n if(b in d):\n s-=(d[b]*b)\n s+=(d[b]*c)\n if(c in d):\n d[c]+=d[b]\n else:\n d[c]=d[b]\n d[b]=0\n print(s)'] | ['Runtime Error', 'Accepted'] | ['s340243090', 's108704108'] | [20648.0, 21288.0] | [440.0, 542.0] | [282, 342] |
p02630 | u907403674 | 2,000 | 1,048,576 | 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. | ['import collections\nn = int(input())\nl = list(map(int, input().split()))\na = int(input())\nc = collections.Counter(l)\nanswer = sum(l)\nfor i in range(a):\n j,k = map(int, input().split())\n save = c[j]\n del c[j]\n c[k] += save\n answer = answer + c[k] -save\n print(answer)\n', 'import collections\nn = int(input())\nl = list(map(int, input().split()))\na = int(input())\nc = collections.Counter(l)\nanswer = sum(l)\nfor i in range(a):\n j,k = map(int, input().split())\n save = c[j]\n del c[j]\n c[k] += save\n answer = answer + k*save - j*save\n print(answer)\n'] | ['Wrong Answer', 'Accepted'] | ['s089776082', 's052474223'] | [23980.0, 24044.0] | [585.0, 584.0] | [285, 290] |
p02630 | u907865484 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\n\ncnt_dict = {}\n\n\ns = sum(A)\n\nans = 0\n\nfor item in A:\n if item not in cnt_dict:\n cnt_dict[item] = 0\n cnt_dict[item] += 1\n\nfor _ in range(Q):\n X,Y = map(int,input().split())\n\n if X not in cnt_dict:\n cnt_dict[X] = 0\n if Y not in cnt_dict:\n cnt_dict[Y] = 0\n\n s -= cnt_dict[X] * X\n s += cnt_dict[Y] * Y\n\n cnt_dict[X] += cnt_dict[Y]\n cnt_dict[Y] = 0\n\n print(s)\n\n\n\n\n\n\n', 'N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\n\ncnt_dict = {}\n\n\ns = sum(A)\n\nans = 0\n\nfor item in A:\n if item not in cnt_dict:\n cnt_dict[item] = 0\n cnt_dict[item] += 1\n\nfor _ in range(Q):\n X,Y = map(int,input().split())\n\n if X not in cnt_dict:\n cnt_dict[X] = 0\n if Y not in cnt_dict:\n cnt_dict[Y] = 0\n\n s -= cnt_dict[X] * X\n s += cnt_dict[X] * Y\n\n cnt_dict[Y] += cnt_dict[X]\n cnt_dict[X] = 0\n\n\n print(s)\n\n\n\n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s324076737', 's385969236'] | [23204.0, 23180.0] | [563.0, 544.0] | [798, 799] |
p02630 | u910426639 | 2,000 | 1,048,576 | 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. | ['N = int(input())\nA = list(map(int, input().split()))\n\nQ = int(input())\n\ns = sum(A)\n\nfor i in range(Q):\n b, c = map(int, input().split())\n diff = c - A[b - 1]\n A[b - 1] = c\n diff\n print(s)\n', 'N = int(input())\nA = list(map(int, input().split()))\n\nQ = int(input())\n\ns = sum(A)\n\nfor i in range(Q):\n b, c = map(int, input().split())\n diff = c - A[b - 1]\n A[b - 1] = c\n s += diff\n print(s)\n', 'N = int(input())\nA = list(map(int, input().split()))\nma = [0] * (100000 + 1)\n\nfor i in range(N):\n ma[A[i]] += 1\n\nQ = int(input())\n\ns = sum(A)\n\nfor i in range(Q):\n b, c = map(int, input().split())\n diff = c * ma[b] - ma[b] * b\n ma[c] += ma[b]\n ma[b] = 0\n s += diff\n print(s)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s811581526', 's878706016', 's567668613'] | [8836.0, 20864.0, 20808.0] | [26.0, 482.0, 482.0] | [204, 208, 295] |
p02630 | u916205307 | 2,000 | 1,048,576 | 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. | ['x = int(input())\nar = list(map(int, input().split()))\nsum_val = sum(ar)\n\nunique_val = dict()\n\nfor i in ar:\n if i in unique_val:\n unique_val[i] += 1\n else:\n unique_val[i] = 1\n\nq = int(input())\nwhile(q):\n a, b = map(int, input().split())\n if a in unique_val:\n value = (b-a)*unique_val[a]\n sum_val += value\n unique_val[b] = unique_val.pop(a)\n \n print(sum_val)\n q -= 1\n\nprint(sum_val)\n\n\n\n\n', 'x = int(input())\nar = list(map(int, input().split()))\nsum_val = sum(ar)\n\nunique_val = dict()\n\nfor i in ar:\n if i in unique_val:\n unique_val[i] += 1\n else:\n unique_val[i] = 1\n\nq = int(input())\nwhile(q):\n a, b = map(int, input().split())\n if a in unique_val:\n value = (b-a)*unique_val[a]\n sum_val += value\n if b in unique_val:\n unique_val[b] = unique_val[b] + unique_val.pop(a)\n else:\n unique_val[b] = unique_val.pop(a)\n print(unique_val)\n \n print(sum_val)\n q -= 1\n\nprint(sum_val)', 'x = int(input())\nar = list(map(int, input().split()))\nsum_val = sum(ar)\n\nunique_val = dict()\n\nfor i in ar:\n if i in unique_val:\n unique_val[i] += 1\n else:\n unique_val[i] = 1\n\nq = int(input())\nwhile(q):\n a, b = map(int, input().split())\n if a in unique_val:\n value = (b-a)*unique_val[a]\n sum_val += value\n if b in unique_val:\n unique_val[b] = unique_val[b] + unique_val.pop(a)\n else:\n unique_val[b] = unique_val.pop(a)\n \n \n print(sum_val)\n q -= 1\n\n\n\n\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s540897360', 's789134959', 's074367463'] | [21008.0, 147500.0, 20920.0] | [509.0, 2154.0, 520.0] | [445, 574, 564] |
p02630 | u923662841 | 2,000 | 1,048,576 | 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. | ['\n\ndef main():\n n, *i = map(int, open(0).read().split())\n a = i[:n]\u3000\u3000#数列Aのリスト\n _ = i[n]\u3000\u3000\u3000#Qのこと\n s = sum(a)\u3000\u3000#数列Aの総和\n\n m = [0] * (10 ** 5 + 1)\u3000\u3000#Aは1<A<10^5なのでラベル用リストを作成\n for x in a:\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000#Aの個数をラベル化。リストmは個数を記録している\n m[x] += 1\n\n ans = []\n for b, c in zip(*[iter(i[n + 1:])] * 2):\n m[c] += m[b]\u3000\u3000\u3000\u3000\u3000\u3000#cの個数にbの個数を足し算\n s += (c - b) * m[b]\u3000\u3000#s:数列Aの総和に、(c-b)×(bの個数)を足し算\n m[b] = 0\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000#bの個数はゼロに\n ans.append(s)\u3000\u3000\u3000\u3000\u3000\u3000#リストansにSの変化を記録していく\n\n print("\\n".join(map(str, ans)))\n\n\nif __name__ == \'__main__\':\n main()', 'def main():\n n, *i = map(int, open(0).read().split())\n a = i[:n]\n _ = i[n]\n s = sum(a)\n\n m = [0] * (10 ** 5 + 1)\n for x in a:\n m[x] += 1\n\n ans = []\n for b, c in zip(*[iter(i[n + 1:])] * 2):\n m[c] += m[b]\n s += (c - b) * m[b]\n m[b] = 0\n ans.append(s)\n\n print("\\n".join(map(str, ans)))\n\nif __name__ == \'__main__\':\n main()'] | ['Runtime Error', 'Accepted'] | ['s120799947', 's132265373'] | [8804.0, 44004.0] | [23.0, 147.0] | [861, 384] |
p02630 | u932868243 | 2,000 | 1,048,576 | 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. | ['n=int(input())\na=list(map(int,input().split()))\nq=int(input())\nnuml=[0 for i in range(10**5+1)]\ns=sum(a)\nfor aa in a:\n numl[aa-1]+=1\n\nfor qq in range(q):\n x,y=map(int,input().split())\n s+=numl[x-1]*(y-x)\n print(s)\n numl[y-1]+=numl[x-1]\n numl[x-1]=0\n print(numl)', 'import collections\nn=int(input())\na=list(map(int,input().split()))\nq=int(input())\nnuml=collections.Counter(a)\ns=sum(a)\nfor qq in range(q):\n x,y=map(int,input().split())\n s+=numl[x]*(y-x)\n print(s)\n numl[y]+=numl[x]\n numl[x]=0\n '] | ['Wrong Answer', 'Accepted'] | ['s954523176', 's410813352'] | [144016.0, 23992.0] | [2382.0, 582.0] | [268, 233] |
p02630 | u934119021 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int, input().split()))\nfor i in range(n):\n dic[a[i]] += 1\nq = int(input())\nans = [sum(a)]\nfor i in range(q):\n b, c = map(int, input().split())\n ans.append(ans[-1] + (c - b) * dic[b])\n dic[c] += dic[b]\n dic[b] = 0\nfor i in range(1, q + 1):\n print(ans[i])', 'k = [i for i in range(1, 10 ** 5 + 1)]\nv = [0] * (10 ** 5)\ndic = {key: val for key, val in zip(k, v)}\nn = int(input())\na = list(map(int, input().split()))\nfor i in range(n):\n dic[a[i]] += 1\nprint(dic)\nq = int(input())\nans = [sum(a)]\nfor i in range(q):\n b, c = map(int, input().split())\n ans.append(ans[-1] + (c - b) * dic[b])\n print(dic[b])\n print(dic[c])\n dic[c] += dic[b]\n dic[b] = 0\nfor i in range(1, q + 1):\n print(ans[i])', 'k = [i for i in range(1, 10 ** 5 + 1)]\nv = [0] * (10 ** 5)\ndic = {key: val for key, val in zip(k, v)}\nn = int(input())\na = list(map(int, input().split()))\nfor i in range(n):\n dic[a[i]] += 1\nq = int(input())\nans = [sum(a)]\nfor i in range(q):\n b, c = map(int, input().split())\n ans.append(ans[-1] + (c - b) * dic[b])\n dic[c] += dic[b]\n dic[b] = 0\nfor i in range(1, q + 1):\n print(ans[i])'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s642420695', 's953508504', 's485606512'] | [20896.0, 30704.0, 30664.0] | [48.0, 661.0, 370.0] | [289, 434, 391] |
p02630 | u944325914 | 2,000 | 1,048,576 | 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. | ['n=int(input())\na=list(map(int,input().split()))\nq=int(input())\nfor i in range(q):\n b,c = map(int,input().split())\n a=[c if i==b else i for i in a]\n print(a)\n print(sum(a))', 'from collections import Counter\nn=input()\na=list(map(int,input().split()))\nb=Counter(a)\nn=int(input())\nans=sum(a)\nfor i in range(n):\n x,y=map(int,input().split())\n ans+=b[x]*(y-x)\n print(ans)\n b[y]+=b[x]\n b[x]=0'] | ['Wrong Answer', 'Accepted'] | ['s836944865', 's823373927'] | [145628.0, 24140.0] | [3533.0, 572.0] | [175, 226] |
p02630 | u944886577 | 2,000 | 1,048,576 | 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. | ['n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\n \nq=int(input())\nans=0\n \nfor j in range(q):\n x,y=map(int,input().split())\n sum+=(y-x)*cnt[x]\n cnt[x]+=cnt[y]\n cnt[y]=0\n print(sum)', 'n=int(input())\ns=[]\ns=input().split()\nq=int(input())\nfor i in range(q):\n x,y=map(int,input().split())\n s=re.sub(x,y,s)\n\nfor j in range(q)\n ans+=int(s[j])\n\nprint(ans)', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\nq=int(input())\nans=0\n\nfor j in range(q):\n x,y=map(int,input().split())\n ans=-(x-y)*cnt[x]+sum\n print(ans)\n cnt[x]+=cnt[y]\n cnt[y]=0', 'n=int(input())\ns=str(input())\nq=int(input())\n \nfor i in range(q):\n x,y=map(str, input().split())\n s.replace(x,y)\n ans=0 \n s_list=list(s.split())\n for j in range(q+1):\n ans+=int(s_list[j])\n print(ans)', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\n \nq=int(input())\nans=0\n \nfor j in range(q):\n x,y=map(int,input().split())\n sum+=(y-x)*cnt[x]\n cnt[x]+=cnt[y]\n cnt[y]=0\n print(sum)', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\nq=int(input())\nans=0\n\nfor j in range(q):\n x,y=map(int,input().split())\n ans=-(x-y)*cnt[x]+sum\n cnt[x]+=cnt[y]\n print(ans)', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\nq=int(input())\nans=0\n \nfor j in range(q):\n x,y=map(int,input().split())\n sum+=(x-y)*cnt[x]\n print(sum)\n cnt[x]+=cnt[y]\n cnt[y]=0', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\nq=int(input())\nans=0\n\nfor j in range(q):\n x,y=map(int,input().split())\n ans=-(x-y)*cnt[x]+sum\n print(ans)', 'import re\nn=int(input())\ns=str(input())\nq=int(input())\n \nfor i in range(q):\n x,y=map(str, input().split())\n s=re.sub(x,y,s)\n print(s)\n ans=0 \n s_list=list(s.split())\n for j in range(q+1):\n ans+=int(s_list[j])\n print(ans)', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\nq=int(input())\nans=0\n \nfor j in range(q):\n x,y=map(int,input().split())\n sum+=(x-y)*cnt[x]\n print(ans)\n cnt[x]+=cnt[y]', 'n=int(input())\ns=[]\ns=input().split()\nq=int(input())\nfor i in range(q):\n x,y=map(int,input().split())\n s=re.sub(x,y,s)\n \nfor j in range(q):\n ans+=int(s[j])\n \nprint(ans)', 'n=int(input())\ns=str(input())\nq=int(input())\n \nfor i in range(q):\n x,y=map(str, input().split())\n s.replace(x,y)\nans=0 \ns_list=list(s.split())\nfor j in range(q):\n ans+=int(s_list[j])\n \nprint(ans)', 'import re\nn=int(input())\ns=[]\ns=input().split()\nq=int(input())\n\nfor i in range(q):\n x,y=map(str, input().split())\n s=re.sub(str(x),str(y),str(s))\n \nfor j in range(q):\n ans+=int(s[j])\n \nprint(ans)', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\n \nq=int(input())\nans=0\n \nfor j in range(q):\n x,y=map(int,input().split())\n sum+=(y-x)*cnt[x]\n cnt[y]+=cnt[x]\n cnt[y]=0\n print(sum)', 'n=int(input())\ns=str(input())\nq=int(input())\n \nfor i in range(q):\n x,y=map(str, input().split())\n s.replace(x,y)\nans=0 \ns_list=list(s.split())\nfor j in range(q+1):\n ans+=int(s_list[j])\n \nprint(ans)', 'n=int(input())\na_list=list(map(int,input().split()))\ncnt = [0] * int(1e5 + 10)\nsum=0\nfor i in a_list:\n cnt[i] +=1\n sum+=i\n \nq=int(input())\nans=0\n \nfor j in range(q):\n x,y=map(int,input().split())\n sum+=(y-x)*cnt[x]\n cnt[y]+=cnt[x]\n cnt[x]=0\n print(sum)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s017448841', 's040894262', 's100654756', 's154309261', 's329950624', 's465524167', 's466969409', 's663210348', 's679934959', 's802188482', 's805599397', 's806985928', 's808984935', 's900948368', 's966269187', 's497461727'] | [21028.0, 8972.0, 20988.0, 18316.0, 20852.0, 83732.0, 20924.0, 20660.0, 19476.0, 56336.0, 16860.0, 10656.0, 52116.0, 21032.0, 10572.0, 21084.0] | [485.0, 25.0, 505.0, 95.0, 489.0, 2308.0, 487.0, 487.0, 70.0, 597.0, 34.0, 2206.0, 2206.0, 490.0, 2206.0, 490.0] | [253, 165, 253, 201, 253, 243, 250, 227, 221, 240, 168, 195, 195, 253, 197, 253] |
p02630 | u950825280 | 2,000 | 1,048,576 | 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. | ["n = int(input())\na = list(map(int, input().split()))\nq = int(input())\n\ns = ','.join(map(str, a)) + ','\nans = []\n\nfor _ in range(q):\n b, c = map(str, input().split())\n s = s.replace(b+',', c+',')\n ans.append(s)\n \nfor i in ans:\n print(i[:-1])\n print(sum(int(str) for str in i[:-1].split(',')))\n ", 'n = int(input())\na = list(map(str, input().split()))\n\nd = {}\nt = 0\nfor i in a:\n if not i in d.keys():\n d[i] = 1\n else:\n d[i] += 1\n t += int(i)\n\nq = int(input())\n\nfor _ in range(q):\n b, c = map(str, input().split())\n diff = 0\n if b in d.keys() and c in d.keys():\n diff = (int(c) - int(b)) * d[b]\n d[c] += d[b]\n d.pop(b)\n elif b in d.keys():\n diff = int(c) * d[b] - int(b) * d[b]\n d[c] = d[b]\n d.pop(b)\n t += diff\n print(t)\n '] | ['Wrong Answer', 'Accepted'] | ['s130001381', 's672429932'] | [795144.0, 22980.0] | [2231.0, 587.0] | [314, 509] |
p02630 | u953379577 | 2,000 | 1,048,576 | 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. | ['import collections as c\n\nn = int(input())\n\na = list(map(int,input().split()))\n\nq = int(input())\n\ns = sum(a)\n\ncnt = c.Counter(a)\n\nfor i in range(q):\n b,c = map(int,input().split())\n s += (c-b)*cnt[b-1]\n cnt[c-1] += cnt[b-1]\n cnt[b-1] = 0\n print(s)', 'import collections as c\n\nn = int(input())\n\na = list(map(int,input().split()))\n\nq = int(input())\n\ns = sum(a)\n\ncnt = c.Counter(a)\n\nfor i in range(q):\n b,c = map(int,input().split())\n s += (c-b)*cnt[b]\n cnt[c] += cnt[b]\n cnt[b] = 0\n print(s)'] | ['Wrong Answer', 'Accepted'] | ['s407349910', 's674077815'] | [24108.0, 24016.0] | [605.0, 566.0] | [261, 253] |
p02630 | u968404618 | 2,000 | 1,048,576 | 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. | ['from collections import *\nfrom operator import mul\n\nn = int(input())\nA = list(map(int, input().split()))\nq = int(input())\n\n\nA_dic = Counter(A)\nA_sum = sum(A)\n\nfor _ in range(q):\n b, c = map(int, input().split())\n tmp = A_dic[b]\n A_dic[c] += tmp\n A_dic[b] = 0\n A_sum += c*A_dic[c] - b*tmp\n print(A_sum)', 'from collections import Counter\n\nn = int(input())\nA = list(map(int, input().split()))\nq = int(input())\n\nA_dic = Counter(A)\nA_sum = sum(A)\n\nfor _ in range(q):\n b, c = map(int, input().split())\n tmp = A_dic[b]\n A_dic[c] += tmp\n A_dic[b] = 0\n A_sum += tmp * (c-b)\n print(A_sum)'] | ['Wrong Answer', 'Accepted'] | ['s569439080', 's781982781'] | [24072.0, 24184.0] | [567.0, 574.0] | [319, 292] |
p02630 | u978313283 | 2,000 | 1,048,576 | 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. | ['import numpy as np\nN=int(input())\nA=list(map(int,input().split()))\nSUM=sum(A)\nQ=int(input())\nindex=np.array([i for i in range(10**5+1)])\nList=np.array([0 for _ in range(10**5+1)])\nfor a in A:\n List[a]+=1\nBList=np.array([0 for _ in range(10**5+1)])\nfor q in range(Q):\n B,C=map(int,input().split())\n BList[B]+=C-B\n print(np.sum(BList*List)+SUM)', 'import numpy as np\nN=int(input())\nA=list(map(int,input().split()))\nSUM=sum(A)\nQ=int(input())\nList=np.array([0 for _ in range(10**5+1)])\nfor a in A:\n List[a]+=1\nfor q in range(Q):\n B,C=map(int,input().split())\n SUM-=B*List[B]\n SUM+=C*List[B]\n List[C]+=List[B]\n List[B]=0\n print(SUM)'] | ['Wrong Answer', 'Accepted'] | ['s122003638', 's296954422'] | [39072.0, 38224.0] | [2206.0, 783.0] | [354, 302] |
p02630 | u981418135 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nsums = sum(a)\nd = {}\n\nfor i in a:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\n\nfor i in range(q):\n b,c = map(int, input().split())\n if b in d:\n sums += d[b]*(c-b)\n if c in d:\n d[c] += d[b]\n else:\n d[c] = d[b]\n \t\td[b] = 0\n print(sums)', 'd = {}\n\nfor i in a:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\n\nfor i in range(q):\n b,c = map(int, input().split())\n if b in d:\n sums += d[b]*(c-b)\n if c in d:\n d[c] += d[b]\n else:\n d[c] = d[b]\n \n print(sums)', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nsums = sum(a)\nd = {}\n\nfor i in a:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\n\nfor i in range(q):\n b,c = map(int, input().split())\n if b in d:\n sums += d[b]*(c-b)\n if c in d:\n d[c] += d[b]\n else:\n d[c] = d[b]\n d[b] = 0\n print(sums)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s186336065', 's420411480', 's256344058'] | [8988.0, 9124.0, 20620.0] | [28.0, 24.0, 527.0] | [356, 262, 360] |
p02630 | u984592063 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\nn = int(input())\na=list(map(int,input().split()))\nq = int(input())\nbc=[list(map(int,input().split())) for _ in range(q)]\n\na_c = Counter(a)\n\n', 'from collections import Counter\nn = int(input())\na=list(map(int,input().split()))\nq = int(input())\nbc=[list(map(int,input().split())) for _ in range(q)]\n\na_c = Counter(a)\na_sum = sum(a)\nfor i in range(q):\n if bc[i][0] in a_c:\n a_sum += a_c[bc[i][0]] * (bc[i][1] - bc[i][0])\n if bc[i][1] in a_c:\n a_c[bc[i][1]] += a_c[bc[i][0]]\n else:\n a_c[bc[i][1]] = a_c[bc[i][0]]\n a_c[bc[i][0]] = 0\n else:\n a_sum = a_sum\n print(a_sum)\n'] | ['Wrong Answer', 'Accepted'] | ['s831547326', 's731089053'] | [36244.0, 36248.0] | [245.0, 430.0] | [172, 486] |
p02630 | u989074104 | 2,000 | 1,048,576 | 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. | ['N=int(input())\nlistA=list(map(int, input().split()))\nQ=int(input())\n\nlistB=[] \nwhile True:\n try:\n listB.append(list(map(int,input().split())))\n\n except:\n break;\n \nsum=sum(listA)\nnumlist=[0]*(10**5+1)\nfor i in range(10**5+1):\n numlist[i]=listA.count(i)\n \nfor i in range(Q):\n B=listB[i][0]\n C=listB[i][1]\n sum=sum+(C-B)*numlist[B]\n print(C)\n numlist[C]+=numlist[B]\n numlist[B]=0\n # print(numlist)\n print(sum)\n', 'N=int(input())\nlistA=list(map(int, input().split()))\nQ=int(input())\n\nlistB=[] \nwhile True:\n try:\n listB.append(list(map(int,input().split())))\n\n except:\n break;\n \nsum=sum(listA)\nnumlist=[0]*(10**5+1)\nfor i in listA:\n numlist[i]+=1\n \nfor i in range(Q):\n B=listB[i][0]\n C=listB[i][1]\n if numlist[B]!=0:\n sum=sum+(C-B)*numlist[B]\n # print(C)\n numlist[C]+=numlist[B]\n numlist[B]=0\n # print(numlist)\n print(sum)\n'] | ['Wrong Answer', 'Accepted'] | ['s002221058', 's643096600'] | [32484.0, 31900.0] | [2207.0, 334.0] | [478, 489] |
p02630 | u991619971 | 2,000 | 1,048,576 | 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. | ['#import math\n#import numpy as np\n#import torch\n#import torch.nn as nn\n#import matplotlib.pyplot as plt\n#from decimal import Decimal\n#import itertools\nimport collections\n\nN=int(input())\n#N,K = map(int,input().split())\n#B,W = map(int,input().split())\n#T=int(input())\nA = list(map(int,input().split()))\n#S=str(input())\n#A=[p for p in range(2*10**5)]\nQ=int(input())\nc=collections.Counter(A)\ns=sum(A)\nfor i in range(Q):\n #print(A)\n B,C = map(int,input().split())\n print(c[B])\n if c[B]:\n s += (C-B)*c[B]\n c[C] += c[B]\n c[B] = 0\n\n print(s)\n', '#import math\n#import numpy as np\n#import torch\n#import torch.nn as nn\n#import matplotlib.pyplot as plt\n#from decimal import Decimal\n#import itertools\nimport collections\n\nN=int(input())\n#N,K = map(int,input().split())\n#B,W = map(int,input().split())\n#T=int(input())\nA = list(map(int,input().split()))\n#S=str(input())\n#A=[p for p in range(2*10**5)]\nQ=int(input())\nc=collections.Counter(A)\ns=sum(A)\nfor i in range(Q):\n #print(A)\n B,C = map(int,input().split())\n if c[B]:\n s += (C-B)*c[B]\n c[C] += c[B]\n c[B] = 0\n\n print(s)\n'] | ['Wrong Answer', 'Accepted'] | ['s847413979', 's891924518'] | [21412.0, 21368.0] | [576.0, 522.0] | [569, 553] |
p02631 | u001769145 | 2,000 | 1,048,576 | 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. | ['# ABC171 E \n\nimport itertools\n\nn = int(input())\na_l = [list(format(int(x), "030b")) for x in input().split()]\n\nfor _d,_tp in enumerate(zip(*a_l)):\n if "1" not in _tp:\n continue\n if "0" not in _tp:\n continue\n else:\n _num = _tp.count("0")\n if _num % 2 == 1:\n for i in range(n):\n if a_l[i][_d] == "0":\n a_l[i][_d] == "1"\n else:\n a_l[i][_d] == "0"\n\nprint(*[int("".join(x), 2) for x in a_l])', '# ABC171 E \n\nimport itertools\n\nn = int(input())\na_l = [list(format(int(x), "030b")) for x in input().split()]\n\nfor _d,_tp in enumerate(zip(*a_l)):\n if "1" not in _tp:\n continue\n if "0" not in _tp:\n continue\n else:\n _num = _tp.count("0")\n if _num % 2 == 1:\n for i in range(n):\n if a_l[i][_d] == "0":\n a_l[i][_d] = "1"\n else:\n a_l[i][_d] = "0"\n\nprint(*[int("".join(x), 2) for x in a_l])'] | ['Wrong Answer', 'Accepted'] | ['s459208558', 's734575708'] | [87720.0, 87708.0] | [1817.0, 1612.0] | [502, 500] |
p02631 | u004482945 | 2,000 | 1,048,576 | 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. | ["n = int(input())\na = list(map(int, input().split()))\nans = 0\nans_list = []\nfor i in a:\n s = str(bin(i))\n s = s[2:]\n ans_list.append(int(s))\n ans += int(s)\nz = []\nfor i in ans_list:\n z.append(ans - i)\nf = []\nfor i in z:\n e = []\n for j in str(i):\n if int(j) % 2 == 0:\n j = 0\n if int(j) % 2 == 1:\n j = 1\n e.append(str(j))\n f.append(''.join(e))\nh = []\nfor i in f:\n h.append(int(i, 2))\nprint(h)", "n = int(input())\na = list(map(int, input().split()))\nx = 0\nfor i in a:\n x ^= i\nans = [x^i for i in a]\nprint(' '.join(map(str, ans)))\n "] | ['Wrong Answer', 'Accepted'] | ['s509842121', 's946504198'] | [49140.0, 41768.0] | [2207.0, 140.0] | [417, 136] |
p02631 | u014800961 | 2,000 | 1,048,576 | 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. | ['n = int(input())\nalist = list(map(int,input().split()))\n\nfrom itertools import combinations\n \nperm = combinations(alist,len(alist)-1)\n\nans = []\nfor i in perm:\n xor = 0 \n for j in i:\n xor ^= j\n ans.append(xor)\n\nprint(" ".join(str(x) for x in ans))', 'n = int(input())\nalist = list(map(int,input().split()))\n\ns = 0\nfor i in alist:\n s ^= i\n\nans = []\nfor i in alist:\n ans.append(s ^ i)\n\nprint(" ".join(str(x) for x in ans))'] | ['Wrong Answer', 'Accepted'] | ['s896427453', 's976036223'] | [31452.0, 41784.0] | [2206.0, 168.0] | [263, 175] |
p02631 | u026155812 | 2,000 | 1,048,576 | 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. | ["N = int(input())\na = [int(i) for i in input().split()]\nans = []\nfor x in a:\n s = '1'*(len(str(x)))\n ans.append(x^int(s))\nprint(*ans)", 'N = int(input())\na = [int(i) for i in input().split()]\nans = []\ns = 0\nfor x in a:\n s = s^x\nfor x in a:\n ans.append(x^s)\nprint(*ans)'] | ['Wrong Answer', 'Accepted'] | ['s366847821', 's142476045'] | [31616.0, 31528.0] | [250.0, 178.0] | [138, 137] |
p02631 | u035044350 | 2,000 | 1,048,576 | 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. | ["import functools\nN = int(input())\nnumbers = list(map(int,input().split()))\nxor = ''\nfor i in range(len(numbers)):\n othersNumbers = numbers[:i] + numbers[i + 1:]\n currentXor = 0\n xor += str(functools.reduce(lambda x,y:x^y,othersNumbers)) + ' '\n \nprint(xor)", "N = int(input())\nnumbers = list(map(int,input().split()))\nxor = ''\nfor i in range(len(numbers)):\n othersNumbers = numbers[:i] + numbers[i + 1:]\n currentXor = 0\n for num in othersNumbers:\n currentXor ^= num\n xor += ' ' + str(currentXor) + ' '\nprint(xor)", 'N=int(input())\na=list(map(int,input().split()))\na_all=0\nfor i in range(N):\n a_all^=a[i]\nans=[]\nfor j in range(N):\n ans.append(a_all^a[j])\nprint(*ans)'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s434175050', 's734912270', 's037331552'] | [31904.0, 31512.0, 31616.0] | [2206.0, 2206.0, 186.0] | [267, 271, 155] |
p02631 | u038404105 | 2,000 | 1,048,576 | 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. | ["n = int(input())\na = list(map(int, input().split()))\nallxor = 0\nfor i in range(n):\n allxor = allxor^a[i]\nans = ''\nfor i in range(n):\n ans= ans +str(allxor^a[i])+' '\nprint(ans)", 'n = int(input())\na = list(map(int, input().split()))\nallxor = 0\nans = [0]*n\nfor i in range(n):\n allxor = allxor^a[i]\nfor i in range(n):\n ans[i] = allxor^a[i]\nansstr = " ".join(map(str,ans))\nprint(ansstr)'] | ['Time Limit Exceeded', 'Accepted'] | ['s560162630', 's745921102'] | [31632.0, 41644.0] | [2206.0, 161.0] | [181, 209] |
p02631 | u076245995 | 2,000 | 1,048,576 | 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. | ['N = int(input())\na = list(map(int, input().split()))\nans = []\nfor i in range(N):\n xor = 0\n for j in range(N):\n if i == j:\n xor ^= a[j]\n ans.append(xor)\nprint(*ans)', 'N = int(input())\na = list(map(int, input().split()))\ns = 0\nfor i in range(N):\n s ^= a[i]\n\nans = []\nfor i in range(N):\n ans.append(a[i] ^ s)\nprint(*ans)'] | ['Wrong Answer', 'Accepted'] | ['s031391835', 's362745048'] | [31604.0, 31568.0] | [2206.0, 169.0] | [190, 157] |
p02631 | u126146165 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int, input().split()))\nb = 0\nfor i in range(n):\n b ^= a[i]\nans = []\nfor i in range(n):\n ap = b ^ a[i]\n ans.append(ap)\nprint(*a)\nprint(*list(set(ans)))\n', 'n = int(input())\na = list(map(int, input().split()))\nb = 0\nfor i in range(n):\n b ^= a[i]\nans = []\nfor i in range(n):\n ap = b ^ a[i]\n ans.append(ap)\n\nprint(*list(set(ans)))\n', 'n = int(input())\na = list(map(int, input().split()))\nb = 0\nfor i in range(n):\n b ^= a[i]\nans = []\nfor i in range(n):\n ap = b ^ a[i]\n ans.append(ap)\n\nprint(*ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s207995763', 's736662845', 's119433354'] | [38496.0, 37576.0, 31636.0] | [288.0, 207.0, 176.0] | [190, 181, 170] |
p02631 | u167681994 | 2,000 | 1,048,576 | 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. | ['n = int(input())\na = list(map(int,input().split()))\n\nxor_a = 0\nfor i in range(n):\n xor_a ^= a[i]\n\nprint(xor_a)\n\nans = []\nfor i in range(n):\n ans.append(a[i] ^ xor_a)\n\nprint(*ans)\n', 'n = int(input())\na = list(map(int,input().split()))\n\nxor_a = 0\nfor i in range(n):\n xor_a ^= a[i]\n\n#print(xor_a)\n\nans = []\nfor i in range(n):\n ans.append(a[i] ^ xor_a)\n\nprint(*ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s995152237', 's192806195'] | [31524.0, 31444.0] | [177.0, 169.0] | [181, 182] |
p02631 | u180812294 | 2,000 | 1,048,576 | 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. | ['def xor_operate(a_list):\n result = 0\n for a in a_list:\n result ^= int(a)\n return str(result)\n\n\n\nif __name__ == "__main__":\n N = input()\n a_list = input()\n\n a_list = a_list.split(" ")\n\n i_list = []\n for i in range(len(a_list)):\n r_list = a_list[:i]+a_list[i+1:]\n i_list.append(xor_operate(r_list))\n return " ".join(i_list)\n \n\n\n \n\n', 'def xor_operate(a_list):\n result = 0\n for a in a_list:\n result ^= int(a)\n return result\n\n\n\nif __name__ == "__main__":\n N = input()\n a_list = input()\n\n a_list = a_list.split(" ")\n\n bit_value = xor_operate(a_list)\n\n i_list = []\n for a in a_list:\n i_list.append(str(bit_value ^ int(a)))\n print(" ".join(i_list))\n \n\n\n \n\n'] | ['Runtime Error', 'Accepted'] | ['s516478553', 's897820736'] | [9116.0, 41736.0] | [24.0, 186.0] | [387, 370] |
p02631 | u194297606 | 2,000 | 1,048,576 | 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. | ['N = int(input())\na = list(map(int, input().split()))\nans = []\ns = 0\nfor i in range(N):\n s = s ^ a[i]\n\nfor i in range(N):\n tmp = s ^ a[i]\n ans.append(tmp)\n \nprint(ans)', "N = int(input())\na = list(map(int, input().split()))\nans = []\ns = 0\nfor i in range(N):\n s = s ^ a[i]\n\nfor i in range(N):\n tmp = s ^ a[i]\n ans.append(str(tmp))\n \nans = ' '.join(ans) \nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s279517087', 's267502946'] | [31588.0, 33636.0] | [146.0, 190.0] | [178, 207] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.