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 | u018776180 | 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())\nalist = [int(s) for s in input().split(" ")]\nadict = {}\nans = 0\nfor a in alist:\n ans += a\n if a in adict:\n adict[a] += 1\n else:\n adict[a] = 1\nq = int(input())\nbclist = []\nfor _ in range(q):\n b, c = [int(s) for s in input().split(" ")]\n bclist.append([b, c])\n\nfor b, c in bclist:\n if c in adict and b in adict:\n ans += c * (adict[c] + adict[b]) - b * adict[b]\n adict[c] += adict[b]\n del adict[b]\n elif b in adict:\n ans += (c - b) * adict[b]\n adict[c] = adict[b]\n del adict[b]\n print(ans)', 'n = int(input())\nalist = [int(s) for s in input().split(" ")]\nadict = {}\nans = 0\nfor a in alist:\n ans += a\n if a in adict:\n adict[a] += 1\n else:\n adict[a] = 1\nq = int(input())\nbclist = []\nfor _ in range(q):\n b, c = [int(s) for s in input().split(" ")]\n bclist.append([b, c])\n\nfor b, c in bclist:\n if c in adict and b in adict:\n ans += (c - b) * adict[b]\n adict[c] += adict[b]\n del adict[b]\n elif b in adict:\n ans += (c - b) * adict[b]\n adict[c] = adict[b]\n del adict[b]\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s952433011', 's630546122'] | [33392.0, 33396.0] | [389.0, 390.0] | [535, 513] |
p02630 | u020472025 | 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())\nlis = np.zeros(10**5)\n\nAs = np.array(input().split()).astype(np.int64)\nNUM = As.sum()\n\nfor n in As:\n lis[n-1] += 1\n\nQ = int(input())\nfor q in range(Q):\n B, C = map(int, input().split())\n nnn = lis[B-1]\n lis[B-1] = 0\n lis[C-1] += nnn\n NUM = NUM - B*nnn + C*nnn\n print(NUM)', 'import numpy as np\n\nN = int(input())\nlis = np.zeros(10**5)\n\nAs = np.array(input().split()).astype(np.int64)\nNUM = As.sum()\n\nfor n in As:\n lis[n-1] += 1\n\nQ = int(input())\nfor q in range(Q):\n B, C = map(int, input().split())\n nnn = lis[B-1]\n lis[B-1] = 0\n lis[C-1] += nnn\n NUM = NUM - B*nnn + C*nnn\n print(int(NUM))'] | ['Wrong Answer', 'Accepted'] | ['s446963267', 's141789526'] | [39948.0, 40052.0] | [864.0, 798.0] | [315, 320] |
p02630 | u021019433 | 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. | ['R = lambda: map(int, input().split())\nR()\na = [0] * 100001\ns = 0\nfor x in R():\n s += x\n a[x] += 1\nq, = R()\nfor _ in range(q):\n b, c = R()\n s += (c - b) * a[b]\n print(s)\n a[c]+=d[b]\n a[b] = 0\n', 'R = lambda: map(int, input().split())\nR()\na = [0] * 100001\ns = 0\nfor x in R():\n s += x\n a[x] += 1\nq, = R()\nfor _ in range(q):\n b, c = R()\n s += (c - b) * a[b]\n print(s)\n a[c]+=a[b]\n a[b] = 0\n'] | ['Runtime Error', 'Accepted'] | ['s652346741', 's559758478'] | [17876.0, 17824.0] | [65.0, 485.0] | [198, 198] |
p02630 | u021387650 | 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())\nnum_list = list(map(int,input().split()))\nq = int(input())\n\nnum_list.sort()\n\nfor i in range(q):\n query = list(map(int,input().split()))\n for j in range(len(num_list)):\n if num_list[j] == query[0]:\n num_list[j] = query[1]\n if num_list[j] > query[0]:\n break\n print(sum(num_list))', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\ntable = [0] * 100001\n\nc = 0\ns = 0\n\nfor i in A:\n table[i] += 1\n s += i\n\nprint(su,s)\n\nfor i in range(Q):\n B, C = map(int,input().split())\n c = table[B]\n s += (C - B) * c\n table[C] += table[B]\n table[B] = 0\n print(s)\n', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\ntable = [0] * 100001\n\nc = 0\ns = 0\n \nfor i in A:\n table[i] += 1\n sum += i\n \nfor i in range(Q):\n B, C = map(int,input().split())\n c = table[B]\n s += (C - B) * c\n table[C] += table[B]\n table[B] = 0\n print(s)\n', 'N = int(input())\nnum_list = list(map(int,input().split()))\nq = int(input())\n\nfor i in range(len(num_list)):\n ans += num_list[i]\n\nfor j in range(q):\n query = list(map(int,input().split()))\n cnt = num_list.count(query)\n ans += (query[1] - query[0]) * cnt\n print(ans)', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\ntable = [0] * 100001\n\nc = 0\ns = 0\n\nfor i in A:\n table[i] += 1\n s += i\n\nfor i in range(Q):\n B, C = map(int,input().split())\n c = table[B]\n s += (C - B) * c\n table[C] += table[B]\n table[B] = 0\n print(s)\n'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s086684542', 's646253731', 's681934638', 's928930061', 's478149757'] | [20800.0, 20928.0, 20960.0, 20864.0, 20816.0] | [2206.0, 77.0, 48.0, 47.0, 495.0] | [313, 309, 303, 269, 296] |
p02630 | u023762741 | 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())\n\nLine = [int(s) for s in input().split()]\nc = collections.Counter(Line)\n\n# print(c)\n\nQ = int(input())\n\n\nfor _ in range(Q):\n Line = [int(s) for s in input().split()]\n try:\n c[Line[1]] += c[Line[0]]\n c.pop(Line[0])\n except:\n print('Error')\n print(c)\n \n s=0\n for i in c:\n # print(i)\n s += i * c[i]\n print(s) ", "import collections\nN = int(input())\n\nLine = [int(s) for s in input().split()]\nc = collections.Counter(Line)\n\n# print(c)\nv = 0\n\nfor i in c:\n # print(i)\n v += i * c[i]\n# print(v) \n\nQ = int(input())\n\n\nfor _ in range(Q):\n Line = [int(s) for s in input().split()]\n try:\n c[Line[1]] += c[Line[0]]\n \n # print(c[Line[1]],c[Line[0]])\n v += c[Line[0]] * (Line[1] - Line[0])\n c.pop(Line[0])\n \n except:\n pass\n \n # print('Error')\n # print(c)\n\n # s=0\n \n # # print(i)\n \n print(v) \n "] | ['Wrong Answer', 'Accepted'] | ['s749329833', 's128049980'] | [58324.0, 23260.0] | [2301.0, 592.0] | [403, 651] |
p02630 | u029399657 | 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()))\nt = int(input())\nwhile t:\n t-=1\n k,r = map(int,input().split())\n arr.sort()\n if k in arr:\n for i in range(n):\n if arr[i]>k:\n break\n if arr[i]==k:\n arr[i]=r\n \n print(arr)\n print(sum(arr))', 'n = int(input())\narr = list(map(int,input().split()))\nt = int(input())\nsu = sum(arr)\nprint(su)\nwhile t:\n t-=1\n k,r = map(int,input().split())\n p = arr.count(k)\n su += (r-k)*p\n print(su)', 'n = int(input())\narr = list(map(int, input().split()))\nsu = sum(arr)\nlst = [0]*100001\nq = int(input())\nfor i in arr:\n lst[i] += 1\nfor _ in range(q):\n b, c = map(int, input().split())\n su += (c - b) * lst[b]\n print(su)\n lst[c] += lst[b]\n lst[b] = 0\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s320577466', 's851370177', 's658700521'] | [139880.0, 20796.0, 20988.0] | [2844.0, 2206.0, 498.0] | [328, 200, 266] |
p02630 | u035044350 | 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())\nnumbers = list(map(int,input().split()))\nnumOfOperation = int(input())\ndic = {}\n\nfor num in numbers:\n if num in dic : dic[num] += 1\n else: dic[num] = 1\n \n\nsums = sum(numbers)\nfor i in range(numOfOperation):\n B,C = map(int,input().split())\n dic[B] = 1\n dic[C] = 0\n sums += dic[B] * (C - B)\n print(sums)\n', 'N = int(input())\nnumbers = list(map(int,input().split()))\nnumOfOperation = int(input())\ndic = {}\n\nfor num in numbers:\n if num in dic : dic[num] += 1\n else: dic[num] = 1\n \n\nsums = sum(numbers)\nfor i in range(numOfOperation):\n B,C = map(int,input().split())\n if (B in dic) : \n cnt = dic[B]\n dic[B] = 0\n if (C not in dic) : dic[C] = cnt\n else : dic[C] += cnt\n sums += cnt * (C - B)\n print(sums)\n'] | ['Wrong Answer', 'Accepted'] | ['s632022572', 's768774505'] | [23540.0, 20728.0] | [537.0, 537.0] | [343, 445] |
p02630 | u038676814 | 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. | ['l = [0] * 10**5\ntot = 0\nfor i in range(N) :\n l[A[i]]+=1\n tot += A[i]\nfor i in range(Q):\n s0 = S[i][0]\n s1 = S[i][1]\n tot += s1 * (l[s0] + l[s1]) - (s0 * l[s0] + s1*l[s1])\n l[s1] += l[s0]\n l[s0] = 0\n print(tot)', 'N = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nS = [list(map(int, input().split())) for l in range(Q)]\n\nl = [0] * 10**6\ntot = 0\nfor i in range(N) :\n l[A[i]]+=1\n tot += A[i]\nfor i in range(Q):\n s0 = S[i][0]\n s1 = S[i][1]\n tot += s1 * (l[s0] + l[s1]) - (s0 * l[s0] + s1*l[s1])\n l[s1] += l[s0]\n l[s0] = 0\n print(tot)'] | ['Runtime Error', 'Accepted'] | ['s618773066', 's126807872'] | [9420.0, 39280.0] | [27.0, 354.0] | [233, 359] |
p02630 | u039860745 | 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())\nS = []\nc = 0\ns = sum(A)\ntable = [0] * 100010\n# A = pd.Series(A)\n# for a in A:\n# print(a)\n\nfor i in A:\n table[i] += 1\nfor i in range(Q):\n B, C = map(int,input().split())\n # if B in A:\n \n c = table[B]\n s += (C - B) * c\n table[C] = table[B]\n table[B] = 0\n # print(s)\n \n # string = ",".join(A)\n # string_new = string.replace(B,C)\n # A = string_new.split(",")\n \n S.append(s)\n\n # A.replace(B, C,c)\n # while B in A:\n \n # for a in A:\n # print(a)\n # else:\n # S.append(s)\n\n\n\nfor s in S:\n print(s)\n', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nS = []\nc = 0\ns = sum(A)\ntable = [0] * 100010\n# A = pd.Series(A)\n# for a in A:\n# print(a)\n\nfor i in A:\n table[i] += 1\nfor i in range(Q):\n B, C = map(int,input().split())\n # if B in A:\n \n c = table[B]\n s += (C - B) * c\n table[C] = table[B]\n table[B] = 0\n print(s)', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nS = []\nc = 0\ns = sum(A)\ntable = [0] * 100010\n# A = pd.Series(A)\n# for a in A:\n# print(a)\n\nfor i in A:\n table[i] += 1\n\nfor i in range(Q):\n B, C = map(int,input().split())\n # if B in A:\n \n c = table[B]\n s += (C - B) * c\n table[C] += table[B]\n table[B] = 0\n # print(s)\n \n # string = ",".join(A)\n # string_new = string.replace(B,C)\n # A = string_new.split(",")\n \n S.append(s)\n\n # A.replace(B, C,c)\n # while B in A:\n \n # for a in A:\n # print(a)\n # else:\n # S.append(s)\n\n\n\nfor s in S:\n print(s)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s912639574', 's921667419', 's969523907'] | [21036.0, 21080.0, 20864.0] | [309.0, 480.0, 302.0] | [768, 378, 770] |
p02630 | u046187684 | 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\n\ndef solve(string):\n n, *aqbc = map(int, string.split())\n a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:]\n s = sum(a)\n t = Counter(a)\n ans = []\n for b, c in zip(*[iter(bc)] * 2):\n t[c] += t[b]\n t[b] = 0\n s += (c - b) * t[b]\n ans.append(s)\n return "\\n".join(map(str, ans))\n\n\nif __name__ == \'__main__\':\n import sys\n print(solve(sys.stdin.read().strip()))\n', 'from collections import Counter\n\n\ndef solve(string):\n n, *aqbc = map(int, string.split())\n a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:]\n s = sum(a)\n t = Counter(a)\n ans = []\n for b, c in zip(*[iter(bc)] * 2):\n if b in t.keys():\n s += (c - b) * t[b]\n t[b], t[c] = 0, t[b] + t[c]\n ans.append(s)\n return "\\n".join(map(str, ans))\n\n\nif __name__ == \'__main__\':\n import sys\n print(solve(sys.stdin.read().strip()))\n'] | ['Wrong Answer', 'Accepted'] | ['s785105197', 's152981616'] | [44332.0, 44196.0] | [198.0, 187.0] | [436, 468] |
p02630 | u068142202 | 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\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\nbc = [list(map(int, input().split())) for _ in range(q)]\nans_count = []\ncount = collections.Counter(a)\nfor i in range(q):\n num = count[bc[i][0]]\n count[bc[i][0]] = 0\n count[bc[i][1]] += num\n ans_count.append(count)\n\nfor ans in ans_count:\n total = 0\n for key, value in zip(count.keys(), count.values()):\n total += int(key) * int(value)\n print(total)', 'import collections\n\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\nbc = [list(map(int, input().split())) for _ in range(q)]\nans_count = []\ntotal = 0\nfor i in range(n):\n total += a[i]\n\ncount = collections.Counter(a)\nfor i in range(q):\n num = count[bc[i][0]]\n count[bc[i][0]] = 0\n count[bc[i][1]] += num\n total += (bc[i][1] - bc[i][0]) * num\n print(total)'] | ['Wrong Answer', 'Accepted'] | ['s917930183', 's032654878'] | [40152.0, 40232.0] | [2207.0, 410.0] | [448, 382] |
p02630 | u070581567 | 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())\nlist_a = list(map(int, input().split()))\n\nlist_a.sort()\n\ncounts = []\n\nfor i in range(0, 100000):\n if (i+1) in list_a:\n counts.append(list_a.count(i))\n else:\n counts.append(0)\n\nq = int(input())\nans = sum(list_a)\n\nfor i in range(q):\n b, c = map(int, input().split())\n\n ans += counts[b-1] * (c - b)\n\n counts[c-1] += counts[b-1]\n counts[b-1] = 0\n\n print(ans)\n', 'n = int(input())\nlist_a = list(map(int, input().split()))\n\nlist_a.sort()\n\ncounts = []\n\nfor i in range(0, 100000):\n if (i+1) in list_a:\n counts.append(list_a.count(i+1))\n else:\n counts.append(0)\n\nprint(counts)\n\nq = int(input())\nans = sum(list_a)\n\nfor i in range(q):\n b, c = map(int, input().split())\n\n ans += counts[b-1] * (c - b)\n\n counts[c-1] += counts[b-1]\n counts[b-1] = 0\n\n print(ans)\n', 'import numpy as np\n\nn = int(input())\nlist_a = list(map(int, input().split()))\n\ncounts = np.zeros(100000, dtype=int)\n\nans = 0\n\nfor i in range(len(list_a)):\n counts[list_a[i]-1] += 1\n ans += list_a[i]\n\nq = int(input())\n\nfor i in range(q):\n b, c = map(int, input().split())\n\n ans += counts[b-1] * (c - b)\n\n counts[c-1] += counts[b-1]\n counts[b-1] = 0\n\n print(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s672919221', 's693318811', 's005549103'] | [20848.0, 21024.0, 38580.0] | [2206.0, 2206.0, 767.0] | [407, 424, 382] |
p02630 | u075303794 | 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\nfrom numba import njit\n\nn=int(input())\na=np.array(list(map(int, input().split())))\nq=int(input())\na_sum= np.sum(a)\n\n\n@njit\ndef func(a,b,c,a_sum):\n count=np.count_nonzero(a==b)\n a[a==b]=c\n a_sum += count*(c-b)\n return a,a_sum\n \nfor i in range(q):\n b,c=map(int, input().split())\n a,a_sum=func(a,b,c,a_sum)\n print(a_sum)', 'import collections\n\nN=int(input())\nA=list(map(int,input().split()))\nX=collections.Counter(A)\nQ=int(input())\n\nans=sum(A)\nfor i in range(Q):\n B,C=map(int,input().split())\n ans+=(C-B)*X[B]\n print(ans)\n X[C]+=X[B]\n X[B]=0\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s505849830', 's193109904'] | [116912.0, 24184.0] | [2209.0, 561.0] | [344, 223] |
p02630 | u075317232 | 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\ndef Replacing():\n\n Num = int(input())\n\n value_A = list(map(int,input().split()))\n\n Sum = sum(value_A)\n Counter_value = Counter(value_A)\n\n NumB = int(input())\n\n for i in range(NumB):\n value_B = list(map(int,input().split()))\n\n Sum += (value_B[1] - value_B[0])*Counter_value(value_B[0])\n Counter_value[Ci] += Counter_value[Bi]\n Counter_value[Bi] = 0\n\n print(Sum)\n\nif __name__ == '__main__':\n Replacing()\n", "from collections import Counter\n\ndef Replacing():\n\n Num = int(input())\n\n value_A = list(map(int,input().split()))\n\n Sum = sum(value_A)\n Counter_value = Counter(value_A)\n\n NumB = int(input())\n\n for i in range(NumB):\n value_B = list(map(int,input().split()))\n\n Sum += (value_B[1] - value_B[0])*Counter_value(value_B[0])\n Counter_value[value_B[1]] += Counter_value[value_B[0]]\n Counter_value[value_B[0]] = 0\n\n print(Sum)\n\nif __name__ == '__main__':\n Replacing()\n", "from collections import Counter\n\ndef Replacing():\n\n Num = int(input())\n\n value_A = list(map(int,input().split()))\n\n Sum = sum(value_A)\n Counter_value = Counter(value_A)\n\n NumB = int(input())\n\n for i in range(NumB):\n value_B = list(map(int,input().split()))\n\n Sum += (value_B[1] - value_B[0])*Counter_value(value_B[0])\n Counter_value[Ci] += Counter_value[Bi]\n Counter_value[Bi] = 0\n\n print(Sum)\n\nif __name__ == '__main__':\n Replacing()\n", "from collections import Counter\n\ndef Replacing():\n\n Num = int(input())\n\n value_A = list(map(int,input().split()))\n\n Sum = sum(value_A)\n Counter_value = Counter(value_A)\n\n NumB = int(input())\n\n for i in range(NumB):\n value_B = list(map(int,input().split()))\n\n Sum += (value_B[1] - value_B[0])*Counter_value[value_B[0]]\n Counter_value[value_B[1]] += Counter_value[value_B[0]]\n Counter_value[value_B[0]] = 0\n\n print(Sum)\n\nif __name__ == '__main__':\n Replacing()\n"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s110808481', 's313596595', 's321512597', 's323352862'] | [21384.0, 21496.0, 21276.0, 24052.0] | [63.0, 59.0, 61.0, 576.0] | [491, 515, 491, 515] |
p02630 | u092387689 | 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(x) for x in input().split()]\nsumA = sum(A)\ncounter = [0]*(10**5+1)\nfor i in range(n):\n counter[A[i]] += 1\n\nprint(counter[:30])\nq = int(input())\n\nqueue = [list(map(int,input().split())) for i in range(q)]\n\nfor b,c in queue: \n b_cnt = counter[b]\n sumA -= (b*b_cnt)\n counter[b] = 0\n c_cnt = counter[c]\n sumA += c*(b_cnt)\n counter[c] = b_cnt+c_cnt\n print(sumA)\n ', 'n = int(input())\nA = [int(x) for x in input().split()]\nsumA = sum(A)\ncounter = [0]*(10**5+1)\nfor i in range(n):\n counter[A[i]] += 1\n\nq = int(input())\n\nqueue = [list(map(int,input().split())) for i in range(q)]\n\nfor b,c in queue: \n b_cnt = counter[b]\n sumA -= (b*b_cnt)\n counter[b] = 0\n sumA += c*(b_cnt)\n counter[c] += b_cnt\n print(sumA)\n '] | ['Wrong Answer', 'Accepted'] | ['s382635883', 's993768337'] | [32716.0, 32740.0] | [331.0, 346.0] | [414, 366] |
p02630 | u101350975 | 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()))\nq = int(input())\ndic = collections.Counter(a)\nsum_list = [x * y for (x, y) in dic.items()]\nsum = sum(sum_list)\nfor i in range(q):\n b, c = map(int, input().split())\n if b in dic:\n print(sum - (b - c) * dic[b])\n else:\n print(sum)\n', 'import collections\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\ndic = collections.Counter(a)\nsum_list = [x * y for (x, y) in dic.items()]\nsum = sum(sum_list)\nfor i in range(q):\n if b in dic:\n b, c = map(int, input().split())\n print(sum - (b - c) * dic[b])\n', 'import collections\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\ndic = collections.Counter(a)\nsum_list = [x * y for (x, y) in dic.items()]\nfor i in range(q):\n b, c = map(int, input().split())\n print(sum(sum_list) - (b - c) * dic[b])\n', 'import collections\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\ndic = collections.Counter(a)\nsum_list = [x * y for (x, y) in dic.items()]\nsum = sum(sum_list)\nfor i in range(q):\n b, c = map(int, input().split())\n if b in dic and c not in dic:\n sum -= (b - c) * dic[b]\n print(sum)\n dic[c] = dic[b]\n del dic[b]\n elif b in dic and c in dic:\n sum -= (b - c) * dic[b]\n print(sum)\n dic[c] += dic[b]\n del dic[b]\n else:\n print(sum)\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s264176405', 's708526423', 's808409471', 's801818642'] | [21384.0, 21480.0, 21248.0, 21796.0] | [474.0, 68.0, 2206.0, 563.0] | [323, 298, 263, 523] |
p02630 | u102059282 | 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 sum_dict(d, sum, b, c):\n val = 0\n if b in d:\n val = d[b]\n sum -= (b * val)\n del d[b]\n d[c] = d.get(c, 0) + val\n sum += (c * val)\n return sum, d\n \nn = int(input())\na = [int(x) for x in input().split()]\nd = {}\nfor i in a:\n d[i] = d.get(i, 0) + 1\ns = sum(a)\nq = int(input())\nfor i in range(q):\n b, c = map(int, input().split())\n s, d = sum_dict(d, b, c)\n print(s)', 'def sum_dict(d, sum, b, c):\n val = 0\n if b in d:\n val = d[b]\n sum -= (b * val)\n del d[b]\n d[c] = d.get(c, 0) + val\n sum += (c * val)\n return sum, d\n \nn = int(input())\na = [int(x) for x in input().split()]\nd = {}\nfor i in a:\n d[i] = d.get(i, 0) + 1\ns = sum(a)\nq = int(input())\nfor i in range(q):\n b, c = map(int, input().split())\n s, d = sum_dict(d, s, b, c)\n print(s)'] | ['Runtime Error', 'Accepted'] | ['s360329323', 's804693175'] | [20628.0, 20640.0] | [73.0, 520.0] | [423, 426] |
p02630 | u106118504 | 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())\nnum = list(map(int,input().strip().split()))\ns = sum(num)\nnum_dict = {}\nfor i in num:\n if i in num_dict:\n num_dict[i] += 1\n else:\n num_dict[i] = 1\nq = int(input())\nfor i in range(q):\n b,c = map(int,input().strip().split())\n if b in num_dict:\n num_dict[c] = num_dict[b]\n del num_dict[b]\n if b > c:\n s = s - (b-c)*num_dict[c]\n print(s)\n else:\n s = s + (c-b)*num_dict[c]\n print(s)\n else:\n print(s)\n ', 'n = int(input())\nnum = list(map(int,input().strip().split()))\ns = sum(num)\nnum_dict = {}\nfor i in num:\n if i in num_dict:\n num_dict[i] += 1\n else:\n num_dict[i] = 1\nq = int(input())\nfor i in range(q):\n b,c = map(int,input().strip().split())\n if c in num_dict:\n if b in num_dict:\n k = num_dict[b]\n num_dict[c] += num_dict[b]\n del num_dict[b]\n if b > c:\n s = s - (b-c)*k\n print(s)\n else:\n s = s + (c-b)*k\n print(s)\n else:\n print(s)\n else:\n if b in num_dict:\n k = num_dict[b]\n num_dict[c] = num_dict[b]\n del num_dict[b]\n if b > c:\n s = s - (b-c)*k\n print(s)\n else:\n s = s + (c-b)*k\n print(s)\n else:\n print(s)\n \n '] | ['Wrong Answer', 'Accepted'] | ['s168879761', 's994097597'] | [20844.0, 20888.0] | [523.0, 540.0] | [460, 749] |
p02630 | u107269063 | 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())\nprint(int(N*(N-1)/2))', 'N = int(input())\na = list(map(int,input().split()))\nQ = int(input())\nbc = [[int(i) for i in input().split()] for j in range(Q)]\n \ncounter = [0] * 1000000\nfor i in a:\n counter[i] += 1\n\nans = sum(a)\n \nfor _ in bc:\n ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]\n counter[_[1]] += counter[_[0]]\n counter[_[0]] = 0\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s022731326', 's858681641'] | [9152.0, 37684.0] | [25.0, 319.0] | [38, 346] |
p02630 | u111473084 | 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 import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n from collections import Counter\n\n N = int(input())\n A = list(map(int, input().split()))\n CA = Counter(A)\n sumA = 0\n for key, value in CA.items():\n sumA += key*value\n\n Q = int(input())\n for i in range(Q):\n b, c = map(int, input().split())\n sumA = (c-b)*CA[b]\n CA[c] += CA[b]\n CA[b] = 0\n print(sumA)\n\nmain()', 'def main():\n import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n from collections import Counter\n\n N = int(input())\n A = list(map(int, input().split()))\n CA = Counter(A)\n sumA = 0\n for key, value in CA.items():\n sumA += key*value\n\n Q = int(input())\n for i in range(Q):\n b, c = map(int, input().split())\n sumA += (c-b)*CA[b]\n CA[c] += CA[b]\n CA[b] = 0\n print(sumA)\n\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s197446708', 's780366515'] | [24320.0, 24180.0] | [223.0, 243.0] | [463, 464] |
p02630 | u111652094 | 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\n\nN=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\n\nnpdata = np.arange(10**5+1)\n\nkosuu=np.zeros(10)\nkosuumoto=kosuu\nfor i in range(N):\n a=A[i]\n kosuu[a]+=1\nSUM=sum(A)\n\nBC_list=[]\n\nfor i in range (Q):\n bc=list(map(int,input().split()))\n BC_list.append(bc)\nS=SUM\n\nfor i in range(Q):\n b=BC_list[i][0]\n c=BC_list[i][1]\n minus=b*kosuu[b]\n kosuu[c]=kosuu[c]+kosuu[b]\n plus=c*kosuu[c]\n kosuu[b]=0\n S=S-minus+plus\n\n print(int(S))\n\n \n', 'import numpy as np\n\nN=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\n\nnpdata = np.arange(10**5+1)\n\nkosuu=np.zeros(10**5+1)\nkosuumoto=kosuu\nfor i in range(N):\n a=A[i]\n kosuu[a]+=1\nSUM=sum(A)\n\nBC_list=[]\n\nfor i in range (Q):\n bc=list(map(int,input().split()))\n BC_list.append(bc)\nS=SUM\n\nfor i in range(Q):\n b=BC_list[i][0]\n c=BC_list[i][1]\n minus=b*kosuu[b]\n kosuu[c]=kosuu[c]+kosuu[b]\n plus=c*kosuu[c]\n kosuu[b]=0\n S=S-minus+plus\n\n print(int(S))\n', 'port numpy as np\n\nN=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\n\nnpdata = np.arange(10**5+1)\n\nkosuu=np.zeros(10**5+1)\nkosuumoto=kosuu\nfor i in range(N):\n a=A[i]\n kosuu[a]+=1\n\nBC_list=[]\n\nfor i in range (Q):\n bc=list(map(int,input().split()))\n BC_list.append(bc)\nS=0\nfor i in range(Q):\n b=BC_list[i][0]\n c=BC_list[i][1]\n kosuu[c]=kosuu[c]+kosuu[b]\n kosuu[b]=0\n S=sum(np.multiply(npdata,kosuu))\n print(int(S))\n\n \n', '\nimport numpy as np\n\nN=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\n\nnpdata = np.arange(10**5+1)\n\nkosuu=np.zeros(10**5+1)\nkosuumoto=kosuu\nfor i in range(N):\n a=A[i]\n kosuu[a]+=1\nSUM=sum(A)\n\nBC_list=[]\n\nfor i in range (Q):\n bc=list(map(int,input().split()))\n BC_list.append(bc)\nS=SUM\nfor i in range(Q):\n b=BC_list[i][0]\n c=BC_list[i][1]\n minus=b*kosuu[b]\n plus=c*kosuu[b]\n kosuu[c]=kosuu[c]+kosuu[b]\n kosuu[b]=0\n S=S-minus+plus\n print(int(S))\n\n \n'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s009031224', 's102918041', 's825446300', 's838666889'] | [43344.0, 51132.0, 8944.0, 50908.0] | [402.0, 617.0, 30.0, 622.0] | [497, 495, 461, 500] |
p02630 | u115110170 | 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())\nls = list(map(int,input().split()))\n\nls = sorted(ls)\nans = sum(ls)\nnewls = [0]*(n+1)\nfor p in ls:\n newls[p] += 1\nls = newls\n\nq=int(input())\nfor _ in range(q):\n b,c = map(int,input().split())\n \n tmp = ls[b]\n ans = ans + tmp*c - tmp*b\n ls[b] = 0\n ls[c] = tmp\n \n print(ans)\n \n', 'n=int(input())\nls = list(map(int,input().split()))\n\nls = sorted(ls)\nans = sum(ls)\nnewls = [0]*(100000+1+1)\nfor p in ls:\n newls[p] += 1\nls = newls\n\nq=int(input())\nfor _ in range(q):\n b,c = map(int,input().split())\n \n tmp = ls[b]\n ans = ans + tmp*c - tmp*b\n ls[b] = 0\n ls[c] += tmp\n \n print(ans)\n '] | ['Runtime Error', 'Accepted'] | ['s967597028', 's495130258'] | [20868.0, 20844.0] | [505.0, 488.0] | [298, 305] |
p02630 | u116038906 | 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\nimport sys\ninput = sys.stdin.readline\nN = int(input())\nA = list(map(int, input().split()))\nA_np =np.array(A,dtype=np.int64)\nQ = int(input())\nS =[0]*Q\nfor i in range(Q):\n b,c = (int(i) for i in input().split())\n A_np =np.where(A_np ==b,c,A_np)\n S[i] =np.sum(A_np)\n print(A_np)\n\n\nprint(*S,sep='\\n')", '\nfrom collections import Counter\nimport sys\ninput = sys.stdin.readline\nN = int(input())\nA = list(map(int, input().split()))\nA_c =Counter(A)\nQ = int(input())\nS =[0]*Q\nbc =[]\nfor i in range(Q):\n x,y = (int(i) for i in input().split())\n bc.append((x,y))\n #print(A_np)\nsum_A =[0]*(Q+1)\nsum_A[0] =sum(A)\nind =0\nfor k,v in bc:\n sum_A[ind+1] =sum_A[ind] -A_c[k] *k +A_c[k] *v\n A_c[v] +=A_c[k]\n A_c[k] =0\n #print(A_c)\n print(sum_A[ind +1])\n ind +=1'] | ['Wrong Answer', 'Accepted'] | ['s229674310', 's782908485'] | [38672.0, 39756.0] | [2206.0, 322.0] | [342, 481] |
p02630 | u117291818 | 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 os\nimport sys\nfrom io import BytesIO, IOBase\nfrom math import gcd\nfrom collections import Counter as cc\n\ndef main():\n n=int(input())\n l=list(map(int,input().split()))\n sm=sum(l)\n cnt=cc(l)\n q=int(input())\n for _ in range(q):\n p,r=map(int,input().split())\n sm-=(p*cnt[p])\n cnt[r]+=cnt[p]\n sm+=(r*cnt[r])\n cnt[p]=0\n print(sm)\n \n\n\n \n\n\n# region fastio\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._fd = file.fileno()\n self.buffer = BytesIO()\n self.writable = "x" in file.mode or "r" not in file.mode\n self.write = self.buffer.write if self.writable else None\n\n def read(self):\n while True:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n if not b:\n break\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines = 0\n return self.buffer.read()\n\n def readline(self):\n while self.newlines == 0:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n self.newlines = b.count(b"\\n") + (not b)\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines -= 1\n return self.buffer.readline()\n\n def flush(self):\n if self.writable:\n os.write(self._fd, self.buffer.getvalue())\n self.buffer.truncate(0), self.buffer.seek(0)\n\n\nclass IOWrapper(IOBase):\n def __init__(self, file):\n self.buffer = FastIO(file)\n self.flush = self.buffer.flush\n self.writable = self.buffer.writable\n self.write = lambda s: self.buffer.write(s.encode("ascii"))\n self.read = lambda: self.buffer.read().decode("ascii")\n self.readline = lambda: self.buffer.readline().decode("ascii")\n\n\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\ninput = lambda: sys.stdin.readline().rstrip("\\r\\n")\n\n\n\nif __name__ == "__main__":\n main()', 'import os\nimport sys\nfrom io import BytesIO, IOBase\nfrom math import gcd\nfrom collections import Counter as cc\n\ndef main():\n n=int(input())\n l=list(map(int,input().split()))\n sm=sum(l)\n cnt=cc(l)\n q=int(input())\n for _ in range(q):\n p,r=map(int,input().split())\n sm-=(p*cnt[p])\n cnt[r]+=cnt[p]\n sm+=(r*cnt[p])\n cnt[p]=0\n print(sm)\n\n\n\n \n\n\n# region fastio\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._fd = file.fileno()\n self.buffer = BytesIO()\n self.writable = "x" in file.mode or "r" not in file.mode\n self.write = self.buffer.write if self.writable else None\n\n def read(self):\n while True:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n if not b:\n break\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines = 0\n return self.buffer.read()\n\n def readline(self):\n while self.newlines == 0:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n self.newlines = b.count(b"\\n") + (not b)\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines -= 1\n return self.buffer.readline()\n\n def flush(self):\n if self.writable:\n os.write(self._fd, self.buffer.getvalue())\n self.buffer.truncate(0), self.buffer.seek(0)\n\n\nclass IOWrapper(IOBase):\n def __init__(self, file):\n self.buffer = FastIO(file)\n self.flush = self.buffer.flush\n self.writable = self.buffer.writable\n self.write = lambda s: self.buffer.write(s.encode("ascii"))\n self.read = lambda: self.buffer.read().decode("ascii")\n self.readline = lambda: self.buffer.readline().decode("ascii")\n\n\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\ninput = lambda: sys.stdin.readline().rstrip("\\r\\n")\n\n\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s233992652', 's424132165'] | [26944.0, 26844.0] | [330.0, 331.0] | [2128, 2120] |
p02630 | u135116520 | 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. | ['form collections import Counter\nN=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\ncounter=Counter(A)\nsum_res=sum(A)\nfor i in range(Q):\n b,c=map(int,input().split())\n sum_res-=counter[b]*b\n sum_res+=counter[b]*c\n counter[c]+=counter[b]\n counter[b]=0\n print(sum_res)', 'from collections import Counter\nN=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\ncounter=Counter(A)\nsum_res=sum(A)\nfor i in range(Q):\n b,c=map(int,input().split())\n sum_res-=counter[b]*b\n sum_res+=counter[b]*c\n counter[c]+=counter[b]\n counter[b]=0\n print(sum_res)'] | ['Runtime Error', 'Accepted'] | ['s146969431', 's927908434'] | [8612.0, 24120.0] | [22.0, 580.0] | [283, 283] |
p02630 | u136843617 | 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\ndef solve():\n N = int(input())\n A = np.array(list(map(int, input().split())),dtype=np.int64)\n Q = int(input())\n BC = np.array([list(map(int, input().split())) for _ in range(Q)])\n\n nums = np.zeros(max(A.max(), BC.max())+1)\n sm = A.sum(dtype=np.int64)\n for i in A:\n nums[i]+=1\n\n for b,c in BC:\n sm += nums[b]*(c-b)\n nums[c] +=nums[b]\n nums[b] = 0\n print(sm)\n\n\n\n\n\n\n\n\nif __name__ == "__main__":\n solve()', 'import numpy as np\ndef solve():\n N = int(input())\n A = np.array(list(map(int, input().split())),dtype=np.int64)\n Q = int(input())\n BC = np.array([list(map(int, input().split())) for _ in range(Q)])\n\n nums = np.zeros(max(A.max(), BC.max())+1)\n sm = np.sum(A, dtype=np.int64)\n for i in A:\n nums[i]+=1\n\n for b,c in BC:\n sm += nums[b]*(c-b)\n nums[c] +=nums[b]\n nums[b] = 0\n print(int(sm))\n\n\n\n\n\n\n\n\nif __name__ == "__main__":\n solve()'] | ['Wrong Answer', 'Accepted'] | ['s897010719', 's980759066'] | [47780.0, 47904.0] | [673.0, 626.0] | [481, 490] |
p02630 | u137646745 | 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())\nfor i in range(q):\n bc=list(map(int,input().split()))\nlist=np.array(a)\nsum=list.sum()\nans=[]\nfor i in range(q):\n sa=bc[1]-bc[0]\n num=a.count(bc[0])\n ans.append(sum+num)\n \nfor i in range(q):\n print(ans[i])', '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)]\ncount=Counter(a)\n\nsum=sum(a)\nfor i in range(q):\n b=bc[i][0]\n c=bc[i][1]\n diff=c-b\n num=count[b]\n sum+=num*diff\n print(sum)\n count[c]+=count[b]\n count[b]=0'] | ['Wrong Answer', 'Accepted'] | ['s393585732', 's484594718'] | [38704.0, 40432.0] | [2206.0, 429.0] | [304, 327] |
p02630 | u139132412 | 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()))\nk = int(input())\nfor _ in range(k):\n a,b = map(int, input().split())\n arr[arr.index(a)] = b\n print(sum(arr))', 'n = int(input())\noutput = []\narr = list(map(int, input().split()))\nk = int(input())\nfor _ in range(k):\n a,b = map(int, input().split())\n arr[arr.index(a)] = b\n output.append(sum(arr))\nfor i in output:\n print(i)', 'n = int(input())\narr = list(map(int, input().split()))\nk = int(input())\ns = sum(arr)\nfor _ in range(k):\n\tv = 0\n a,b = map(int, input().split())\n for i in range(len(arr)):\n if arr[i] == a:\n \tarr[i] = b\n \tv += 1\n s = s - (a*v) + (b*v)\n print(s)', 'n = int(input())\narr = list(map(int, input().split()))\nk = int(input())\ns = sum(arr)\nd = {}\nfor i in arr:\n d[i] = arr.count(i)\nfor _ in range(k):\n v = 0\n a,b = map(int, input().split())\n if a in d:\n d[b] = d[a]\n del d[a]\n v = d[b]\n s = s - (a*v) + (b*v)\n print(s)', 'n = int(input())\narr = list(map(int, input().split()))\nk = int(input())\nnew_sum = sum(arr)\nfor _ in range(k):\n a,b = map(int, input().split())\n s = new_sum - arr.count(a)*a + b\n print(s)', 'n = int(input())\narr = list(map(int, input().split()))\nk = int(input())\ns = sum(arr)\nd = {}\nfor i in arr:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\nfor _ in range(k):\n v = 0\n a,b = map(int, input().split())\n if a not in d:\n print(s)\n continue\n s += (b-a) * d[a]\n if b in d:\n d[b] += d[a]\n else:\n d[b] = d[a]\n print(s)\n del d[a]'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s085267751', 's394678885', 's417241445', 's442937139', 's474069253', 's830201243'] | [21028.0, 20856.0, 9024.0, 21064.0, 20864.0, 20644.0] | [55.0, 50.0, 27.0, 2206.0, 2206.0, 515.0] | [166, 214, 270, 298, 189, 397] |
p02630 | u148981246 | 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\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\ns = sum(a)\n\nad = collections.Counter(a)\nprint(ad)\n\nfor i in range(q):\n b, c = map(int, input().split())\n s += ad.get(b, 0) * (c - b) \n print(s)\n ad[c] += ad.get(b, 0)\n ad[b] = 0', 'import collections\n\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\ns = sum(a)\n\nad = collections.Counter(a)\n\nfor i in range(q):\n b, c = map(int, input().split())\n s += ad.get(b, 0) * (c - b) \n print(s)\n ad[c] += ad.get(b, 0)\n ad[b] = 0'] | ['Wrong Answer', 'Accepted'] | ['s753852260', 's670776077'] | [24936.0, 24068.0] | [616.0, 554.0] | [282, 272] |
p02630 | u152741807 | 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 =np.array([int(x) for x in input().split()])\nq = int(input())\nbc = [map(int, input().split()) for _ in range(q)]\nb, c = [list(i) for i in zip(*bc)]\n\nans = np.sum(a)\nfor i in range(q):\n if np.count_nonzero(a == b[i]) > 0:\n a = np.where(a == b[i], c[i],a)\n ans += np.count_nonzero(a == b[i])*(c[i]-b[i])\n print(ans)', 'import numpy as np\nimport collections\n\nn = int(input())\na =np.array([int(x) for x in input().split()])\nq = int(input())\nbc = [map(int, input().split()) for _ in range(q)]\nb, c = [list(i) for i in zip(*bc)]\n\ncount_dict = collections.Counter(a)\nans = np.sum(a)\nfor i in range(q):\n if count_dict[b[i]] > 0:\n ans += count_dict[b[i]]*(c[i]-b[i])\n count_dict[c[i]] += count_dict[b[i]]\n count_dict[b[i]] = 0\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s044068862', 's875876857'] | [82184.0, 86276.0] | [2209.0, 726.0] | [371, 439] |
p02630 | u158380546 | 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())\naa = 0;\nfor i in range(n):\n aa += a[i];\n\nb = [input().split() for l in range(q)]\n\nbu = [None]*(100000);\n\nfor i in range(10000):\n bu[i] = a.count(i);\n \nfor x in range(q):\n c = int(b[x][0])\n d = int(b[x][1])\n aa += (d-c)*(bu[c]);\n bu[d] += bu[c];\n bu[c] = 0;\n \nprint(aa);', '\nn = int(input())\na = list(map(int,input().split()));\nq = int(input())\naa = 0;\nfor i in range(n):\n aa += a[i];\n\nb = [input().split() for l in range(q)]\n\nbu = [0]*(100000);\n\nfor i in range(n):\n bu[a[i]-1] += 1;\n \nfor x in range(q):\n c = int(b[x][0])\n d = int(b[x][1])\n aa += (d-c)*(bu[c-1]);\n bu[d-1] += bu[c-1];\n bu[c-1] = 0;\n print(aa);\n '] | ['Runtime Error', 'Accepted'] | ['s021244030', 's276184682'] | [43396.0, 43436.0] | [2207.0, 390.0] | [366, 369] |
p02630 | u159144188 | 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())\nsu = sum(A)\nprint(counter)\nlis = {}\nfor i in range(Q):\n B, C = map(int, input().split())\n su -= B * counter[B]\n su += C * counter[B]\n counter[C] += counter[B]\n counter[B] = 0\n print(su)', 'from collections import Counter\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nsu = sum(A)\ncounter = Counter(A)\nlis = {}\nfor i in range(Q):\n B, C = map(int, input().split())\n su -= B * counter[B]\n su += C * counter[B]\n counter[C] += counter[B]\n counter[B] = 0\n print(su)'] | ['Runtime Error', 'Accepted'] | ['s859748472', 's438856900'] | [21468.0, 23668.0] | [47.0, 582.0] | [293, 299] |
p02630 | u166973463 | 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())\nquery = [list(map(int,input().split())) for _ in range(q)]\n\nall_sum = sum(a)\n\ncnt = {}\nfor i in a:\n if i not in cnt:\n cnt[a] = 0\n cnt[a] += 1\n\nfor (b, c) in query:\n if b in cnt:\n all_sum -= b*cnt[b]\n all_sum += c * cnt[b]\n if c not in cnt:\n cnt[c]=0 \n print(all_sum)', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nquery = [list(map(int,input().split())) for _ in range(q)]\n\nall_sum = sum(a)\n\ncnt = {}\nfor i in a:\n if i not in cnt:\n cnt[a] = 0\n cnt[a] += 1\n\nfor (b, c) in query:\n if b in cnt:\n all_sum -= b * cnt[b]\n all_sum += c * cnt[b]\n if c not in cnt:\n cnt[c]=0 \n cnt[c] += cnt[b]\n cnt[b] = 0\n print(all_sum)', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nquery = [list(map(int,input().split())) for _ in range(q)]\n\nall_sum = sum(a)\n\ncnt = {}\nfor i in a:\n if i not in cnt:\n cnt[i] = 0\n cnt[i] += 1\n\nfor (b, c) in query:\n if b in cnt:\n all_sum -= b * cnt[b]\n all_sum += c * cnt[b]\n if c not in cnt:\n cnt[c]=0 \n cnt[c] += cnt[b]\n cnt[b] = 0\n print(all_sum)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s050457383', 's293649005', 's720784839'] | [31444.0, 31292.0, 35928.0] | [230.0, 235.0, 377.0] | [388, 434, 434] |
p02630 | u173644182 | 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\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n c = Counter(A)\n q = int(input())\n s = sum(a)\n for _ in range(q):\n b, c = map(int, input().split())\n s -= C[b]*b\n s += C[b]*c\n C[c] += c[b]\n c[b] = 0\n print(s)\n\nif __name__ == "__main__":\n main()\n', 'rom collections import Counter\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n c = Counter\n q = int(input())\n s = sum(a)\n for _ in range(q):\n b, c = map(int, input().split())\n s -= C[b]*b\n s += C[b]*c\n C[c] += c[b]\n c[b] = 0\n print(s)\n\nif __name__ == "__main__":\n main()\n', 'from collections import Counter\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n cnt = Counter(a)\n q = int(input())\n s = sum(a)\n for _ in range(q):\n b, c = map(int, input().split())\n s -= cnt[b]*b\n\n s += cnt[b]*c\n cnt[c] += cnt[b]\n cnt[b] = 0\n print(s)\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s604752967', 's654300667', 's375567059'] | [21432.0, 8876.0, 24220.0] | [52.0, 26.0, 544.0] | [360, 356, 373] |
p02630 | u175590965 | 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)\nx = [0]*100001\nfor i in a:\n x[i] += 1\n\nq = int(input())\nfor i in range(q):\n b,c = map(int(input().split()))\n s -= b*x[b]\n s += c*x[c]\n x[c] += x[b]\n x[b] = 0\n print(s)', 'n =int(input())\na = list(map(int,input().split()))\ns = sum(a)\nx = [0]*1000001\nfor i in a:\n x[i] +=1\n\nq = int(input())\nfor i in range(q):\n b,c = map(int,input().split())\n s -= b*x[b]\n s += c*x[b]\n x[c] += x[b]\n x[b] = 0\n print(s)'] | ['Runtime Error', 'Accepted'] | ['s165188977', 's892920327'] | [21132.0, 23832.0] | [58.0, 486.0] | [249, 249] |
p02630 | u179025808 | 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())\ndis_list = []\nfor i in range(Q):\n s = list(map(int, input().split()))\n dis_list.append(s)\nfor j in dis_list:', 'from collections import Counter\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\ncount = Counter(A) #not dict!!\ntemp_sum = sum(A)\nfor _ in range(Q):\n before, after = map(int, input().split())\n temp_sum += (after - before) * count[before]\n count[after] += count[before]\n count[before] = 0\n print(temp_sum)'] | ['Runtime Error', 'Accepted'] | ['s192057861', 's199070239'] | [8868.0, 24324.0] | [25.0, 558.0] | [184, 340] |
p02630 | u179376941 | 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. | ['for i in range(n):\n key = lst[i]\n if key not in dic:\n dic[key] = 0\n dic[key] += 1\n#print(dic)\nsum = 0\nfor key, value in dic.items():\n sum += key * value\n\nm = int(input())\nfor _ in range(m):\n lst_s = list(map(int, input().split()))\n number = dic.get(lst_s[0])\n if number is not None:\n if lst_s[1] in dic:\n dic[lst_s[1]] += number\n else:\n dic[lst_s[1]] = number\n sum += lst_s[1] * number\n sum -= lst_s[0] * number\n dic.pop(lst_s[0])\n print(sum)', 'n = int(input())\nlst = [int(i) for i in input().split()]\ndic = {}\nfor i in range(n):\n key = lst[i]\n if key not in dic:\n dic[key] = 0\n dic[key] += 1\n#print(dic)\nsum = 0\nfor key, value in dic.items():\n sum += key * value\n\nm = int(input())\nfor _ in range(m):\n lst_s = list(map(int, input().split()))\n number = dic.get(lst_s[0])\n if number is not None:\n if lst_s[1] in dic:\n dic[lst_s[1]] += number\n else:\n dic[lst_s[1]] = number\n sum += lst_s[1] * number\n sum -= lst_s[0] * number\n dic.pop(lst_s[0])\n print(sum)'] | ['Runtime Error', 'Accepted'] | ['s550741818', 's862784186'] | [9108.0, 21112.0] | [24.0, 554.0] | [478, 544] |
p02630 | u182178426 | 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())\nu = []\nfor i in range(q):\n u.append(tuple(map(int,input().split())))\n\nfrom collections import Counter\nz = Counter(a)\n\nsum = sum(a)\nfor i in range(q):\n try:\n rev = z.pop(u[i][0])\n print(sum+(u[i][1]-u[i][0])*rev)\n if u[i][1] in z.keys():\n z[u[i][1]]+=rev\n else:\n z[u[i][1]]=rev\n except KeyError:\n print(sum)', 'n = int(input())\na = list(map(int,input().split()))\nq = int(input())\nu = []\nfor i in range(q):\n u.append(tuple(map(int,input().split())))\n\nfrom collections import Counter\nz = Counter(a)\n\nsum = sum(a)\nfor i in range(q):\n try:\n rev = z.pop(u[i][0])\n sum+=(u[i][1]-u[i][0])*rev\n print(sum)\n if u[i][1] in z:\n z[u[i][1]]+=rev\n else:\n z[u[i][1]]=rev\n except KeyError:\n print(sum)'] | ['Wrong Answer', 'Accepted'] | ['s792422537', 's495049367'] | [32600.0, 32712.0] | [372.0, 350.0] | [441, 447] |
p02630 | u195396655 | 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())\nA_cnt = [0] * 100001\nA_sum = 0\n\n\nfor a in A:\n A_cnt[a]+=1\n \n A_sum+=a\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n A_sum = A_sum + ((C-B) * A_cnt[B])\n print(A_sum)\n', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nA_cnt = [0] * 100001\nA_sum = 0\n\n\nfor a in A:\n A_cnt[a]+=1\n \n A_sum+=a\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n A_cnt[C] = A_cnt[C] + A_cnt[B]\n A_sum = A_sum + ((C-B) * A_cnt[B])\n A_cnt[B] = 0\n print(A_sum)\n'] | ['Wrong Answer', 'Accepted'] | ['s413948451', 's378710956'] | [20952.0, 20824.0] | [481.0, 481.0] | [347, 399] |
p02630 | u200916944 | 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, *bc = map(int, open(0).read().split()) \na = [bc.pop(0) for _ in range(n)] \nq = bc.pop(0) ', 'n, *bc = map(int, open(0).read().split()) \na = [bc.pop(0) for _ in range(n)] \nq = bc.pop(0) \n \nd = {} \nfor x in a: \n if x in d: \n d[x] += 1 \n else: \n d[x] = 1 \nret = sum(a) ', 'n, *r = map(int, open(0).read().split())\na = r[:n]\nq = r[n]\nbc = r[n+1:]\n\nd = {}\nfor x in a:\n if x in d:\n d[x] += 1\n else:\n d[x] = 1\nret = sum(a)\nfor i in range(0, min(q*2, len(bc)), 2):\n b = bc[i]\n c = bc[i+1]\n if b in d:\n v = d.pop(b)\n if c in d:\n d[c] += v\n else:\n d[c] = v\n ret += c * v - b * v\n \n print(ret)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s170103134', 's216803429', 's219172975'] | [43936.0, 43904.0, 44084.0] | [2206.0, 2206.0, 222.0] | [134, 516, 439] |
p02630 | u228303592 | 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\ndef main():\n N = int(input())\n A = list(map(int,input().split()))\n A.sort()\n d = np.zeros(A[-1]+1, dtype=np.unit64)\n \n for i in range(N):\n a = A[i]\n a1 = A[i-1]\n if a != a1:\n if a != a1:\n d[a::a] += 1\n else:\n d[a] += 1\n print(np.count_nonzero(d[A] == 1))\n \nmain()\n', 'import collections\n\nn=int(input())\narr=list(map(int,input().split()))\ncnt=collections.defaultdict(int)\nfor val in arr:\n cnt[val]+=1\nsums=sum(arr)\nq=int(input())\nfor a in range(q):\n b,c=map(int,input().split())\n diff=(c-b)*(cnt[b])\n sums+=diff\n print(sums)\n cnt[c]+=cnt[b]\n cnt[b]=0\n'] | ['Runtime Error', 'Accepted'] | ['s401625792', 's662956346'] | [38728.0, 24196.0] | [188.0, 559.0] | [325, 289] |
p02630 | u231570044 | 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\nfrom numba import jit\n\nN = int(input())\nA = np.asarray(list(map(int, input().split())))\nQ = int(input())\nB, C = np.zeros(Q, dtype=np.int64), np.zeros(Q, dtype=np.int64)\nfor i in range(Q):\n [b, c] = list(map(int, input().split()))\n B[i], C[i] = b, c\n \n@jit(nopython=True)\ndef calc(A, B, C, Q):\n for i in range(Q):\n A = np.where(A==B[i], C[i], A)\n print(np.sum(A))\n\ncalc(A, B, C, Q)\n', 'import numpy as np\n#import random\nfrom numba import jit\n\n@jit\ndef main():\n #N = 100000\n #A = random.choices(range(1, N), k=N)\n N = int(input())\n A = np.array(list(map(int, input().split())), dtype=np.uintc)\n MAX = 10**5\n X = np.zeros(MAX, dtype=np.uintc)\n Y = np.array(range(MAX), dtype=np.uintc)\n \n for i in range(len(A)): X[A[i]] += 1\n \n Q = int(input())\n #Q = MAX\n OUT = np.zeros(Q, dtype=np.uintc)\n for i in range(Q):\n [b, c] = list(map(int, input().split()))\n #b, c = random.choice(range(1, N)), random.choice(range(1, N))\n X[c] += X[b]\n X[b] = 0\n OUT[i] = int(np.sum(X*Y))\n return OUT\n\nOUT = main()\nprint("\\n".join(map(str, list(OUT))))\n\n', "\nN = int(input())\nA = array.array('L', list(map(int, input().split())))\nMAX = 10**5\nX = array.array('L', [0]) * MAX\nY = array.array('L', range(MAX))\n\nfor i in range(len(A)): X[A[i]] += 1\n \nQ = int(input())\ncur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))\n\nfor i in range(Q):\n [b, c] = list(map(int, input().split()))\n cur = cur - X[b]*b + X[b]*c\n print(cur)\n X[c] += X[b]\n X[b] = 0\n", "import array\n\nN = int(input())\nA = array.array('L', list(map(int, input().split())))\nMAX = 10**5+1\nX = array.array('L', [0]) * MAX\nY = array.array('L', range(MAX))\n\nfor i in range(len(A)): X[A[i]] += 1\n \nQ = int(input())\ncur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))\n\nfor i in range(Q):\n [b, c] = list(map(int, input().split()))\n cur = cur - X[b]*b + X[b]*c\n print(cur)\n X[c] += X[b]\n X[b] = 0\n\n"] | ['Time Limit Exceeded', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s195450853', 's550290863', 's755904246', 's345401015'] | [117952.0, 125484.0, 9124.0, 21004.0] | [2209.0, 2209.0, 26.0, 540.0] | [426, 724, 415, 431] |
p02630 | u240630407 | 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 itertools\n# import math\n# import sys\n\n# import numpy as np\n\nN = int(input())\n# S = input()\n# n, *a = map(int, open(0))\n# N, M = map(int, input().split())\nA = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n\n# for l in tree[s]:\n\n\n# dfs(tree, l[0])\n# dfs(tree, 1)\n\n\n\nQ = int(input())\nB_C = [list(map(int,input().split())) for _ in range(Q)]\n\ntot = sum(A)\ncnt = [0] * 100001\nfor i in A:\n cnt[i] += 1\n\n\nfor l in B_C:\n cnt[l[1]] += cnt[l[0]]\n cnt[l[0]] = 0\n tot += cnt[l[0]] * (l[1] - l[0])\n print(tot)\n', '# import itertools\n# import math\n# import sys\n\n# import numpy as np\n\nN = int(input())\n# S = input()\n# n, *a = map(int, open(0))\n# N, M = map(int, input().split())\nA = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n\n# for l in tree[s]:\n\n\n# dfs(tree, l[0])\n# dfs(tree, 1)\n\ntot = sum(A)\ncnt = [0] * 100001\nfor i in A:\n cnt[i] += 1\n\n\nQ = int(input())\n\nfor i in range(Q):\n b, c = map(int,input().split())\n cnt[c] += cnt[b]\n print(tot + cnt[b] * (c - b))', '# import itertools\n# import math\n# import sys\n\n# import numpy as np\n\nN = int(input())\n# S = input()\n# n, *a = map(int, open(0))\n# N, M = map(int, input().split())\nA = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n\n# for l in tree[s]:\n\n\n# dfs(tree, l[0])\n# dfs(tree, 1)\n\n\n\nQ = int(input())\nB_C = [list(map(int,input().split())) for _ in range(Q)]\n\ntot = sum(A)\ncnt = [0] * 100001\nfor i in A:\n cnt[i] += 1\n\n# print(cnt[:6])\n\nfor l in B_C:\n cnt[l[1]] += cnt[l[0]]\n tot += cnt[l[0]] * (l[1] - l[0])\n cnt[l[0]] = 0\n print(tot)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s294659557', 's777395682', 's417528381'] | [32048.0, 85560.0, 32200.0] | [331.0, 2330.0, 322.0] | [1079, 1018, 1096] |
p02630 | u241348301 | 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)\nS = sum(A)\n \nfor _ in range(int(input())):\n p, q = map(int, input().split())\n k = count[p]\n count[p] = 0\n count[q] += k\n S += (q - p) * k\n print(S)', 'from collections import Counter\n \nN = int(input())\nA = list(map(int, input().split()))\ncount = Counter(A)\nS = sum(A)\n \nfor _ in range(int(input())):\n b, c = map(int, input().split())\n k = count[b]\n count[b] = 0\n count[c] += k\n S += (c - b) * k\n print(S)'] | ['Runtime Error', 'Accepted'] | ['s009372542', 's663716674'] | [21240.0, 24192.0] | [60.0, 558.0] | [267, 271] |
p02630 | u247680229 | 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())\nB=[list(map(int, input().split())) for _ in range(Q)]\n\nans=[]\n\nfor i in B:\n b=i[0]\n c=i[1]\n a=A.count(b)\n ans.append(sum(A)+(c*a-b*a))\n \nfor i in ans:\n print(i)', 'N=int(input())\nA=list(map(int, input().split()))\nQ=int(input())\n\nnum=[0]*10**5 \na=sum(A)\n\nfor i in A: \n num[i-1]+=1\n\nfor _ in range(Q):\n b,c=map(int, input().split())\n \n a=a+(-num[b-1]*b+c*num[b-1])\n num[c-1]+=num[b-1]\n num[b-1]-=num[b-1]\n print(a)\n'] | ['Wrong Answer', 'Accepted'] | ['s775951995', 's465107338'] | [48960.0, 20952.0] | [2207.0, 527.0] | [249, 284] |
p02630 | u257823704 | 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\noperations = []\n\nfor i in range(q):\n temp = input().split(" ")\n operations.append((int(temp[0]), int(temp[1])))\n\nfor op in operations:\n target, goto = op\n\n a.sort()\n\n try:\n index = a.index(target)\n \n while True:\n if a[index] != target:\n break\n\n a[index] = target\n index += 1\n\n print(sum(a))\n\n except:\n print(sum(a))\n\n \n # if a[i] == target:\n # a[i] = goto\n\n #print(sum(a))', 'n = int(input())\na = [int(i) for i in input().split(" ")]\nq = int(input())\n\noperations = []\n\nfor i in range(q):\n temp = input().split(" ")\n operations.append((int(temp[0]), int(temp[1])))\n\nfor op in operations:\n target, goto = op\n\n a.sort()\n\n try:\n index = a.index(target)\n \n while:\n if a[index] != target:\n break;\n\n a[index] = target\n index += 1\n\n print(sum(a))\n\n except:\n print(sum(a))', 'from collections import defaultdict\n\nd = defaultdict(int)\n\nn = int(input())\na = [int(i) for i in input().split(" ")]\nq = int(input())\n\noperations = []\n\nfor i in range(q):\n temp = input().split(" ")\n operations.append((int(temp[0]), int(temp[1])))\n\nfor hoge in a:\n d[hoge] += 1\n\ninitial_sum = 0\nfor key, value in d.items():\n initial_sum += key * value\n\nfor op in operations:\n target, goto = op\n\n before = goto * d[goto] + target * d[target]\n d[goto] += d[target]\n d[target] = 0\n\n after = goto * d[goto]\n diff = after - before\n \n initial_sum += diff\n print(initial_sum)\n \n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s607170180', 's766087756', 's578519182'] | [27064.0, 9052.0, 35564.0] | [2206.0, 24.0, 379.0] | [595, 488, 612] |
p02630 | u260036763 | 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 = sorted(list(map(int, input().split())))\nQ = int(input())\nfor _ in range(Q):\n B, C = map(int, input().spit())\n if A[0] <= B <= A[-1]:\n for x in A:\n if x == B:\n x = C\n print(sum(A))\n else:\n print(sum(A))', 'from collections import Counter \nN = int(input())\na = list(map(int, input().split()))\nA = Counter(a)\nQ = int(input())\n\nans = sum(a)\nfor _ in range(Q):\n B, C = map(int, input().split())\n if B in A.keys():\n if C in A.keys():\n A[C] += A[B]\n else:\n A[C] = A[B]\n ans += (C-B)*A[B]\n A[B] = 0\n print(ans)'] | ['Runtime Error', 'Accepted'] | ['s385031008', 's255324287'] | [20528.0, 21440.0] | [73.0, 533.0] | [278, 356] |
p02630 | u262039080 | 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=[]\nfor i in range(Q):\n B.append(list(map(int,input().split())))\nsum=int(0)\nAA=[int(0)]\nfor i in range(100000):\n AA.append(int(0))\n\n# AA[i]=A.count(int(i))\n\n# print(AA[i])\nsum=int(0)\nfor i in range(N):\n sum += A[i]\nfor i in range(Q):\n AA[(B[i][0])]=A.count(int((B[i][0])))\n A.replace(B[i][0],B[i][1])\n# AA[(B[i][1])]=A.count(int((B[i][1])))\n sum = sum + B[i][1]*AA[(B[i][0])]-B[i][0]*AA[(B[i][0])]\n# AA[(B[i][1])] = AA[(B[i][1])]+AA[(B[i][0])]\n# AA[(B[i][0])] = 0\n print(sum)', 'N=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\nB=[]\nfor i in range(Q):\n B.append(list(map(int,input().split())))\nsum=int(0)\nAA=[int(0)]\nfor i in range(100000):\n AA.append(int(0))\nfor i in A:\n AA[i]+=1 #A.count(int(i))\n\n# print(AA[i])\nsum=int(0)\nfor i in range(N):\n sum += A[i]\nfor i in range(Q):\n# AA[(B[i][0])]=A.count(int((B[i][0])))\n# A.replace(B[i][0],B[i][1])\n# AA[(B[i][1])]=A.count(int((B[i][1])))\n sum = sum + B[i][1]*AA[(B[i][0])]-B[i][0]*AA[(B[i][0])]\n AA[(B[i][1])] = AA[(B[i][1])]+AA[(B[i][0])]\n AA[(B[i][0])] = 0\n print(sum)\n'] | ['Runtime Error', 'Accepted'] | ['s392626026', 's497271506'] | [32224.0, 31888.0] | [285.0, 386.0] | [618, 609] |
p02630 | u265506056 | 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()))\na=[0]*(10**5+1)\nnum=0\nfor i in range(N):\n s=A[i]\n a[s]+=1\n num+=s\nQ=int(input())\nans=[]\nprint(num)\nfor i in range(Q):\n B,C=map(int,input().split())\n a[C]+=a[B]\n num+=(C-B)*a[B]\n a[B]=0\n ans.append(num)\nfor i in ans:\n print(i)', 'N=int(input())\nA=list(map(int,input().split()))\na=[0]*(10**5+1)\nnum=0\nfor i in range(N):\n s=A[i]\n a[s]+=1\n num+=s\nQ=int(input())\nans=[]\nfor i in range(Q):\n B,C=map(int,input().split())\n a[C]+=a[B]\n num+=(C-B)*a[B]\n a[B]=0\n ans.append(num)\nfor i in ans:\n print(i)'] | ['Wrong Answer', 'Accepted'] | ['s173167546', 's338738803'] | [20460.0, 21092.0] | [321.0, 311.0] | [300, 289] |
p02630 | u266014018 | 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 import sys\n def input(): return sys.stdin.readline().rstrip()\n n = int(input())\n A = list(map(int, input().split()))\n q = int(input())\n import numpy as np\n A.sort()\n ans = sum(A)\n for i in range(q):\n b,c = map(int, input().split())\n count = 0\n for j,a in enumerate(A):\n if a == b:\n A[j]=c\n conunt += 1\n elif a > b:\n break\n ans += (c-b)* count\n print(ans)\n\nif __name__ == '__main__':\n main()", "def main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n n = int(input())\n A = list(map(int, input().split()))\n q = int(input())\n import numpy as np\n A.sort()\n ans = sum(A)\n from bisect import bisect_left,bisect_right\n from collections import Counter\n count = Counter(A)\n for i in range(q):\n b,c = map(int, input().split())\n k = count[b]\n if k != 0\n count[c] += count.pop(b)\n ans += (c-b)* k\n print(ans)\n\n\nif __name__ == '__main__':\n main()", "def main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n n = int(input())\n A = list(map(int, input().split()))\n q = int(input())\n import numpy as np\n A.sort()\n ans = sum(A)\n from bisect import bisect_left,bisect_right\n from collections import Counter\n count = Counter(A)\n for i in range(q):\n b,c = map(int, input().split())\n k = count[b]\n if k != 0:\n count[c] += count.pop(b)\n ans += (c-b)* k\n print(ans)\n\n\nif __name__ == '__main__':\n main()"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s716186754', 's781202446', 's405817459'] | [30872.0, 8996.0, 37152.0] | [299.0, 26.0, 361.0] | [535, 544, 545] |
p02630 | u268318377 | 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\nreadline = sys.stdin.buffer.readline\n\nfrom collections import Counter\n\n\nN = int(input())\nA = list(map(int, readline().split()))\nQ = int(input())\n\nS = sum(A)\nC = Counter(A)\n\nans = []\nfor _ in range(Q):\n b, c = map(int, input().split())\n count = C[b]\n S += (c - b) * count\n C[b], C[c] = 0, C[c] + count\n ans.append(S)\n\nprint('\\n'.join(map(str, ans)))", "from collections import Counter\n\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nS = sum(A)\nC = Counter(A)\n\nans = []\nfor _ in range(Q):\n b, c = map(int, input().split())\n count = C[b]\n S += (c - b) * count\n C[b], C[c] = 0, C[c] + count\n ans.append(S)\n\nprint('\\n'.join(map(str, ans)))"] | ['Runtime Error', 'Accepted'] | ['s876668806', 's338885102'] | [19768.0, 33832.0] | [48.0, 341.0] | [374, 322] |
p02630 | u269600684 | 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 _print_sum(cache):\n sum_value = 0\n for v, indices in cache.items():\n sum_value += v * len(indices)\n print(sum_value)\n\n\ndef _main(N, A_list, Q, BC_list):\n cache = {}\n values = set()\n for i, a in enumerate(A_list):\n cache.setdefault(a, []).append(i)\n values.add(a)\n\n for b, c in BC_list:\n indices = cache.get(b, [])\n cache[b] = []\n cache.setdefault(c, []).extend(indices)\n _print_sum(cache)\n\n\ndef _entry():\n N = int(input())\n A_list = list(map(int, input().split()))\n Q = int(input())\n BC_list = []\n for i in range(Q):\n B, C = map(int, input().split())\n BC_list.append((B, C))\n _main(N, A_list, Q, BC_list)\n\n if __name__ == "__main__":\n _entry()\n', 'def _calc_sum(cache):\n sum_value = 0\n for v, indices in cache.items():\n sum_value += v * len(indices)\n return sum_value\n\n\ndef _main(N, A_list, Q, BC_list):\n cache = {}\n for i, a in enumerate(A_list):\n cache.setdefault(a, []).append(i)\n\n sum_value = _calc_sum(cache)\n\n for b, c in BC_list:\n indices = cache.get(b, [])\n cache[b] = []\n sum_value -= b * len(indices)\n cache.setdefault(c, []).extend(indices)\n sum_value += c * len(indices)\n print(sum_value)\n\n\ndef _entry():\n N = int(input())\n A_list = list(map(int, input().split()))\n Q = int(input())\n BC_list = []\n for i in range(Q):\n B, C = map(int, input().split())\n BC_list.append((B, C))\n _main(N, A_list, Q, BC_list)\n\n\nif __name__ == "__main__":\n _entry()\n'] | ['Wrong Answer', 'Accepted'] | ['s211829759', 's343485938'] | [9108.0, 46088.0] | [28.0, 1569.0] | [760, 820] |
p02630 | u284120954 | 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 q in range(Q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n\nsam = float(sum(A))\nbaketu = [0]*(10**5)\nfor a in A:\n baketu[a] += 1\n\nfor q in range(Q):\n sam = sam + baketu[B[q]] * (C[q] - B[q])\n baketu[C[q]] += baketu[B[q]]\n baketu[B[q]] = 0\n print(sam)', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nB = []\nC = []\nfor q in range(Q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n\nsam = sum(A)\nbaketu = [0]*(100001)\nfor a in A:\n baketu[a] += 1\n\nfor q in range(Q):\n sam = sam + baketu[B[q]] * (C[q] - B[q])\n baketu[C[q]] += baketu[B[q]]\n baketu[B[q]] = 0\n \n print(sam)'] | ['Runtime Error', 'Accepted'] | ['s815754702', 's408871464'] | [21864.0, 22224.0] | [303.0, 309.0] | [378, 391] |
p02630 | u285492845 | 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 = input()\nN = int(n)\nA = [int(a) for a in input().split()]\nq = input()\nQ = int(q)\nB, C = [], []\nfor i in range(Q):\n b, c = input().split()\n B.append(int(b))\n C.append(int(c))\n\n\nmy_dict = Counter(A)\n\ndef cals_sum(my_dict):\n values = [ my_dict[key]*key for key in my_dict.keys() if my_dict[key] != 0]\n #for key in my_dict.keys():\n # value = my_dict[key]\n \n return sum(values)\n \nmy_sum = cals_sum(my_dict)\n\nfor i in range(len(B)):\n b = B[i]\n c = C[i]\n tmpb = my_dict[b] \n my_dict[b] = 0\n tmpc = my_dict[c]\n my_dict[c] = tmpb + tmpc\n \n my_sum += ((tmpb + tmpc)*c - tmpb*b)\n\n print(my_sum)\n', 'from collections import Counter\n\nn = input()\nN = int(n)\nA = [int(a) for a in input().split()]\nq = input()\nQ = int(q)\nB, C = [], []\nfor i in range(Q):\n b, c = input().split()\n B.append(int(b))\n C.append(int(c))\n\n\nmy_dict = Counter(A)\n\ndef cals_sum(my_dict):\n values = [ my_dict[key]*key for key in my_dict.keys() if my_dict[key] != 0]\n #for key in my_dict.keys():\n # value = my_dict[key]\n \n return sum(values)\n \nmy_sum = cals_sum(my_dict)\n\nfor i in range(len(B)):\n b = B[i]\n c = C[i]\n tmpb = my_dict[b] \n my_dict[b] = 0\n tmpc = my_dict[c]\n my_dict[c] = tmpb + tmpc\n \n my_sum += ((tmpb)*c - tmpb*b)\n\n print(my_sum)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s405842803', 's421072295'] | [30624.0, 30832.0] | [394.0, 413.0] | [708, 703] |
p02630 | u290187182 | 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. | ["if __name__ == '__main__':\n n = int(input())\n a = [int(i) for i in input().split()]\n q = int(input())\n key = [i for i in range(10**5+1)]\n val = [0]*(10**5+1)\n dict = dict(zip(key,val))\n dict.update(collections.Counter(a))\n ans = sum(a)\n\n for i in range(q):\n b, c = map(int, input().split())\n ans= ans - b*dict[b] + c*dict[b]\n count = dict[b]\n dict[b]=0\n dict[c]+=count\n print(ans)\n\n\n", "import collections\n\n\nif __name__ == '__main__':\n n = int(input())\n a = [int(i) for i in input().split()]\n q = int(input())\n key = [i for i in range(10**5+1)]\n val = [0]*(10**5+1)\n dict = dict(zip(key,val))\n dict.update(collections.Counter(a))\n ans = sum(a)\n\n for i in range(q):\n b, c = map(int, input().split())\n ans= ans - b*dict[b] + c*dict[b]\n count = dict[b]\n dict[b]=0\n dict[c]+=count\n print(ans)\n\n\n\n"] | ['Runtime Error', 'Accepted'] | ['s214779457', 's044645274'] | [26468.0, 28216.0] | [73.0, 588.0] | [452, 474] |
p02630 | u293215208 | 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 = map(int, input().split())\nA = list(map(int, input().split()))\nq = map(int, input().split())\n \ncnt = collections.Counter(A)\nANS = []\nbase = sum(A)\n\nfor i in range(q):\n b,c = map(int, input().split())\n ans = base + (c-b) * cnt[b]\n ANS.append(ans)\n cnt[c] += cnt[b]\n cnt[b] = 0\n base = ans\n\nfor i in ANS:\n print(i)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\n \nbase = 0\ncnt = collections.Counter(A) \nAns = []\n \nfor i in range(N):\n base += A[i]\n\nfor i in range(Q):\n b ,c = map(int, input().split())\n Ans.append(Ans[i] + (c-b) * cnt[b])\n cnt[c] += cnt[b]\n cnt[b] = 0\n\nprint(Ans)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\n \nbase = 0\ncnt = collections.Counter(A) \nAns = []\n \nfor i in range(N):\n base += A[i]\n\nfor i in range(Q):\n b,c = map(int, input().split())\n ans = base + (c-b) * cnt[b]\n Ans.append(ans)\n cnt[c] += cnt[b]\n cnt[b] = 0\n base = ans\n\nprint(Ans)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\n \nbase = 0\ncnt = collections.Counter(A) \nAns = []\n \nfor i in range(N):\n base += A[i]\n\nfor i in range(Q):\n b ,c = map(int, input().split())\n Ans.append(base + (c-b) * cnt[b])\n cnt[c] += cnt[b]\n cnt[b] = 0\n base = Ans[i]\n\nprint(Ans)', 'import collections\n\nn = map(int, input().split())\nA = list(map(int, input().split()))\nq = map(int, input().split())\n\nCNT = collections.Counter(A)\nANS = []\nans = sum(A)\n\nfor i in range(q):\n b, c = map(int, input().split())\n t = CNT[b]\n ans +=(c - b) * t\n ANS.append(ans)\n CNT[c] += t\n CNT[b] = 0\n\nfor i in ANS:\n print(i)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\n \nbase = 0\ncnt = collections.Counter(A) \nANS = []\n \nfor i in range(N):\n base += A[i]\n\nfor i in range(Q):\n b,c = map(int, input().split())\n ans = base + (c-b) * cnt[b]\n ANS.append(ans)\n cnt[c] += cnt[b]\n cnt[b] = 0\n base = ans\n\nprint(ANS)', 'import collections\n\nn = map(int, input().split())\nA = list(map(int, input().split()))\nq = map(int, input().split())\n\ncnt = collections.Counter(A)\nANS = []\nbase = sum(A)\n\nfor i in range(q):\n b, c = map(int, input().split())\n t = CNT[b]\n ans = base + (c - b) * t\n ANS.append(ans)\n CNT[c] += t\n CNT[b] = 0\n base = ans\n\nfor i in ANS:\n print(i)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\nB, C = list(map(int, input().split())),list(map(int, input().split()))\n\nbase = 0\ncnt = collections.Counter(A)\n\nfor i in range(N):\n base += A[i]\n\nAns = []\nAns.append(base + (C[0]-B[0]) * cnt[B[0]])\n\nfor i in range(Q-1):\n if cnt[B[i+1]] != 0:\n Ans.append(Ans[i] + (C[i+1]-B[i+1]) * cnt[B[i+1]])\n for j in range(i+1):\n Ans[i+1] += B.count(C[j]) * (C[i+1] - C[j])\n else:\n Ans.append(Ans[i])\n\nprint(Ans)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\n \nbase = 0\ncnt = collections.Counter(A) \nANS = []\n \nfor i in range(N):\n base += A[i]\n\nfor i in range(Q):\n b,c = map(int, input().split())\n ans = base + (c-b) * cnt[b]\n ANS.append(ans)\n cnt[c] += cnt[b]\n cnt[b] = 0\n base = ans\n\nfor i in ANS:\n print(i)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\n \nbase = 0\ncnt = collections.Counter(A)\n \nfor i in range(N):\n base += A[i]\n \nAns = []\nAns.append(base + (C[0]-B[0]) * cnt[B[0]])\n \nfor i in range(Q-1):\n b ,c = map(int, input().split())\n Ans.append(Ans[i] + (c-b) * cnt[b])\n cnt[c] += cnt[b]\n cnt[b] = 0\n\nprint(Ans)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\n \nbase = 0\ncnt = collections.Counter(A)\n \nfor i in range(N):\n base += A[i]\n\nAns = []\nAns.append(base + (C[0]-B[0]) * cnt[B[0]])\n \nfor i in range(Q-1):\n if cnt[B[i+1]] != 0:\n Ans.append(Ans[i] + (C[i+1]-B[i+1]) * cnt[B[i+1]])\n for j in range(i+1):\n Ans[i+1] += B.count(C[j]) * (C[i+1] - C[j])\n else:\n Ans.append(Ans[i])\n\nprint(Ans)', 'import collections\nN = map(int, input().split())\nA = list(map(int, input().split()))\nQ = map(int, input().split())\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\n\nbase = 0\ncnt = collections.Counter(A)\n\nfor i in range(N):\n base += A[i]\n\nAns = []\nAns.append(base + (C[0]-B[0]) * cnt[B[0]])\n\nfor i in range(Q-1):\n if cnt[B[i+1]] != 0:\n Ans.append(Ans[i] + (C[i+1]-B[i+1]) * cnt[B[i+1]])\n for j in range(i+1):\n Ans[i+1] += B.count(C[j]) * (C[i+1] - C[j])\n else:\n Ans.append(Ans[i])\n\nprint(Ans)', 'import collections\n\nn = int(input())\nA = list(map(int, input().split()))\nq = int(input())\n\nCNT = collections.Counter(A)\nANS = []\nans = sum(A)\n\nfor i in range(q):\n b, c = map(int, input().split())\n t = CNT[b]\n ans +=(c - b) * t\n ANS.append(ans)\n CNT[c] += t\n CNT[b] = 0\n\nfor i in ANS:\n print(i)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s039614469', 's078176405', 's193239134', 's386708259', 's387690723', 's397262694', 's398841653', 's573882434', 's723048466', 's745374144', 's881964540', 's885172075', 's302585985'] | [21300.0, 21328.0, 21476.0, 21232.0, 21480.0, 21168.0, 21472.0, 21244.0, 21436.0, 21172.0, 21620.0, 21472.0, 26984.0] | [58.0, 59.0, 62.0, 57.0, 59.0, 61.0, 58.0, 56.0, 59.0, 57.0, 58.0, 60.0, 357.0] | [341, 342, 364, 356, 340, 364, 363, 554, 378, 389, 558, 555, 314] |
p02630 | u303344598 | 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().split()))\nc = [0] * (10 ** 5 + 1)\nfor i in l:\n c[i] += 1\nn = int(input())\ns = sum(c)\nfor i in range(n):\n be,af = map(int,input().split())\n s -= be * c[be]\n s += af * c[be]\n c[af] += c[be]\n c[be] = 0\n print(s)', 'n = int(input())\nl= list(map(int,input().split()))\nc = [0] * 10001\nfor i in l:\n c[i] += 1\nn = int(input())\ns = sum(c)\nfor i in range(n):\n be,af = map(int,input().split())\n s -= be * c[be]\n s += af * c[be]\n c[af] += c[be]\n c[be] = 0\n print(s)', 'N = int(input())\nA= list(map(int,input().split()))\nQ = int(input())\nheavy = [0] * (10 ** 5 + 1)\nfor i in A:\n heavy[i] += 1\ns = sum(A)\nfor i in range(Q):\n be,af = map(int,input().split())\n s -= be * heavy[be]\n s += af * heavy[be]\n heavy[af] += heavy[be]\n heavy[be] = 0\n print(s)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s189853157', 's769498181', 's642009801'] | [20992.0, 20804.0, 20984.0] | [488.0, 53.0, 493.0] | [256, 248, 284] |
p02630 | u305349402 | 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()))\nsummary = sum(A)\nd = {}\nfor a in A:\n if a in d:\n d[a] += 1\n else:\n d[a] = 1\n \nQ = int(input())\nfor _ in range(Q):\n B, C = list(map(int,input().split()))\n if b in d:\n b = 0\n else:\n b = d[B]\n \td[B] = 0\n if C in d:\n d[C] += b\n else:\n d[C] = b\n summary = summary + b * (C - B)\n print(summary)', 'N = int(input())\nA = list(map(int,input().split()))\nsummary = sum(A)\nd = {}\nfor a in A:\n if a in d:\n d[a] += 1\n else:\n d[a] = 1\n \nQ = int(input())\nfor _ in range(Q):\n B, C = list(map(int,input().split()))\n if B not in d:\n b = 0\n else:\n b = d[B]\n \td[B] = 0\n if C in d:\n d[C] += b\n else:\n d[C] = b\n summary = summary + b * (C - B)\n print(summary)', 'N = int(input())\nA = list(map(int,input().split()))\nsummary = sum(A)\nd = {}\nfor a in A:\n if a in d:\n d[a] += 1\n else:\n d[a] = 1\n \nQ = int(input())\nfor _ in range(Q):\n B, C = list(map(int,input().split()))\n if B not in d:\n b = 0\n else:\n b = d[B]\n d[B] = 0\n if C in d:\n d[C] += b\n else:\n d[C] = b\n summary = summary + b * (C - B)\n print(summary)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s985534948', 's992824895', 's547567301'] | [8896.0, 8932.0, 20816.0] | [24.0, 27.0, 526.0] | [371, 375, 376] |
p02630 | u310337637 | 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())\nxy = [map(int, input().split()) for _ in range(q)]\nb, c = [list(i) for i in zip(*xy)]\n\nstuck_b = []\nstuck_c = []\nstuck_sum = []\n\nsum = 0\n\nfor cnt_q in range(q):\n sum = 0\n if stuck_b[cnt_q] == b[cnt_q] and stuck_c[cnt_q] == c[cnt_q]:\n print(stuck_sum[cnt_q])\n else:\n for cnt_n in range(n):\n if a[cnt_n] == b[cnt_q]:\n a[cnt_n] = c[cnt_q]\n for num in range(n):\n sum += a[num]\n print(sum)\n', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nxy = [map(int, input().split()) for _ in range(q)]\nb, c = [list(i) for i in zip(*xy)]\n\nans = 0\n\nsum_all = 0\nfor cnt in range(n):\n sum_all += a[cnt]\n\na = sorted(a)\nlist_a_num = [0]*(10**5 + 1)\nfor cnt in range(n):\n list_a_num[a[cnt]] += 1\n\nfor cnt in range(q):\n sum_all += (c[cnt] - b[cnt]) * list_a_num[b[cnt]]\n list_a_num[c[cnt]] += list_a_num[b[cnt]]\n list_a_num[b[cnt]] = 0\n print(sum_all)\n'] | ['Runtime Error', 'Accepted'] | ['s856462111', 's938434753'] | [66840.0, 67052.0] | [371.0, 486.0] | [529, 481] |
p02630 | u317423698 | 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\nfrom collections import Counter\nreadline = sys.stdin.buffer.readline\n\nn = int(readline())\na = Counter(map(int, readline().split()))\nq = int(readline())\nL = []\nfor i in range(q):\n L.append(list(map(int, readline().split())))\n\ns = sum(a)\nfor b, c in L:\n print(a)\n if b in a:\n a[c] += a[b]\n del a[b]\n # print(sum(x * y for x, y in a.items()))\n \nprint(a)\n', 'import sys\nfrom collections import Counter\nreadline = sys.stdin.buffer.readline\n \nn = int(readline())\na = Counter(map(int, readline().split()))\nq = int(readline())\nL = []\nfor i in range(q):\n L.append(list(map(int, readline().split())))\n \ns = sum(x * y for x, y in a.items())\nfor b, c in L:\n # print(a)\n if b in a:\n s += (c - b) * a[b]\n a[c] += a[b]\n del a[b]\n print(s)\n'] | ['Wrong Answer', 'Accepted'] | ['s001329604', 's645529624'] | [82628.0, 35236.0] | [2484.0, 313.0] | [375, 382] |
p02630 | u325956328 | 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\ninput = sys.stdin.readline\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n\n d = Counter(A)\n # print(d)\n\n for i in range(Q):\n ans = 0\n b, c = map(int, input().split())\n if b in d.keys():\n d[c] += d[b]\n d[b] = 0\n for k, v in d.items():\n ans += k * v\n # print(d)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n\n', 'from collections import Counter\nimport sys\n\ninput = sys.stdin.readline\n\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n\n d = Counter(A)\n # print(d)\n ans = sum(A)\n\n for i in range(Q):\n b, c = map(int, input().split())\n if d[b] != 0:\n ans -= d[b] * b\n ans -= d[c] * c\n d[c] += d[b]\n d[b] = 0\n ans += d[c] * c\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n\n'] | ['Runtime Error', 'Accepted'] | ['s546913619', 's666055628'] | [9368.0, 20992.0] | [26.0, 227.0] | [477, 497] |
p02630 | u326278153 | 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())\nsum_res = sum(A)\ncounter = [0 for _ in range(10 ** 5 + 1)]\n\nfor a in A:\n counter[a] += 1\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n sum_res = sum_res - (counter[B] * B)\n sum_res = sum_res + (counter[B] * C)\n counter[C] = counter[B]\n counter[B] = 0\n print(sum_res)\n', 'from collections import Counter\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nsum_res = sum(A)\ncounter = Counter(A)\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n sum_res += (C - B) * counter[B]\n counter[C] += counter[B]\n counter[B] = 0\n print(sum_res)\n'] | ['Wrong Answer', 'Accepted'] | ['s446949423', 's552350949'] | [20760.0, 24004.0] | [487.0, 561.0] | [367, 301] |
p02630 | u340040203 | 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\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n q = int(input())\n ans = []\n a = dict(collections.Counter(a))\n for _ in range(q):\n tmp = 0\n b, c = map(int, input().split())\n if b in a.keys():\n if c in a.keys():\n a[c] = a[b] + a[c]\n else:\n a[c] = a[b]\n del a[b]\n for key, value in a.items():\n tmp += key * value\n ans.append(tmp)\n print(ans)\n\nif __name__ == '__main__':\n main()", "import sys\nimport collections\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n q = int(input())\n ans = [sum(a)]\n a = dict(collections.Counter(a))\n for i in range(q):\n b, c = map(int, input().split())\n if b in a.keys():\n ans.append(ans[i] + ((c - b) * a[b]))\n if c in a.keys():\n a[c] = a[b] + a[c]\n else:\n a[c] = a[b]\n del a[b]\n else:\n ans.append(ans[i])\n print(*ans[1:], sep='\\n')\n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s735092197', 's223764004'] | [21492.0, 21148.0] | [2206.0, 200.0] | [604, 612] |
p02630 | u343490140 | 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 _ in range(q)]\nprint(bc)\nsum = 0\nfor i in range(q):\n for j in range(n):\n if a[j] == bc[i][0]:\n a[j] = bc[i][1]\n for k in range(n):\n sum += a[k]\n print(sum)\n sum = 0', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\nbc = [list(map(int, input().split())) for _ in range(q)]\ns = 0\nfor g in range(len(a)):\n s += a[g]\ne = [0] * 100001\nfor i in a:\n e[i] += 1\nfor j in range(q):\n s += (bc[j][1] - bc[j][0]) * e[bc[j][0]]\n e[bc[j][1]] += e[bc[j][0]]\n e[bc[j][0]] = 0\n print(s)'] | ['Wrong Answer', 'Accepted'] | ['s365371854', 's927443679'] | [35044.0, 32344.0] | [2206.0, 358.0] | [315, 341] |
p02630 | u344030307 | 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\nasum = sum(a)\nadic = {}\n\nfor i in a:\n if i in adic:\n adic[i] += 1\n else:\n adic[i] = 1\n\n\nfor i in range(q):\n b, c = map(int, input().split())\n if b in adic:\n if c not in adic:\n adic[c] = 0\n cnt = adic.pop(b)\n adic[c] += cnt\n if b in adic:\n asum += (c-b) * cnt\n print(asum)\n', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\n\nasum = sum(a)\nadic = {}\n\nfor i in a:\n if i in adic:\n adic[i] += 1\n else:\n adic[i] = 1\n\n\nfor i in range(q):\n b, c = map(int, input().split())\n if b in adic:\n if c not in adic:\n adic[c] = 0\n cnt = adic.pop(b)\n adic[c] += cnt\n asum += (c-b) * cnt\n print(asum)'] | ['Wrong Answer', 'Accepted'] | ['s737507067', 's911271508'] | [21064.0, 20872.0] | [517.0, 512.0] | [372, 355] |
p02630 | u351480677 | 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#print(ans)\nq = int(input())\nimport collections\ncc = collections.Counter(a)\n#print(cc)\nfor i in range(q):\n b,c = map(int,input().split())\n tmp = cc[b]\n cc[b] = 0\n s=s-b*tmp+c*tmp\n cc[c]+=tmp\n print(s)', 'n = int(input())\na = list(map(int,input().split()))\nans = sum(a)\n#print(ans)\nq = int(input())\nimport collections\ncc = collections.Counter(a)\nprint(cc)\nfor i in range(q):\n b,c = map(int,input().split())\n tmp = cc[b]\n cc[b] = 0\n s=s-b*tmp+c*tmp\n cc[c]+=tmp\n print(s)', 'n = int(input())\na = list(map(int,input().split()))\ns = sum(a)\n#print(ans)\nq = int(input())\nimport collections\ncc = collections.Counter(a)\n#print(cc)\nfor i in range(q):\n b,c = map(int,input().split())\n tmp = cc[b]\n cc[b] = 0\n s=s-b*tmp+c*tmp\n cc[c]+=tmp\n print(s)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s584415696', 's919790961', 's147988262'] | [20660.0, 25132.0, 23972.0] | [63.0, 87.0, 553.0] | [283, 282, 281] |
p02630 | u351892848 | 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()))\nQ = int(input())\nB = []\nC = []\nfor _ in range(Q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n\ncounter = Counter(A)\nans = 0\nfor num, count in counter.items():\n ans += num * count\n\nfor i in range(Q):\n if B[i] in counter:\n ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]\n print(ans)\n', 'from collections import Counter\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nB = []\nC = []\nfor _ in range(Q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n\ncounter = Counter(A)\nans = 0\nfor num, count in counter.items():\n ans += num * count\n\nfor i in range(Q):\n if B[i] in counter:\n ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]\n counter[C[i]] = counter[C[i]] + counter.pop([B[i]])\n print(ans)\n', 'from collections import Counter\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nB = []\nC = []\nfor _ in range(Q):\n b, c = map(int, input().split())\n B.append(b)\n C.append(c)\n\ncounter = Counter(A)\nans = 0\nfor num, count in counter.items():\n ans += num * count\n\nfor i in range(Q):\n if B[i] in counter:\n ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]\n counter[C[i]] = counter[C[i]] + counter.pop(B[i])\n print(ans)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s247131492', 's734232725', 's313344846'] | [26096.0, 26084.0, 27344.0] | [334.0, 257.0, 367.0] | [411, 471, 469] |
p02630 | u354804355 | 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. | ['2\n1 2\n3\n1 100\n2 100\n100 1000', 'n= int(input())\na = list(map(int, input().split()))\nq = int(input())\nb = [list(map(int,input().split())) for i in range(q)]\nnum = [0]*(10**5+1)\nfor i in a:\n num[i] += 1\nsum_a = sum(a)\n\nfor i in range(q):\n dif = b[i][1]-b[i][0]\n #print(dif)\n sum_a += dif*num[b[i][0]]\n num[b[i][1]] += num[b[i][0]]\n num[b[i][0]] = 0\n print(sum_a)'] | ['Runtime Error', 'Accepted'] | ['s302626395', 's032204325'] | [8940.0, 32092.0] | [31.0, 339.0] | [28, 335] |
p02630 | u357751375 | 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 = input()\nq = int(input())\nb = list(input().split() for i in range(q))\n\nfor i in range(q):\n j = b[i][0]\n k = b[i][1]\n a = a.replace(j,k)\n l = a.split(' ')\n l = [int(i) for i in l]\n print(sum(l))", 'import collections\nn = int(input())\na = list(map(int,input().split()))\nq = int(input())\nl = [list(map(int,input().split())) for i in range(q)]\nb,c = [list(i) for i in zip(*l)]\nx = collections.Counter(a)\ny = sum(a)\nfor i in range(q):\n if b[i] in x:\n y -= x[b[i]] * b[i]\n y += x[b[i]] * c[i]\n x[c[i]] += x[b[i]]\n x[b[i]] = 0\n print(y)'] | ['Runtime Error', 'Accepted'] | ['s210048552', 's675629563'] | [10640.0, 40120.0] | [26.0, 419.0] | [214, 366] |
p02630 | u364774090 | 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 = list(map(int, input().split()))\nQ = int(input())\nans = []\nfor i in range(Q):\n\tb, c = list(map(int, input().split()))\n\tfor j in range(N):\n\t\tif A[j] == b:\n\t\t\tA[j] = c\n\n\tans += [sum(A)]\n[print(a) for a in ans]', 'N = int(input())\nA = list(map(int, input().split()))\nAA = {}\nt = 0\nfor a in A:\n\tt += a\n\tif a in AA:\n\t\tAA[a] += 1\n\telse:\n\t\tAA[a] = 1\n\nQ = int(input())\nans = []\nfor i in range(Q):\n\tb, c = list(map(int, input().split()))\n\tif b in AA:\n\t\tif c not in AA:\n\t\t\tAA[c] = 0\n\t\tAA[c] += AA[b]\n\t\tt += (c - b) * AA[b]\n\t\tans += [t]\n\t\tdel AA[b]\n\telse:\n\t\tans += [t]\n[print(a) for a in ans]'] | ['Runtime Error', 'Accepted'] | ['s370535097', 's499592836'] | [10680.0, 21384.0] | [30.0, 345.0] | [210, 370] |
p02630 | u370721525 | 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())\nans = sum(A)\nC = Counter(A)\n\nfor i in range(Q):\n b, c = map(int, input().split())\n if C[b] != 0:\n cnt = C[b]\n C[c] += cnt\n C[b] = 0\n print(C)\n ans += (c-b) * cnt\n print(ans)', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nans = sum(A)\nfor i in Q:\n b,c = map(int, input().split())\n cnt = 0\n while b in A:\n A.remove(b)\n A.append(c)\n cnt += 1\n ans += (c-b) * cnt\n \nprint(ans)', 'from collections import Counter\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nans = sum(A)\nC = Counter(A)\n\nfor i in range(Q):\n b, c = map(int, input().split())\n if C[b] != 0:\n cnt = C[b]\n C[c] += cnt\n C[b] = 0\n ans += (c-b) * cnt\n print(ans)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s304787660', 's335266978', 's797980191'] | [69712.0, 20688.0, 21408.0] | [2289.0, 48.0, 530.0] | [293, 234, 280] |
p02630 | u370852395 | 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()))\nQ = int(input())\nl=[]\nfor _ in range(Q):\n l.append(list(map(int,input().split())))\nc = collections.Counter(A)\nsum=sum(A)\nfor i in range(Q):\n print(c)\n if c[l[i][0]] == 0:\n print(sum)\n continue\n else:\n sum+=c[l[i][0]]*(l[i][1]-l[i][0])\n c[l[i][1]]+=c[l[i][0]]\n del c[l[i][0]]\n print(sum)\n', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nl=[]\nfor _ in range(Q):\n l.append(list(map(int,input().split())))\nc = collections.Counter(A)\nsum=sum(A)\nfor i in range(Q):\n if c[l[i][0]] == 0:\n print(sum)\n continue\n else:\n sum+=c[l[i][0]]*(l[i][1]-l[i][0])\n c[l[i][1]]+=c[l[i][0]]\n del c[l[i][0]]\n print(sum)\n'] | ['Wrong Answer', 'Accepted'] | ['s391175859', 's858688376'] | [80508.0, 37616.0] | [2790.0, 401.0] | [412, 399] |
p02630 | u376752722 | 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\nAn = list(map(int, input().split()))\nQ = int(input())\n\nL = [0] * 100001\nfor item in An:\n L[item] += 1\n\nsum = sum(An)\n\nfor i in range(Q):\n b, c = map(int, input().split())\n sum += (c-b) * L[b]\n print(sum)', 'N = int(input())\nAn = list(map(int, input().split()))\nQ = int(input())\n\nbc = [map(int, input().split()) for _ in range(Q)]\nb, c = [list(i) for i in zip(*bc)]\n\n\nfor i in range(Q):\n for j, name in enumerate(An):\n if An[j] == b[i]:\n An[j] = c[i]\n print(An)\n', 'N = int(input())\n\nAn = list(map(int, input().split()))\nQ = int(input())\n\nL = [0] * 100001\nfor item in An:\n L[item] += 1\n\nsum = sum(An)\n\nfor i in range(Q):\n b, c = map(int, input().split())\n sum += (c-b) * L[b]\n L[c] += L[b]\n L[b] = 0\n print(sum)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s436275694', 's715967252', 's354067062'] | [21088.0, 130688.0, 21000.0] | [469.0, 2338.0, 487.0] | [233, 278, 263] |
p02630 | u387080888 | 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=[]\nfor _ in range(Q):\n B.append(list(map(int,input().split())))\ns=sum(A)\nfrom collections import Counter\na=Counter(A)\nb=list(a.keys())\nc=list(a.values())\nfor i in range(Q):\n for j in range(len(set(A))):\n if b[j]==B[i][0]:\n s-=b[j]*c[j]\n s+=B[i][1]*c[j]\n print(s)', 'N=int(input())\nA=list(map(int,input().split()))\nQ=int(input())\nB=[]\nfor _ in range(Q):\n B.append(list(map(int,input().split())))\ns=sum(A)\nfrom collections import Counter\na=Counter(A)\nb=list(a.keys())\nc=list(a.values())\nfor i in range(Q):\n s-=B[i][0]*a[B[i][0]]\n s+=B[i][1]*a[B[i][0]]\n a[B[i][1]]+=a[B[i][0]]\n a[B[i][0]]=0\n print(s)'] | ['Wrong Answer', 'Accepted'] | ['s769081410', 's351230164'] | [37712.0, 39980.0] | [2206.0, 476.0] | [365, 349] |
p02630 | u395202850 | 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. | [' aList[b - 1] = 0\n', "import math\nimport sys\nimport collections\nimport bisect\nreadline = sys.stdin.readline\n\n\ndef main():\n n = int(readline().rstrip())\n A = list(map(int, readline().rstrip().split()))\n counter = collections.Counter(A)\n q = int(readline().rstrip())\n BCList = [list(map(int, readline().rstrip().split())) for _ in range(q)]\n aList = [0] * (10**5 + 10)\n sumA = sum(A)\n for i in range(n):\n aList[A[i] - 1] += 1\n\n for i in range(q):\n b, c = BCList[i][0], BCList[i][1]\n if aList[b - 1] == 0:\n print(sumA)\n continue\n sumA += (c - b) * aList[b - 1]\n aList[c - 1] += aList[b - 1]\n aList[b - 1] = 0\n print(sumA)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s174943739', 's580011518'] | [8884.0, 34508.0] | [25.0, 221.0] | [25, 735] |
p02630 | u395252999 | 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 = sorted(list(map(int, input().split())))\n Q = int(input())\n BC = [list(map(int, input().split())) for i in range(Q)]\n\n for i in range(Q):\n B, C = tuple(BC[i])\n for j in range(N):\n if A[j] == B:\n A[j] = C\n if A[j] > B:\n break\n A = sorted(A)\n print(sum(A))\n\n\nif __name__ == "__main__":\n main()\n', 'def main():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n BC = [list(map(int, input().split())) for i in range(Q)]\n print(BC)\n\n for i in range(Q):\n B, C = BC[i][0], BC[i][1]\n for j in range(len(A)):\n if A[j] == B:\n A[j] = C\n print(sum(A))\n\n\nif __name__ == "__main__":\n main()\n', 'def main():\n N = int(input())\n A = list(map(int, input().split()))\n Q = int(input())\n BC = [list(map(int, input().split())) for i in range(Q)]\n\n g = {}\n ans = 0\n for a in A:\n ans += a\n if a not in g:\n g[a] = 1\n else:\n g[a] += 1\n\n for i in range(Q):\n B, C = tuple(BC[i])\n if B in g:\n t = g.pop(B)\n ans += t * (C - B)\n if C in g:\n g[C] += t\n else:\n g[C] = t\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s724113535', 's917214495', 's389177151'] | [32228.0, 35084.0, 37084.0] | [2206.0, 2207.0, 361.0] | [424, 372, 570] |
p02630 | u395866601 | 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(j)for j in input().split()]\ns=sum(a)\nimport collections\nc=collections.Counter(a)\nq=int(input())\nfor i in range(q):\n x,y=map(int,input().split())\n s+=c[x]*(y-x)\n c[y]+=c[x]\n c[x]=0\n print(s)\nprint(s)\n\n\n\n\n\n', 'n=int(input())\na=[int(j)for j in input().split()]\ns=sum(a)\nimport collections\nc=collections.Counter(a)\nq=int(input())\nfor i in range(q):\n x,y=map(int,input().split())\n s+=c[x]*(y-x)\n c[y]+=c[x]\n c[x]=0\n print(s)\n\n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s829573119', 's783300790'] | [23840.0, 23844.0] | [570.0, 562.0] | [241, 231] |
p02630 | u401686269 | 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()))\ncount = [0 for i in range(110000)]\nsum_ = sum(A)\nfor i in range(N):\n count[A[i]] += 1\n\nQ=int(input())\nfor i in range(Q):\n b,c = map(int,input().split())\n n = count[b]\n sum_ -= b*n\n count[c] += n\n sum_ += c*count[c]\n print(sum_)', 'from collections import defaultdict\n\nN=int(input())\ncount=defaultdict(int)\n*A,=map(int,input().split())\nfor i in range(N):\n count[A[i]] += 1\n \nans = 0\nfor k in count.keys():\n ans += count[k]*k\n\nQ=int(input())\nfor q in range(Q):\n b,c = map(int,input().split())\n ans += c*count[b] - b*count[b]\n count[c] += count[b]\n count[b] = 0\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s943426919', 's323128320'] | [90336.0, 24168.0] | [2316.0, 564.0] | [282, 347] |
p02630 | u406355300 | 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())\nresult = 0\nfor i in a:\n result += i\nfor j in range(Q):\n b,c = map(int,input().split())\n while b in a:\n a[a.index(b)] = c\n result += c-b\n print(result)\n\n\n', 'N = int(input())\na = list(map(int,input().split()))\nQ = int(input())\ncnt = [0]*1000001\nresult = 0\nfor i in a:\n cnt[i] += 1\n result += i\nfor j in range(Q):\n b,c = map(int,input().split())\n cnt[c] += cnt[b]\n n = cnt[b]\n cnt[b] = 0\n result += (c-b)*n\n print(result)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s512041333', 's912489095'] | [21004.0, 23800.0] | [2206.0, 508.0] | [252, 288] |
p02630 | u407702479 | 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()))\nn=sum(A)\nM=[]\nP=[]\nfor _ in range(int(input())):\n B,C=map(int,input().split())\n if P.count(B)>0:\n n=n-P.count(B)*M[P.index(B)]*(B-C)\n else:\n n=n-A.count(B)*(B-C)\n if A.count(B)>0:\n M.append(A.count(B))\n P.append(C)\n print(n)', 'N=int(input())\nA=list(map(int,input().split()))\ns=sum(A)\nnum=[0]*100001\nfor i in A:\n num[i]+=1\nfor _ in range(int(input())):\n B,C=map(int,input().split())\n s+=(C-B)*num[B]\n num[C]+=num[B]\n num[B]=0\n print(s)'] | ['Wrong Answer', 'Accepted'] | ['s710346162', 's544182665'] | [21008.0, 20992.0] | [2206.0, 486.0] | [315, 225] |
p02630 | u418826171 | 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\ninput = sys.stdin.readline()\nN = int(input())\nA = list(map(int,input().split()))\nQ = int(input())\nB = [0]*Q\nC = [0]*Q\nnum = [0]*100000\ns = sum(A)\nfor i in range(Q):\n B[i], C[i] = map(int,input().split())\nfor i in range(100000):\n num[i] = A.count(i+1)\nfor i in range(Q):\n s += (C[i]-B[i])*num[B[i]-1]\n print(s)\n num[C[i]-1] += num[B[i]-1]\n num[B[i]-1] = 0', 'import sys\ninput = sys.stdin.readline\nN = int(input())\nA = tuple(map(int,input().split()))\nQ = int(input())\ncnt = [0]*100005\ns = sum(A)\nfor i in A:\n cnt[i] += 1\nfor i 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'] | ['Runtime Error', 'Accepted'] | ['s231399138', 's627116264'] | [9168.0, 20684.0] | [20.0, 178.0] | [383, 289] |
p02630 | u440129511 | 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\na=list(map(int,input().split()))\ns=sum(a)\nd=Counter(a)\nfor i in range(q):\n b,c=map(int,input().split())\n if b in d:\n l=d[b]\n d[b]=0\n d[c]+=l\n s+=(c-b)*l\n print(s)\n else:print(s)', 'from collections import Counter\nn=int(input())\na=list(map(int,input().split()))\nq=int(input())\ns=sum(a)\nd=Counter(a)\nfor i in range(q):\n b,c=map(int,input().split())\n if b in d:\n l=d[b]\n d[b]=0\n d[c]+=l\n s+=(c-b)*l\n print(s)\n else:print(s)'] | ['Runtime Error', 'Accepted'] | ['s863481930', 's615854722'] | [9492.0, 21528.0] | [28.0, 547.0] | [253, 283] |
p02630 | u440975163 | 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())\np = [list(map(int, input().split())) for _ in range(q)]\nfrom collections import Counter\nc = Counter(a)\nfor i in range(q):\n if p[i][0] in c:\n c[p[i][1]] += c[p[i][0]]\n c[p[i][0]] = 0\n print(c)\n ans = 0\n for i in c:\n ans += c[i] * i\n print(ans)', 'n = int(input())\na = list(map(int, input().split()))\nq = int(input())\np = [list(map(int, input().split())) for _ in range(q)]\n\n\ncounter = [0] * 1000000\nfor i in a:\n counter[i] += 1\n \nans = sum(a)\n \nfor _ in p:\n ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]\n counter[_[1]] += counter[_[0]]\n counter[_[0]] = 0\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s823813537', 's849998716'] | [67292.0, 39200.0] | [2258.0, 338.0] | [352, 344] |
p02630 | u455408345 | 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(""))\nain=input("").split(" ")\na={1:0,}\nc=[]\nfor i in range(n):\n c+=[int(ain[i])]\ns=sum(c)\nfor i in range(n):\n if (c[i] in a):\n a[c[i]]+=1\n else:\n a[c[i]]=1\nq=int(input(""))\nc=[]\nlistb=[]\nlistc=[]\nfor i in range(q):\n c=+[input("").split(" ")]\n listb+=[int(c[i][0])]\n listc+=[int(c[i][1])]\n if (listb[i] in a and a[listb[i]]!=0):\n s+=(listc[i]-listb[i])*a[listb[i]]\n if (listc[i] in a):\n a[listc[i]]+=a[listb[i]]\n else:\n a[listc[i]]=a[listb[i]]\n \n print(s)\n \n \n \n', ' \nn=int(input(""))\na=[]\nn-=1\nfor i in range(11):\n if (n==0):\n break\n a+=[n%26+1]\n n=int(n/26)\nb=[]\nfor i in range(len(a)):\n b+=[a[len(a)-i-1]]\n\ns=""\nfor i in b:\n if (i==1):\n s+="a"\n elif(i==2):\n s+="b"\n elif(i==3):\n s+="c"\n elif(i==4):\n s+="d"\n elif(i==5):\n s+="e"\n elif(i==6):\n s+="f"\n elif(i==7):\n s+="g"\n elif(i==8):\n s+="h"\n elif(i==9):\n s+="i"\n elif(i==10):\n s+="j"\n elif(i==11):\n s+="k"\n elif(i==12):\n s+="l"\n elif(i==13):\n s+="m"\n elif(i==14):\n s+="n"\n elif(i==15):\n s+="o"\n elif(i==16):\n s+="p"\n elif(i==17):\n s+="q"\n elif(i==18):\n s+="r"\n elif(i==19):\n s+="s"\n elif(i==20):\n s+="t"\n elif(i==21):\n s+="u"\n elif(i==22):\n s+="v"\n elif(i==23):\n s+="w"\n elif(i==24):\n s+="x"\n elif(i==25):\n s+="y"\n elif(i==26):\n s+="z"\nprint(s)\n \n \n', 'n=int(input(""))\nain=input("").split(" ")\na={1:0,}\nc=[]\nfor i in range(n):\n c+=[int(ain[i])]\ns=sum(c)\nfor i in range(n):\n if (c[i] in a):\n a[c[i]]+=1\n else:\n a[c[i]]=1\nq=int(input(""))\nc=[]\n\nfor i in range(q):\n c=input("").split(" ")\n bb=int(c[0])\n cc=int(c[1])\n if (bb in a and a[bb]!=0):\n s+=(cc-bb)*a[bb]\n if (cc in a):\n a[cc]+=a[bb]\n else:\n a[cc]=a[bb]\n a[bb]=0\n \n print(s)\n \n \n \n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s215038150', 's798013279', 's365519890'] | [24740.0, 9160.0, 24208.0] | [87.0, 29.0, 558.0] | [566, 1029, 510] |
p02630 | u458315482 | 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\nprint(BC)\n\nfor i in range(Q):\n for j in range(N):\n if A[j] == BC[i][0]:\n A[j] = BC[i][1]\n print(sum(A))\n', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\nBC = [list(map(int, input().split())) for i in range(Q)]\n\ndef calc(A):\n ans = 0\n for i in range(len(A)):\n ans += A[i] * (i + 1)\n\n return ans\n\nVALUE = [0 for i in range(100000)]\n\nfor i in range(N):\n VALUE[A[i] - 1] += 1\n\nANS = []\nANS.append(calc(VALUE))\n\nfor i in range(Q):\n VALUE[BC[i][1] - 1] += VALUE[BC[i][0] - 1]\n ANS.append(ANS[i] + (BC[i][1] - BC[i][0]) * VALUE[BC[i][0] - 1])\n VALUE[BC[i][0] - 1] = 0\n\nfor i in range(1, Q + 1):\n print(ANS[i])\n'] | ['Wrong Answer', 'Accepted'] | ['s057237836', 's410720814'] | [35124.0, 37960.0] | [2207.0, 419.0] | [256, 551] |
p02630 | u461463382 | 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())\n\nnum_A = [A.count(i) for i in range(10**5+1)]\nfirst = sum(np.array(num_A)*np.array([j for j in range(10**5+1)]))\n\nfor i in range(Q):\n b, c = map(int, input().split())\n first += b*num_A[c]\n first -= b*num_A[b]\n num_A[c] += num_A[b]\n num_A[b] = 0\n print(first)', 'import numpy as np\n\nN = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nnum_A = [A.count(i) for i in range(10**5+1)]\nfirst = sum(np.array(num_A)*np.array([j for j in range(10**5+1)]))\n\nfor i in range(Q):\n b, c = map(int, input().split())\n first += b*num_A[c]\n first -= b*num_A[b]\n num_A[c] += num_A[b]\n num_A[b] = 0\n print(first)', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nnum_A = [0 for i in range(10**5+1)]\nfirst = 0\n\nfor a in A:\n num_A[a] += 1\n first += a\n\nfor i in range(Q):\n b, c = map(int, input().split())\n first += c*num_A[b]\n first -= b*num_A[b]\n num_A[c] += num_A[b]\n num_A[b] = 0\n print(first)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s613063279', 's971237525', 's201905820'] | [39060.0, 38688.0, 20728.0] | [2207.0, 2206.0, 491.0] | [366, 366, 326] |
p02630 | u464205401 | 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())\nx=[0]*10**6\nsum_a=sum(a)\nfor _ in range(q):\n b,c=list(map(int,input().split()))\n x[c]=a.count(b)\n sum_a+=(c-b)*(x[c]+x[b])\n x[c]+=a.count(b)\n# print(x)\n print(sum_a)', 'from collections import defaultdict\n\nn = int(input())\na = list(map(int,input().split()))\nq = int(input())\nd = defaultdict(int)\n\nfor aa in a:#initialize\n d[aa]+=1\n\nans=sum(a)\nfor i in range(q):\n b,c = list(map(int,input().split()))\n d[c]+=d[b]\n ans+=(c-b)*d[b] \n d[b]=0\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s305668416', 's884744138'] | [23812.0, 24012.0] | [2206.0, 559.0] | [250, 286] |
p02630 | u465652095 | 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())\narr = list(map(int,input().split()))\ncnt = collections.defaultdict(int)\nfor val in arr:\n cnt[val] += 1\nsums = sum(arr)\nq = int(input())\nfor _ in range(q):\n b, c = map(int,input().split())\n diff = (c-b)*(cnt[b])\n sums += diff\n print(sums)\n cnt[c] += nt[b]\n cnt[b] = 0', 'import collections\nn = int(input())\narr = list(map(int,input().split()))\ncnt = collections.defaultdict(int)\nfor val in arr:\n cnt[val] += 1\nsums = sum(arr)\nq = int(input())\nfor _ in range(q):\n b, c = map(int,input().split())\n diff = (c-b)*(cnt[b])\n sums += diff\n print(sums)\n cnt[c] += cnt[b]\n cnt[b] = 0\n'] | ['Runtime Error', 'Accepted'] | ['s748120703', 's925733119'] | [21412.0, 24132.0] | [75.0, 554.0] | [323, 325] |
p02630 | u483331319 | 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 = map(int, input().split())\nQ = int(input())\n\nfrom collections import defaultdict\ncount = defaultdict(int)\n\nfor a in A:\n count[a] += 1\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n if count[B] > 0:\n count[C] += count[B]\n count[B] = 0\n\n# print(count)\nans = 0\nfor k, v in count.items():\n ans += k * v\n\nprint(ans)', 'N = int(input())\nA = list(map(int, input().split()))\nQ = int(input())\n\nfrom collections import defaultdict\ncount = defaultdict(int)\n\nfor a in A:\n count[a] += 1\n\nans = sum(A)\n\nfor _ in range(Q):\n B, C = map(int, input().split())\n if count[B] > 0:\n ans += C * count[B]\n ans -= B * count[B]\n count[C] += count[B]\n count[B] = 0\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s529727323', 's657806586'] | [22452.0, 23136.0] | [297.0, 508.0] | [348, 352] |
p02630 | u497277272 | 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 collections\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n \n cnt = collections.defaultdict(int)\n for var in a:\n cnt[var] += 1\n \n sum_a = sum[a]\n \n q = int(input())\n for _ in range(q):\n b, c = list(map(int, input().split()))\n diff = (c-b) * cnt[b]\n sum_a += diff\n print(sum_a)\n cnt[c] += cnt[b]\n cnt[b] = 0\n \nif __name__ == '__main__':\n main()", "import collections\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n \n cnt = collections.defaultdict(int)\n for var in a:\n cnt[var] += 1\n \n sum_a = sum(a)\n \n q = int(input())\n for _ in range(q):\n b, c = list(map(int, input().split()))\n diff = (c-b) * cnt[b]\n sum_a += diff\n print(sum_a)\n cnt[c] += cnt[b]\n cnt[b] = 0\n \nif __name__ == '__main__':\n main()"] | ['Runtime Error', 'Accepted'] | ['s630461408', 's663799865'] | [21296.0, 24132.0] | [69.0, 529.0] | [461, 460] |
p02630 | u503111914 | 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()))\nD = collections.Counter(A)\nQ = int(input())\n#print(D)\nans = sum(A)\nfor i in range(Q):\n B,C = map(int,input().split())\n #print(D[B],type(D[B]))\n ans += (C-B)*D[B]\n print(ans)', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nD = collections.Counter(A)\nQ = int(input())\n#print(D)\nans = sum(A)\nfor i in range(Q):\n B,C = map(int,input().split())\n #print(D[B],type(D[B]))\n ans += (C-B)*D[B]\n D[C] = D[B] + D[C]\n D[B] = 0\n #print(D)\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s209118290', 's611862590'] | [21400.0, 24108.0] | [502.0, 583.0] | [256, 306] |
p02630 | u503228842 | 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\nabc = 'abcdefghijklmnopqrstuvwxyz'\nans = ''\nwhile N > 0:\n N -= 1\n ans = abc[(N%26)] + ans\n N //= 26\nprint(ans)", 'from collections import Counter\nN = int(input())\nA = list(map(int,input().split()))\ns = sum(A)\nQ = int(input())\nc = Counter(A)\nfor _ in range(Q):\n B,C = map(int,input().split())\n s -= B*c[B]\n s += C*c[B]\n c[C] += c[B]\n c[B] = 0\n print(s)'] | ['Wrong Answer', 'Accepted'] | ['s165819164', 's937408720'] | [8940.0, 24016.0] | [29.0, 582.0] | [137, 255] |
p02630 | u523087093 | 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 = np.array(list(map(int, input().split())))\nQ = int(input())\nBC = [tuple(map(int, input().split())) for _ in range(Q)]\n\nfor i in range(Q):\n temp = [A == BC[i][0]] * BC[i][1]\n A = A + temp\n print(sum(A))\n', 'import numpy as np\nN = int(input())\nA = np.array(list(map(int, input().split())))\nQ = int(input())\nBC = [tuple(map(int, input().split())) for _ in range(Q)]\n\nfor i in range(Q):\n temp = [A == BC[i][0]] * BC[i][1]\n A = A + temp\n print(A.sum())\n', 'import numpy as np\nN = int(input())\nA = np.array(list(map(int, input().split())))\nQ = int(input())\nBC = [tuple(map(int, input().split())) for _ in range(Q)]\n\nfor i in range(Q):\n temp = A == BC[i][0]\n temp = temp.astype(np.int)\n temp = temp * BC[i][1]\n\n temp2 = A != BC[i][0]\n temp2 = temp2.astype(np.int)\n\n A = A*temp2 + temp\n\n print(A.sum())\n', 'import numpy as np\nN = int(input())\nA = np.array(list(map(int, input().split())))\nQ = int(input())\nBC = [tuple(map(int, input().split())) for _ in range(Q)]\ntotal = sum(A)\n\nA_dict = {}\nfor a in A:\n if a in A_dict:\n A_dict[a] += 1\n else:\n A_dict[a] = 1\n\nfor i in range(Q):\n b = BC[i][0]\n c = BC[i][1]\n\n if b in A_dict:\n total += (c - b) * A_dict[b]\n print(total)\n \n if c in A_dict:\n A_dict[c] += A_dict[b]\n else:\n A_dict[c] = A_dict[b]\n A_dict[b] = 0\n \n else:\n print(total)'] | ['Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Accepted'] | ['s171318441', 's172981656', 's608200703', 's047537655'] | [3502196.0, 3502988.0, 44500.0, 47500.0] | [2278.0, 2271.0, 2207.0, 572.0] | [250, 251, 364, 578] |
p02630 | u531599639 | 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())\nnums = Counter(a)\nm = sum(a)\nprint(nums)\nfor _ in range(q):\n b,c = map(int,input().split())\n nums[c] += nums[b]\n k = nums[b]\n nums[b] = 0\n m = m + (c-b)*k\n print(m)\nprint(nums)', 'from collections import Counter\nn = int(input())\na = list(map(int,input().split()))\nq = int(input())\nnums = Counter(a)\nm = sum(a)\nfor _ in range(q):\n b,c = map(int,input().split())\n nums[c] += nums[b]\n k = nums[b]\n nums[b] = 0\n m = m + (c-b)*k\n print(m)'] | ['Wrong Answer', 'Accepted'] | ['s120523963', 's662709724'] | [33348.0, 24016.0] | [653.0, 573.0] | [283, 259] |
p02630 | u532549251 | 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#List = list(map(int, input().split()))\n#req = [list(map(int, input().split())) for _ in range(q)]\n#t = t[:-1]\n\n#[0]*n\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\nreq = [list(map(int, input().split())) for _ in range(q)]\ncount = [0]*100000\nsum = 0\nans = [0]*q\n\nfor i in range(100000):\n count[i] = a.count(i+1)\n\nfor j in a:\n sum += j\n\nfor k in range(q):\n diff = req[k][1] - req[k][0]\n diff = diff * count[req[k][0] - 1]\n count[req[k][1] - 1] += count[req[k][0] - 1]\n count[req[k][0] - 1] = 0\n sum += diff\n ans[k] = sum\n\nprint(ans)\n', '\n#List = list(map(int, input().split()))\n#req = [list(map(int, input().split())) for _ in range(q)]\n#t = t[:-1]\n\n#[0]*n\nn = int(input())\na = list(map(int, input().split()))\nq = int(input())\nreq = [list(map(int, input().split())) for _ in range(q)]\ncount = [0]*100001\nsum = sum(a)\n\nfor i in a:\n count[i] += 1\n\nfor k in range(q):\n sum += (req[k][1] - req[k][0]) * count[req[k][0]]\n count[req[k][1]] += count[req[k][0]]\n count[req[k][0]] = 0\n print(sum)\n'] | ['Wrong Answer', 'Accepted'] | ['s798541969', 's408815236'] | [33344.0, 32252.0] | [2207.0, 344.0] | [663, 548] |
p02630 | u541921833 | 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().rstrip())\nAs = {}\nanswer = 0\nfor a in [int(x) for x in input().rstrip().split()]:\n answer += a\n if a in As.keys():\n As[a] += 1\n else:\n As[a] = 1\n# print(As)\nQ = int(input().rstrip())\nd = {}\nfor i in range(Q):\n b, c = map(int, input().rstrip().split())\n d[i] = {'b': b, 'c': c}\n# print(d)\nfor i in sorted(d.keys()):\n if d[i]['b'] in As.keys():\n diff = d[i]['c'] - d[i]['b']\n diff_num = As.pop(d[i]['b'])\n if d[i]['c'] in As.keys():\n As[d[i]['c']] += diff_num\n else:\n As[d[i]['c']] = diff_num\n answer += (diff * diff_num)\n print(answer)\nprint('---')\n\n\n", "N = int(input().rstrip())\nAs = {}\nanswer = 0\nfor a in [int(x) for x in input().rstrip().split()]:\n answer += a\n if a in As.keys():\n As[a] += 1\n else:\n As[a] = 1\n# print(As)\nQ = int(input().rstrip())\nd = {}\nfor i in range(Q):\n b, c = map(int, input().rstrip().split())\n d[i] = {'b': b, 'c': c}\n# print(d)\nfor i in sorted(d.keys()):\n if d[i]['b'] in As.keys():\n diff = d[i]['c'] - d[i]['b']\n diff_num = As.pop(d[i]['b'])\n if d[i]['c'] in As.keys():\n As[d[i]['c']] += diff_num\n else:\n As[d[i]['c']] = diff_num\n answer += (diff * diff_num)\n print(answer)\n"] | ['Wrong Answer', 'Accepted'] | ['s023486227', 's301078527'] | [55100.0, 54944.0] | [411.0, 433.0] | [658, 643] |
p02630 | u544865362 | 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 = input()\narr = [int(x) for x in input().split()]\n\nq = int(input())\nans = sum(arr)\n\nhashmap = {}\nfor val in arr:\n if val in hashmap:\n hashmap[val] += 1\n else:\n hashmap[val] = 1\n\n\nwhile q > 0:\n print(hashmap)\n [x, y] = [int(x) for x in input().split()]\n if x in hashmap:\n if y in hashmap:\n hashmap[y] += hashmap[x]\n ans -= hashmap[x]*x\n ans += y*hashmap[x]\n else:\n diff = hashmap[x] * x\n ans -= diff\n hashmap[y] = hashmap[x]\n del hashmap[x]\n add = hashmap[y] * y\n ans += add\n \n print(ans)\n q -=1', "N = input()\narr = [int(x) for x in input().split()]\n\nq = int(input())\nans = sum(arr)\n\nhashmap = {}\nfor val in arr:\n if val in hashmap:\n hashmap[val] += 1\n else:\n hashmap[val] = 1\n\n\nwhile q > 0:\n print(hashmap)\n [x, y] = [int(x) for x in input().split()]\n if x in hashmap:\n if y in hashmap:\n hashmap[y] += hashmap[x]\n ans -= hashmap[x]*x\n ans += y*hashmap[x]\n else:\n diff = hashmap[x] * x\n ans -= diff\n hashmap[y] = hashmap[x]\n del hashmap[x]\n add = hashmap[y] * y\n ans += add\n \n print('ans', ans)\n q -=1", 'N = input()\narr = [int(x) for x in input().split()]\n\nq = int(input())\nans = sum(arr)\n\nhashmap = {}\nfor val in arr:\n if val in hashmap:\n hashmap[val] += 1\n else:\n hashmap[val] = 1\n\n\nwhile q > 0:\n\n [x, y] = [int(x) for x in input().split()]\n if x in hashmap:\n if y in hashmap:\n hashmap[y] += hashmap[x]\n ans -= hashmap[x]*x\n ans += y*hashmap[x]\n del hashmap[x]\n else:\n diff = hashmap[x] * x\n ans -= diff\n hashmap[y] = hashmap[x]\n del hashmap[x]\n add = hashmap[y] * y\n ans += add\n \n print(ans)\n q -=1'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s787012551', 's863722169', 's609052601'] | [147516.0, 147496.0, 20780.0] | [1972.0, 5858.0, 525.0] | [652, 659, 661] |
p02630 | u554096168 | 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\n\nN = int(input())\n_A = [*map(int, input().split())]\nQ = int(input())\nval = [[*map(int, line.split())] for line in open(0)]\n\nA = defaultdict(int)\nfor _a in _A:\n A[_a] += 1\n\nans = sum(_A)\nfor v in val:\n if v[0] in A.keys():\n num = A[v[0]]\n A[v[0]] = 0\n A[v[1]] += num\n ans += (v[1] - v[0]) * num\n print(ans)\n', 'from collections import defaultdict\n\nN, _A, Q, *val = [[*map(int, line.split())] for line in open(0)]\nN = N[0]\nQ = Q[0]\n\nA = defaultdict(int)\nfor _a in _A:\n A[_a] += 1\n\nans = sum(_A)\nfor v in val:\n if v[0] in A.keys():\n num = A[v[0]]\n A[v[0]] = 0\n A[v[1]] += num\n ans += (v[1] - v[0]) * num\n print(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s485351987', 's140877334'] | [36660.0, 36388.0] | [261.0, 274.0] | [379, 340] |
p02630 | u564770050 | 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 _ in range(q)]\ntemp = [0] * (10**5 + 1)\n\nfor i in a:\n temp[i] += 1\nans = sum(a)\nfor i in range(q):\n b,c = bc[i][0],bc[i][1]\n ans = ans - temp[b] * b + temp[b] * c \n print(sum(temp))\n temp[c] += tremp[b]', '\n \ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n q = int(input())\n bc =[list(map(int, input().split())) for _ in range(q)]\n temp = [0] * (10**5 + 1)\n \n for i in a:\n temp[i] += 1\n ans = sum(a)\n for i in range(q):\n b,c = bc[i][0],bc[i][1]\n ans = ans - temp[b] * b + temp[b] * c \n print(ans)\n temp[c] += temp[b]\n temp[b] = 0\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Accepted'] | ['s194357703', 's925399489'] | [32048.0, 32108.0] | [252.0, 312.0] | [328, 451] |
p02630 | u566574814 | 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\nb=[]\nc=[]\nfor i in range(q):\n d,e=input().split()\n b.append(int(d))\n c.append(int(e))\n\nfor i in range(q):\n for j in range(len(b)):\n if a[i] == b[j]:\n a[i]=c[j]\n # if a[-1] ==b[j]:\n # a[-1]=c[i]\nprint(sum(a))\n # print(a)\n# print(a)\n# print(b)\n# print(c)', 'n=int(input())\na=list(map(int,input().split()))\n\nL=[0]*(100001)\ns=sum(a)\n\nfor i in a:\n L[i] +=1\n\nq= int(input())\nfor _ in range(q):\n b, c = map(int,input().split())\n L[c] += L[b]\n s+= L[b]*(c-b)\n L[b]=0\n print(s)\n# b=[]\n# c=[]\n\n# d,e=input().split()\n# b.append(int(d))\n# c.append(int(e))\n\n\n\n# for j in range(q):\n\n\n# if a[j]==b[i]:\n# a[j]=c[i]\n# else:\n\n# for j in range(q):\n# if a[i] == b[j]:\n# a[i]=c[j]\n\n# # if a[i] == b[i]:\n# # a[i]=c[j]\n# # if a[-1] ==b[j]:\n# # a[-1]=c[i]\n# print(sum(a))\n\n\n\n# # print(a)\n# # print(a)\n# # print(b)\n# # print(c)'] | ['Runtime Error', 'Accepted'] | ['s310656918', 's371849715'] | [22168.0, 21000.0] | [2206.0, 483.0] | [375, 895] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.