Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
A = tuple(map(int, input().split()))
mod = 10**9+7

ans = 0
for k in range(60):
    num1 = 0
    num0 = 0
    for a in A:
        if (a >> k) & 1:
            num1 += 1
        else:
            num0 += 1
    ans += num1 * num0 * pow(2, k) % mod
    ans %= mod

print(ans)

### FIXED CODE ###

N = int(input())
A = tuple(map(int, input().split()))
mod = 10**9+7

def solve(N, A):
    ans = 0
    for k in range(61):
        num1 = 0
        for a in A:
            if (a >> k) & 1:
                num1 += 1
        ans += (num1 * (N-num1)) << k
        ans %= mod
    return ans
    
print(solve(N, A))
### BUGGY CODE ###

from itertools import combinations as com

n=int(input())
L=list(map(int,input().split()))
ans=0
for i,j,k in com(L,3):
    if i+j>k and j+k>i and k+i>j:
        ans+=1
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+=bisect.bisect_left(L,L[i]+L[j])-(j+1)
print(ans)
### BUGGY CODE ###

from bisect import bisect_left

n, m, q = map(int, input().split())
LR = [0]*m
for i in range(m):
    LR[i] = list(map(int, input().split()))
P = [0]*q
Q = [0]*q
for i in range(q):
    P[i], Q[i] = map(int, input().split())

LR.sort(key=lambda x: x[0])
L = list(map(lambda x: x[0], LR))

for i in range(q):
    l = bisect_left(L, P[i])
    r = bisect_left(L, Q[i]+1)-1
    cnt = 0
    for j in range(l, r+1):
        if LR[j][1] <= Q[i]:
            cnt += 1
    print(cnt)


### FIXED CODE ###

from bisect import bisect_left
 
n, m, q = map(int, input().split())
LR = [0]*m
for i in range(m):
    LR[i] = list(map(int, input().split()))
P = [0]*q
Q = [0]*q
for i in range(q):
    P[i], Q[i] = map(int, input().split())
 
LR.sort(key=lambda x: (x[0], x[1]))
L = list(map(lambda x: x[0], LR))
#print(LR)
 
C = [[0]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
    l = bisect_left(L, i)
    r = bisect_left(L, i+1)-1
    R2 = list(map(lambda x: x[1], LR[l:r+1]))
    #print(l, r, R2)
    for j in range(i,n+1):
        C[i][j] = bisect_left(R2, j+1)
    #print(i, C[i])
 
for i in range(q):
    ans = 0
    for j in range(P[i], Q[i]+1):
        ans += C[j][Q[i]]
    print(ans)
### BUGGY CODE ###

from collections import Counter
def change_dict_key(d, old_key, new_key, default_value=None):
    d[new_key] = d.pop(old_key, default_value)

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

q=int(input())
for _ in range(q):
    b,c=map(int,input().split())
    if b in a_cnt.keys():
        if c in a_cnt.keys():
            a_cnt[c]+=a_cnt[b]
            a_cnt.pop(b)
        else:
            change_dict_key(a_cnt,b,c)
    ans=0
    for key,value in a_cnt.items():
        ans+=key*value
    print(ans)


### FIXED CODE ###

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

sum=0
num=[0]*(10**5+1)
for i in range(n):
    sum+=a[i]
    num[a[i]]+=1

q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    sum+=(c-b)*num[b]
    print(sum)
    num[c]+=num[b]
    num[b]=0
### BUGGY CODE ###

s = list(str(input()))

sum = 0
i = 0
flag = 0
while  i < len(s) :

    if s[i] == 'B':
        flag +=1
        i = i+1
    else:
        sum += flag
        s[i] = 'B'
        s[i-flag] = 'W'
        i = i - flag + 1
        flag = 0           

print(sum)

### FIXED CODE ###

s = list(str(input()))

sum = 0
bcount = 0
for i in range(len(s)):
    if s[i] == 'B' :
        bcount += 1
    else :
        sum += bcount

print(sum)
### BUGGY CODE ###

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

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n % 2 != 0:
    b.reverse()

print(*b, sep=' ')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
b = []

for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

if n % 2 != 0:
    even.reverse()
    b = even + odd
else:
    odd.reverse()
    b = odd + even

print(*b, sep=' ')
### BUGGY CODE ###

import queue as q

def main():
    N, M = list(map(int, input().split()))
    D = {}
    for m in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        D.setdefault(u, set()).add(v)

    S, T = list(map(int, input().split()))
    S -= 1
    T -= 1
    print(f(D, S, T))

def f(D, S, T):
    close = [set(), set(), set()]
    Q = q.Queue()
    Q.put((S, 0, 0))

    while not Q.empty():
        p, c, l = Q.get()
        if l % 3 == 0 and p == T:
            return c
        close[l].add(p)

        if not p in D:
            continue

        ns = D[p]
        l, c = (l + 1) % 3, c + (l + 1) // 3
        for n in ns:
            if n in close[l]:
                continue
            Q.put((n, c, l))
    return -1

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))

def f(D, S, T):
    close = [[False] * N, [False] * N, [False] * N]
    Q = []
    index = 0
    Q.append((S, 0, 0))

    while len(Q) > index:
        p, c, l = Q[index]
        index += 1
        
        if close[l][p]:
            continue
        
        if l == 0 and p == T:
            return c // 3
        close[l][p] = True

        l, c = (l + 1) % 3, c + 1
        for n in D[p]:
            if close[l][n]:
                continue
            Q.append((n, c, l))
    return -1

if __name__ == "__main__":
    D = {n: set() for n in range(N)}
    for m in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        D[u].add(v)

    S, T = list(map(int, input().split()))
    S -= 1
    T -= 1

    print(f(D, S, T))
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-



import numpy as np


H, W, D = map(int, input().split())

A = []

for i in range(H):
    A.append(list(map(int, input().split())))

A = np.array(A)

Q = int(input())

for i in range(Q):
    L, R = map(int, input().split())
    cost = 0
    while L != R:
        start = np.where(A==L)
        stop  = np.where(A==L+D)
        cost += abs(start[0][0] - stop[0][0]) + abs(abs(start[1][0] - stop[1][0]))
        L += D
    print(cost)


### FIXED CODE ###

# speed-test
# https://abc089.contest.atcoder.jp/submissions/2206669

h,w,d = map(int,input().split())
 
dic = {}
for i in range(h):
    a = input().split()
    for j in range(w):
        dic[int(a[j])] = (i+1,j+1)
        
q = int(input())
c = [0]*(h*w+1)
for i in range(d+1,h*w+1):
    pi,pj = dic[i]; qi,qj = dic[i-d]
    c[i] = c[i-d] + abs(pi-qi) + abs(pj-qj)
    
for i in range(q):
    l,r = map(int,input().split())
    print(c[r]-c[l])
### BUGGY CODE ###

# encoding:utf-8
def main():
	N, K = list(map(int, input().split()))
	nums = list(map(int, input().split()))

	max_num = max(nums)
	min_num = min(nums)

	# 最大値が越えてたらだめ
	if K > max_num:
		return("IMPOSSIBLE")

	decomp_min = decomp(min_num)
	for x in decomp_min:
		res = [y % x for y in nums]

		# 共通因子を持ってなかったらだめ
		if max(res) == min(res):
			if K % x > 0:
				return("IMPOSSIBLE")
	else:
		return("POSSIBLE")

def decomp(n):
	i = 2
	table = [n]

	while i <= n:
		if n % i == 0:
			table.append(int(i))
		i += 1
	return(table)

if __name__ == '__main__':
	print(main())

### FIXED CODE ###

import functools as ft

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a

def main():
	N, K = list(map(int, input().split()))
	nums = list(map(int, input().split()))

	max_num = max(nums)
	g = ft.reduce(lambda x, y: gcd(x, y), nums)

	if K <= max_num and K % g == 0:
		print("POSSIBLE")
	else:
		print("IMPOSSIBLE")

if __name__ == '__main__':
	main()
### BUGGY CODE ###

n,m = map(int,input().split(' '))
cost = 0
count = 0

mlist = list()
for i in range(n):
  mlist.append(list(map(int,input().split(' '))))
  mlist.sort(key=lambda x: x[0])
#  print(mlist)


for i in range(n):
  ablist = mlist[i]
#  print(ablist)
  for j in range(ablist[1]):
    count += 1
    if count <= m:
      cost += ablist[0]
#      print(count,"本", cost,"円")
print(cost)



### FIXED CODE ###

n,m = map(int,input().split(' '))
cost = 0
count = 0

mlist = list()
for i in range(n):
  mlist.append(list(map(int,input().split(' '))))
mlist.sort(key=lambda x: x[0])

for i in range(n):
  ablist = mlist[i]
  if count+ablist[1] <= m:
    count += ablist[1]
    cost += ablist[0]*ablist[1] 
  else:
    for j in range(ablist[1]):
      count += 1
      if count <= m:
        cost += ablist[0]
      else:
        break_t = True
        break
    if break_t:
      break
print(cost)
### BUGGY CODE ###

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

def solve(not_used, index, cur_elem, cost, cur_min):
    #print("\t" * index, cur_elem, cost)
    if index == N:
        return cost
    for i in not_used:
        if (index - i) % 2 == 0:
            if A[i] >= cur_elem:
                cost_delta = 0
                for j in range(i, N):
                    if j not in not_used:
                        cost_delta += 1
                new_cost = cost + cost_delta
                if new_cost < cur_min:
                    cur_min = min(cur_min, solve(not_used - {i}, index + 1, A[i], new_cost, cur_min))
        else:
            if B[i] >= cur_elem:
                cost_delta = 0
                for j in range(i, N):
                    if j not in not_used:
                        cost_delta += 1
                new_cost = cost + cost_delta
                if new_cost < cur_min:
                    cur_min = min(cur_min, solve(not_used - {i}, index + 1, B[i], new_cost, cur_min))
    return cur_min

ans = solve({i for i in range(N)}, 0, -1, 0, 100000)
if ans == 100000:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

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

dp = [[100100] * (1 << N) for _ in range(N)]
for i in range(N):
    dp[i][1 << i] = 0
for mask in range(1, 1 << N):
    mask_pop = format(mask, 'b').count('1')
    for j in range(N):
        if (1 << j) & mask:
            if (j - mask_pop) % 2 == 1:
                cur_elem = A[j]
            else: 
                cur_elem = B[j]
            prev_mask = mask & ~(1 << j)
            cost_delta = format(prev_mask & (-1 << j), 'b').count('1')
            for t in range(N):
                if (1 << t) & prev_mask:
                    prev_elem = A[t] if (t - mask_pop - 1) % 2 == 1 else B[t]
                    if prev_elem <= cur_elem:
                        if dp[j][mask] > dp[t][prev_mask] + cost_delta:
                            dp[j][mask] = dp[t][prev_mask] + cost_delta
            
# print(*dp, sep = '\n')

ans = min((dp[i][-1] for i in range(N)))
if ans == 100100:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import sys
import copy
import time
import random

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

D = None
C = None
S = None

def cnt_score(t):
    global D, C, S
    score = 0
    cnt = [-1] * 26

    for i in range(D):
        score += S[i][t[i] - 1]
        minusscore = 0
        cnt[t[i] - 1] = i
        for j in range(26):
            minusscore += (i - cnt[j]) * C[j]
        score -= minusscore
    return score


def main():
    global D, C, S
    D = int(input())
    C = [int(x) for x in input().split()]
    S = [[int(x) for x in input().split()] for _ in range(D)]

    start = time.time()

    ans = []
    for s in S:
        ans.append(C.index(max(C)) + 1)

    # 初期値をランダムで探す
    while True:
        # time up
        current = time.time()
        if current - start > 1.0:
            break

        # main
        new_ans = []
        for _ in range(D):
            new_ans.append(random.randint(1, 26))

        if cnt_score(new_ans) > cnt_score(ans):
            ans = new_ans

    #ans = [1] * D

    day = 0
    while True:
        # time up
        current = time.time()
        if current - start > 1.9:
            break

        # main
        new_ans = copy.deepcopy(ans)
        old_score = cnt_score(ans)

        max_sore = old_score
        max_contest = ans[day]
        for i in range(26):
            new_ans[day] = i + 1
            new_score = cnt_score(new_ans)
            if new_score > old_score:
                max_contest = i + 1
                old_score = new_score
        ans[day] = max_contest

        # increment day
        day = (day + 1) % D

    for a in ans:
        print(a)



if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    D = int(input())
    C = [int(x) for x in input().split()]
    S = [[int(x) for x in input().split()] for _ in range(D)]


    for i in range(D):
        print(i % 26 + 1)



if __name__ == '__main__':
    main()
### BUGGY CODE ###

import fractions
import copy
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(str(r1))

### FIXED CODE ###

import fractions
import sys

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

if n1 == 2:
    print(max(nl1))
    sys.exit()

r1 = 0

nl1.sort()

if n1 >= 3:
    n2 = fractions.gcd(nl1[0], nl1[1]) 
    n2 = max(n2, fractions.gcd(nl1[1], nl1[2]))
    n2 = max(n2, fractions.gcd(nl1[0], nl1[2]))

c1 = 0
for i2 in range(n1):
    if nl1[i2] % n2 != 0:
        c1 += 1
    if c1 >= 2:
        break
    if i2 == (n1 - 1):
        r1 = n2

i3 = n2

while r1 == 0:
    c1 = 0
    for i4 in range(n1):
        if nl1[i4] % i3 != 0:
            c1 += 1
        if c1 >= 2:
            break
        if i4 == (n1 - 1):
            r1 = i3
    i3 -= 1

print(str(r1))
### BUGGY CODE ###

import numpy as np
from fractions import gcd
from functools import reduce

LARGE_INT = 10 ** 9 + 7

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

input()
A = list(map(int, input().split()))
lcm = lcm_list(A)

total = 0
for a in A:
    total += lcm // a % LARGE_INT
    total %= LARGE_INT
print(total)

### FIXED CODE ###

import sys
from fractions import gcd

input = sys.stdin.buffer.readline

LARGE = 10 ** 9 + 7

def lcm(x, y):
    return (x * y) // gcd(x, y)

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

l = 1
for a in A:
    l = lcm(l, a)

total = 0
for a in A:
    total += l // a

print(total % LARGE)
### BUGGY CODE ###

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

D = [[]]
for i in range(1, N):
  DD = []
  T = [0]
  for j in range(i, N, i):
    T.append(T[-1] + s[j])
  DD.append(T)
  T = [0]
  start = (N - 1) % i
  if start == 0: start += i
  for j in range(start, N, i):
    T.append(T[-1] + s[j])
  DD.append(T)
  D.append(DD)

ans = s[-1]
cnt = 0
for n in range(2, N - 1):
  end = N - 1 - n
  for m in make_divisors(end):
    if n <= m: break
    if n % m == 0 and end >= n: continue
    k = end // m
    a = D[m][0][k]
    l = len(D[m][1])
    b = D[m][1][-1] - D[m][1][l - k - 2]
    ans = max(ans, a + b)

print(ans)

### FIXED CODE ###

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

D = [[]]
for i in range(1, N):
  DD = []
  T = [0]
  for j in range(i, N, i):
    T.append(T[-1] + s[j])
  DD.append(T)
  T = [0]
  start = (N - 1) % i
  if start == 0: start += i
  for j in range(start, N, i):
    T.append(T[-1] + s[j])
  DD.append(T)
  D.append(DD)

ans = s[-1]
cnt = 0
for n in range(2, N - 1):
  end = N - 1 - n
  for m in make_divisors(end):
    if n <= m: break
    if n % m == 0 and end >= n: continue
    k = end // m
    a = D[m][0][k]
    l = len(D[m][1])
    b = D[m][1][-1] - D[m][1][l - k - 2]
    ans = max(ans, a + b)

print(ans)
### BUGGY CODE ###

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, factorial
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, M, R = map(int, input().split())
    R = list(map(lambda x: int(x) - 1, input().split()))

    matrix = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        matrix[a - 1][b - 1] = c
        matrix[b - 1][a - 1] = c

    for i in range(N):
        matrix[i][i] = 0

    for m in range(N):
        for s in range(N):
            for e in range(N):
                if matrix[s][m] != INF and matrix[m][e] != INF:
                    matrix[s][e] = min(matrix[s][e], matrix[s][m] + matrix[m][e])

    ans = INF
    for r in permutations(R):
        tmp = 0
        for i in range(len(r) - 1):
            tmp += matrix[r[i]][r[i + 1]]
        ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict
from itertools import product, groupby, permutations
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N, M, R = map(int, input().split())
    r_list = list(map(int, input().split()))
    dp = [[float("inf")] * (N + 1) for _ in range(N + 1)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        dp[A][B] = dp[B][A] = C

    for i in range(N):
        dp[i][i] = 0

    for m in range(N + 1):
        for s in range(N + 1):
            for e in range(N + 1):
                dist = dp[s][m] + dp[m][e]
                if dist < dp[s][e]:
                    dp[s][e] = dist

    ans = float("inf")
    for p in permutations(r_list, len(r_list)):
        total = 0
        for i in range(len(p) - 1):
            total += dp[p[i]][p[i + 1]]
            if total >= ans:
                break
        else:
            if total < ans:
                ans = total
    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import math
 
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
    p,c = [int(i) for i in input().split()]
    P.append(p)
    C.append(c)

# cnt = 0
# def count():
#     global cnt
#     cnt+=1
#     print(cnt)

def flag(point,P,now):
    if point+100*(now+1)*P >= g: return 1
    else: return 0

m = 10**9
def score(point = 0, n = 0, now=-1, done=[]):
    global m
    if m <= n: return
    elif point >= g: m = n
    elif flag(point,P[now],now):
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: m = n
    else:
        if now == -1:
            for i in range(d):
                score(point, n, i, done)
        elif m <= n+P[now]: return
        else:
            done = done[:]
            done.append(now)
            for i in range(d):
                if not i in done:
                    score(point+P[now]*100*(now+1) + C[now], n + P[now], i, done)

score()
print(m)

### FIXED CODE ###

import math
 
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
    p,c = [int(i) for i in input().split()]
    P.append(p)
    C.append(c)

# cnt = 0
# def count():
#     global cnt
#     cnt+=1
#     print(cnt)

def flag(point,P,now):
    if point+100*(now+1)*(P-1) >= g: return 1
    elif point+100*(now+1)*P + C[now] >= g: return 2
    else: return 0

m = 10**9
def score(point = 0, n = 0, now=-1, remain = list(range(d))):
    global m
    if m <= n: return
    elif now == -1:
        for i in remain:
            score(point, n, i, remain)
    elif point >= g: m = n
    elif flag(point,P[now],now) == 1:
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: m = n
    elif flag(point,P[now],now) == 2:
        n += P[now]
        if m > n: m = n
    else:
        if m <= n+P[now]: return
        else:
            remain = remain[:]
            remain.remove(now)
            nxtp = point + P[now]*100*(now+1) + C[now]
            for i in remain:
                score(nxtp, n + P[now], i, remain)

score()
print(m)
### BUGGY CODE ###

k = int(input())
sum_ = 0

def gcd(x, y):
    while y != 0:
        r = x % y
        x = y
        y = r
    return x

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            sum_ += gcd(gcd(i, j), l)
        
print(sum_)

### FIXED CODE ###

import math

k = int(input())
sum_ = 0

for i in range(1, k+1):
    for j in range(1, k+1):
        x = math.gcd(i, j)
        for l in range(1, k+1):
            sum_ += math.gcd(x, l)
            
print(sum_)
### BUGGY CODE ###

import math
n = int(input())
def g(x,y,z):
    t = x**2 + y**2 + z**2 + x*y + y*z + z*x
    #print(x,y,z,t)
    return t
ans = []
def f(n):
    #sum = 0
    rn = int(math.sqrt(n))
    for i in range(1,rn+1):
        #print(i,end='')
        for j in range(1,rn+1):
            for k in range(1,rn+1):
                #print(i,j,k)
                t = g(i,j,k)
                if t == n:
                    if (i == j and j==k):
                        #sum += 1
                        ans.append(str(1))
                        return
                    elif (i == j and j != k and i != k) or (i == k and j != k and i != j) or (i != j and j == k and i != k):
                        #sum += 3
                        ans.append(str(3))
                        return
                    else:#elif i != j and i != k and j != k:
                        #sum += 6
                        ans.append(str(6))
                        return
                elif t > n:
                    break
    ans.append(str(0))
                

    

for i in range(1,n+1):
    f(i)


print('\n'.join(ans))

### FIXED CODE ###

n = int(input())
ans = [0]*(10**4+1)
for x in range(1,10**2+1):
    for y in range(1,10**2+1):
        for z in range(1,10**2+1):
            i = x*x + y*y + z*z + x*y + x*z + y*z
            if i <= 10**4:
                ans[i] += 1
            else:
                break
#print(ans)
for i in range(1,n+1):
    print(ans[i])
### BUGGY CODE ###

s=input()
q=int(input())
c=1
t=[s]
for i in range(q):
    qu=input().split()
    if qu[0]=="1":
        c*=-1
    else:
        if c==1:
            if qu[1]=="1":
                t.append(qu[2]+t[-1])
            else:
                t.append(t[-1]+qu[2])
        else:
            if qu[1]=="1":
                t.append(t[-1]+qu[2])
            else:
                t.append(qu[2]+t[-1])
if c==1:
    print(t[-1])
else:
    print(t[-1][::-1])

### FIXED CODE ###

s=input()
q=int(input())
c=1
u=''
for i in range(q):
    inp=input()
    if inp[0]=="1":
        c*=-1
    else:
        t,f,p=inp.split()
        if (f=="1" and c!=1) or (f=="2" and c==1):
            s+=p
        else:
        	u+=p
if c!=1:
    print("".join(reversed(s))+u)
else:
    print("".join(reversed(u))+"".join(s))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  
  for j in range(n):
    if a[j]==b:
      a[j]=c
  print(sum(a))

### FIXED CODE ###

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