Harryxun/stf_run huggingface dataset:
n = int(input())
a = map(int, input().split(" "))

color_types = [False]*8
pro_count = 0
for a_i in a:
	if a_i < 3200:
		color_types[a_i//400] = True
	else:
		pro_count += 1
print(color_types)
print(sum(max(1,　color_types)), min(8, sum(color_types)+pro_count))

### FIXED CODE ###

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

color_types = [False]*8
pro_count = 0
for a_i in a:
	if a_i < 3200:
		color_types[a_i//400] = 1
	else:
		pro_count += 1
print(max(1, sum(color_types)), sum(color_types)+pro_count)
def cost( i,k,j ):
  return m[i][k] + m[k+1][j] + p[i][0] * p[k][1] * p[j][1]
 
n = input()
M = []
m = [ [ 0 for i in range(n) ] for j in range(n) ]
for i in xrange(n):
  M.append( map ( int , raw_input().split() ) )


for l in xrange( 2,n+1 ):
  for i in xrange( 0,n-l+1 ):
    j = i + l - 1
    m[i][j] = min( cost( i,k,j ) for k in xrange( i,j ) )
 
print m[0][n-1]

### FIXED CODE ###

def cost( i,k,j ):
  return m[i][k] + m[k+1][j] + M[i][0] * M[k][1] * M[j][1]
 
n = input()
M = []
m = [[ 0 for i in range(n) ] for j in range(n) ]
for i in range(n):
  M.append( map (int, raw_input().split() ) )
 
M_long = len(M)
for l in range( 2,M_long+1 ):
  for i in range( 0,M_long-l+1 ):
    j = i+l-1
    m[i][j] = min( cost( i,k,j ) for k in range( i,j ) )
 
print m[0][M_long-1]
n,k = map(int, input().split())
h = list(map(int, input().split()))
count = 0
for i in range(n):
  if h[n] >= k:
    count += 1
print(count)

### FIXED CODE ###

n,k = map(int, input().split())
h = list(map(int, input().split()))
count = 0
for i in range(n):
  if h[i] >= k:
    count += 1
print(count)
q=int(input())
import math
import numpy as np
def is_prime(n):
    if n==1:return False
    for k in range(2,int(math.sqrt(n))+1):
        if n%k==0:
            return False
    return True
def is_is_prime(n):
    an=0
    if is_prime((n+1)//2)==True:
        if is_prime(n)==True:
            an=1
    return an
ko=[]
for i in range(1,10**5,2):
    ko.append(is_is_prime(i))

koko=np.cumsum(ko)

for i in range(q):
    l,r=map(int,input().split()) 
    if l==r:       
        if is_is_prime(l)==True:
            print(1)
        else:
            print(0)
    else:
        print(koko[r]-koko[l])

### FIXED CODE ###

q=int(input())
import math
import numpy as np
def is_prime(n):
    if n==1:return False
    for k in range(2,int(math.sqrt(n))+1):
        if n%k==0:
            return False
    return True
def is_is_prime(n):
    an=0
    if is_prime((n+1)//2)==True:
        if is_prime(n)==True:
            an=1
    return an
ko=[]
for i in range(1,10**5,2):
    ko.append(is_is_prime(i))

koko=np.cumsum(ko)

for i in range(q):
    l,r=map(int,input().split()) 
    if l==1:
        ans=koko[(r-1)//2]-koko[(l-1)//2]
    else:
        ans=koko[((r-1)//2)]-koko[((l-1)//2)-1]
    print(ans)
def main():
    import math
    n = int(input())
    h = list(map(int, input().split()))
    # dpテーブル作成,スタート地点のdpテーブルの値は0にする
    dp =[math.inf] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    for i in range(2,n):
        dp[i] = min([dp[i], dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])])
    print(dp[n-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    h = list(map(int, input().split()))
    # dpテーブル作成,スタート地点のdpテーブルの値は0にする
    dp =[10**5] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    for i in range(2,n):
        dp[i] = min([dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])])
    print(dp[n-1])

if __name__ == "__main__":
    main()
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
l=[]
if n>m:
  print(0)
  exit()
for i in range(1,len(x)):  
  for j in range(i,len(x)):
    l.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))
print(min(n))


### FIXED CODE ###

n,m=map(int,input().split())
x=list(map(int,input().split()))
l=[]
ans=0
if n<m:
  x.sort()
  for i in range(m-1):
    l.append(x[i+1]-x[i])
  l.sort()
  for j in range(m-n):
    ans+=l[j]
print(ans)
S = input()

check_str = 'LR'
S_=[]
s_temp = ''
for s in range(len(S)):
    s_temp += S[s]
    
    if s < len(S)-1:
        s_= s+1 
        if S[s]=='L' and S[s_] == 'R':
            S_.append(Counter(s_temp))
            s_temp =''
            
    else:
        S_.append(Counter(s_temp))

def get_ans_temp(S_temp):
    S_R = S_temp['R']
    S_L = S_temp['L']
    
    S_R_ans=[0]*S_R
    S_L_ans=[0]*S_L
    
    if (S_R + S_L) % 2 ==0 :#偶数の時
        S_R_ans[-1] = (S_R + S_L) // 2
        S_L_ans[0] = (S_R + S_L) // 2

    elif S_R != S_L :#奇数の時
        if S_R > S_L:
            S_R_ans[-1] = (S_R + S_L) // 2 +1
            S_L_ans[0] = (S_R + S_L) // 2         
        else:
            S_R_ans[-1] = (S_R + S_L) // 2
            S_L_ans[0] = (S_R + S_L) // 2 + 1
            
        max_RL_num = max(S_R,S_L)
        if max_RL_num % 2 == 0:
            _ = S_R_ans[-1]
            S_R_ans[-1]=S_L_ans[0]
            S_L_ans[0]=_

    ans_temp = []
    ans_temp.extend(S_R_ans)
    ans_temp.extend(S_L_ans)
    return ans_temp

ans_list=[]
for S_temp in S_:
    ans_list.extend(get_ans_temp(S_temp))
    
ans=' '.join(map(str,ans_list))

print(ans)

### FIXED CODE ###

from collections import Counter
S = input()

check_str = 'LR'
S_=[]
s_temp = ''
for s in range(len(S)):
    s_temp += S[s]
    
    if s < len(S)-1:
        s_= s+1 
        if S[s]=='L' and S[s_] == 'R':
            S_.append(Counter(s_temp))
            s_temp =''
            
    else:
        S_.append(Counter(s_temp))

def get_ans_temp(S_temp):
    S_R = S_temp['R']
    S_L = S_temp['L']
    
    S_R_ans=[0]*S_R
    S_L_ans=[0]*S_L
    
    if (S_R + S_L) % 2 ==0 :#偶数の時
        S_R_ans[-1] = (S_R + S_L) // 2
        S_L_ans[0] = (S_R + S_L) // 2

    elif S_R != S_L :#奇数の時
        if S_R > S_L:
            S_R_ans[-1] = (S_R + S_L) // 2 +1
            S_L_ans[0] = (S_R + S_L) // 2         
        else:
            S_R_ans[-1] = (S_R + S_L) // 2
            S_L_ans[0] = (S_R + S_L) // 2 + 1
            
        max_RL_num = max(S_R,S_L)
        if max_RL_num % 2 == 0:
            _ = S_R_ans[-1]
            S_R_ans[-1]=S_L_ans[0]
            S_L_ans[0]=_

    ans_temp = []
    ans_temp.extend(S_R_ans)
    ans_temp.extend(S_L_ans)
    return ans_temp

ans_list=[]
for S_temp in S_:
    ans_list.extend(get_ans_temp(S_temp))
    
ans=' '.join(map(str,ans_list))

print(ans)
import sys
from operator import itemgetter
import collections

def r(n, p):
  m = n + 1
  count = 0
  for i in range(n):
    m = min(p[i], m)
    if m == p[i]:
      count += 1
  return count

def main():
    input = sys.stdin.readline
    n = int(input())
    p = map(int, input().split())
    print(r(n,p))

    
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from operator import itemgetter
import collections

def r(n, p):
  m = n + 1
  count = 0
  for i in range(n):
    m = min([p[i], m])
    if m == p[i]:
      count += 1
  return count

def main():
    input = sys.stdin.readline
    n = int(input())
    p = list(map(int, input().split()))
    print(r(n,p))

    
if __name__ == '__main__':
    main()
D = int(input())
C = "Chiristmas"
if 22 <= D <= 25:
  for i in range(D, 25):
    C += " Eve"
	print(C)

### FIXED CODE ###

D = int(input())
C = "Christmas"
if 22 <= D <= 25:
	for i in range(D, 25):
		C += " Eve"
	print(C)
import bisect
from collections import defaultdict

S=list(input().strip())
T=list(input().strip())
L=len(S)

if set(T)>set(S):
  print(-1)
  exit()

d=defaultdict(list)
for i,s in enumerate(S):
  d[s].append(i)
start=-1
ans=0
for i in T:
  p=bisect.bisect_right(d[i],start)
  le=len(d[i])
  if p==le:
    ans+=(L-start-1)+(d[i][0]+1)
    start=d[i][0]    
  else:
    ans+=d[i][p]-start
    start=d[i][p]
print(ans)

### FIXED CODE ###

import bisect
from collections import defaultdict

S=list(input().strip())
T=list(input().strip())
L=len(S)

if not set(T)<=set(S):
  print(-1)
  exit()

d=defaultdict(list)
for i,s in enumerate(S):
  d[s].append(i)
start=-1
ans=0
for i in T:
  p=bisect.bisect_right(d[i],start)
  le=len(d[i])
  if p==le:
    ans+=(L-start-1)+(d[i][0]+1)
    start=d[i][0]    
  else:
    ans+=d[i][p]-start
    start=d[i][p]
print(ans)
W, H, x, y = map(int, input().split())
full = W*H
count = 0
if x == (W/2):
    if y == (H/2):
        men = W*H/2
        print(men)
        print(1)
    else:
        men = W*H/2
        print(men)
        print(0)
elif y==(H/2):
    men = W*H/2
    print(men)
    print(0)

else:
    X1 = x*H
    X2 = (W-x)*H
    X = [X1, X2]
    XX = max(X)
    Y1 = W*y
    Y2 = W*(H-y)
    Y = [Y1, Y2]
    YY = max(Y)
    if XX == YY:
        print(menseki)
        print(1)
    else:
        menseki = min(XX, YY)
        print(menseki)
        print(0)

### FIXED CODE ###

W, H, x, y = map(int, input().split())
if x == (W/2):
    if y == (H/2):
        men = W*H/2
        print(men)
        print(1)
    else:
        men = W*H/2
        print(men)
        print(0)
else:
        men = W*H/2
        print(men)
        print(0)
N,L = map(str,input().split())

words = list()
for i in range(N):
  words.append(input())
  
words.sort()

print(*words,seq ="")


### FIXED CODE ###

N,L = map(int,input().split())

words = list()
for i in range(N):
  words.append(input())
  
words.sort()

print(*words,sep ="")
N=int(input())
ans=1
for x in range(3,N+1):
    tmp=x-1
	ans+=tmp//x
 
print(ans)

### FIXED CODE ###

N=int(input())
ans=0
for x in range(1,N):
  ans+=(N-1)//x
print(ans)
N=int(input())
X=set(str(N))
Y=len(X)
if Y==1
  print(N)
if Y!=1:
  Z=0
  for i in range(111,1000,111):
    if N-i<0:
      Z+=i
      break
  print(Z)

### FIXED CODE ###

N=int(input())
X=set(str(N))
Y=len(X)
if Y==1:
  print(N)
if Y!=1:
  Z=0
  for i in range(111,1000,111):
    if N-i<0:
      Z+=i
      break
  print(Z)
N, M = map(int, input().split())
point = input().split()
thr = 0
good = 0
bad = 0

if M == 0:
    print("0 0")
else:
    for i in range(M - 1):
        if point[0] == str(thr):
            point = input().split()
            continue
        elif point[1] == "AC":
            good += 1
            thr = point[0]
            point = input().split()
            continue
        elif point[1] == "WA":
            bad += 1
            point = input().split()
            continue
    print(str(good), str(bad))


### FIXED CODE ###

tmp = ord(input())
tmp += 1
print(chr(tmp))
a=input()
for i in range(9):
 if a%(9-i)==0 and a/(9-i)<10:
  print("yes")
  break
else:
 print("no")

### FIXED CODE ###

a=int(input())
for i in range(9):
 if a%(9-i)==0 and a/(9-i)<10:
  print("Yes")
  break
else:
 print("No")
import numpy as np
mod = 10**9+7
N = int(input())
s = input()
dp = [[0]*N for _ in range(N)]
for i in range(N):
    dp[0][i] = 1
for i in range(1, N):
    if s[i-1] == '>':
        dp[i][0] = dp[i-1][0]
        for j in range(1, N-i):
            dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod
    else:
        for j in range(N-1)[::-1]:
            dp[i][j] = (dp[i][j+1]+dp[i-1][j+1])%mod
print(sum(dp[-1])%mod)

### FIXED CODE ###

mod = 10**9+7
N = int(input())
s = input()
dp = [[0]*N for _ in range(N)]
for i in range(N):
    dp[0][i] = 1
for i in range(1, N):
    if s[i-1] == '>':
        dp[i][0] = dp[i-1][0]
        for j in range(1, N-i):
            dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod
    else:
        for j in range(N-1)[::-1]:
            dp[i][j] = (dp[i][j+1]+dp[i-1][j+1])%mod
print(sum(dp[-1])%mod)
n=int(input())
s=input()
stack=[]
for c in s:
    if len(stack)>0 and stack[-1]=='(' and c==')':
        stack.pop()
    else:
        stack.append(c)
if len(stack)==0:
    print(s)
else:
    l=0
    r=0
    for c in stack:
        if c==')':
            l+=1
        else:
            r+=1
print('('*l+s+')'*r)


### FIXED CODE ###

n=int(input())
s=input()
stack=[]
l=0
r=0
for c in s:
    if len(stack)>0 and stack[-1]=='(' and c==')':
        stack.pop()
    else:
        stack.append(c)
if len(stack)==0:
    print(s)
else:
    for c in stack:
        if c==')':
            l+=1
        else:
            r+=1
    print('('*l+s+')'*r)
import fractions
#import math
def lcm(x, y):
	return int((x * y) / fractions.gcd(x, y));
	#return (x * y) // math.gcd(x, y);

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
num_c = int(b/c) - int((a-1)/c);
num_d = int(b/d) - int((a-1)/d); 
num_cd = int(b/lcm(c, d)) - int((a-1)/lcm);
print(b - a + 1 -(num_c + num_d - num_cd))

### FIXED CODE ###

import fractions
#import math
def lcm(x, y):
	return (x * y) // fractions.gcd(x, y);
	#return (x * y) // math.gcd(x, y);

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
num_c = b//c - (a-1)//c;
num_d = b//d - (a-1)//d; 
num_cd = b//lcm(c, d) - (a-1)//lcm(c,d);
print(b - a + 1 -(num_c + num_d - num_cd))
N = int(input())
ex_t, ex_x, ex_y = 0, 0, 0
count = 0
for i in range(N):
    t, x, y = map(int, input().split())
    if abs(x-ex_x) + abs(y-ex_y) <= abs(t-ex_t) and t%2 = (x+y)%2:
        count += 1
    ex_t, ex_x, ex_y = t, x, y
print('Yes' if count == N else 'No')

### FIXED CODE ###

N = int(input())
ex_t, ex_x, ex_y = 0, 0, 0
count = 0
for i in range(N):
    t, x, y = map(int, input().split())
    if abs(x-ex_x) + abs(y-ex_y) <= abs(t-ex_t) and t%2 == (x+y)%2:
        count += 1
    ex_t, ex_x, ex_y = t, x, y
print("Yes" if count == N else "No")
s = input()
ans = ""
for i in range(len(s)//2 + 1):
    ans += str(s[2*i])
print(ans)


### FIXED CODE ###

s = input()
ans = ""
for i in range((len(s)+1)//2):
    ans += str(s[2*i])
print(ans)
X,Y=map(int,input().split())

def cmb(nn, rr, mod):
    if ( rr<0 or rr>nn ):
        return 0
    rr = min(rr, nn-rr)
    return g1[nn] * g2[rr] * g2[nn-rr] % mod

if (X+Y)%3 != 0:
      print(0)
      exit()
 
if min(X,Y)*2<max(X,Y):
    print(0)
    exit()

n,x,y=0,X,Y
while x != y*2:
      x-=1
      y-=2
      n+=1
m=((X+Y)//3)-n

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = cmb(n+m,n,mod)
print(ans)


### FIXED CODE ###

X,Y=map(int,input().split())

mod=10**9+7
def nCr(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

if (X+Y)%3 != 0:
      print(0)
      exit()
 
n=((2*X)-Y)//3

m=((X+Y)//3)-n

if n<0 or m<0:
    print(0)
    exit()

ans = nCr(n+m,n,mod)
print(ans)
n = input().split()
a = list(map(int, input().split()))
b = 0
c = []
count = 0


while(True):
    T = False
    for i in range(len(a)):
        if a[i]%2 != 0 :
            T = True 
        
        if T:
            break


    for i in range(len(a)):
        b = a[i] / 2
        c.append(b)
        
    a = c
    count+=1


print(count)


### FIXED CODE ###


s = input()
a = [int(c) for c in s]

print(a[0] + a[1] + a[2])
from collections import defaultdict
import numpy as np

n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)])

x = xy[xy.argsort(axis=0)[:, 0]]
y = xy[xy.argsort(axis=0)[:, 1]]

x = [list(x) for x in np.diff(x, axis=0)]
y = [list(y) for y in np.diff(y, axis=0)]


memo_x = defaultdict(int)
memo_y = defaultdict(int)

for i, j in zip(x, y):
    memo_x[str(i)] += 1
    memo_y[str(j)] += 1

print(n - max(max(memo_x.values()), max(memo_x.values())))

### FIXED CODE ###

from collections import defaultdict
import numpy as np
import sys

n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)])

if n == 1:
    print(1)
    sys.exit()

memo = defaultdict(int)

for i in xy:
    for j in xy:
        if np.all(i == j):
            continue
        else:
            tmp = j - i
            if tmp[0] < 0:
                tmp *= -1
            elif tmp[0] == 0 and tmp[1] < 0:
                tmp *= -1
            memo[str(tmp)] += 1

print(n - max(memo.values()) // 2)
count_n = int(input())
N = []
n = input()
N = n.split()
N = list(map(lambda x: int(x), N)).sort()


count_p = int(input())
P = []
p = input()
P = p.split()
P = list(map(lambda x: int(x), P)).sort()


def b(i, l):
    left = 0
    right = len(l)
    while left < right:
        mid = int((left + right) / 2)
        if l[mid] > i:
            right = mid
        elif l[mid] < i:
            left = mid + 1
        elif l[mid] == i:
            return True
    return False
answer = 0
for n in N:
    if b(n, P):
        answer += 1
print (answer)

### FIXED CODE ###

count_n = int(input())
N = []
n = input()
N = n.split()
N = list(map(lambda x: int(x), N))


count_p = int(input())
P = []
p = input()
P = p.split()
P = list(map(lambda x: int(x), P))


N.sort()
P.sort()


def b(i, l):
    left = 0
    right = len(l)
    while left < right:
        mid = int((left + right) / 2)
        if l[mid] > i:
            right = mid
        elif l[mid] < i:
            left = mid + 1
        elif l[mid] == i:
            return True
    return False
answer = 0
for p in P:
    if b(p, N):
        answer += 1
print (answer)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)] 
 
graph = [[] for _ in range(N+1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p, x in PX:
    value[p] +=x
 
def dfs(v, parent, add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x, v, value[v])
 
dfs(1, 0, 0)
ans = ' '.join(map(str,value[1:]))
print(ans)

### FIXED CODE ###

n = int(input())
s = input()

if n >= 3200:
    print(s)
else:
    print("red")
class Node:
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right

    def get_type(self):
        if self.parent == -1: return "root"
        elif self.left == -1: return "leaf"
        else: return "internal node"

def set_depth(u,d):
    global D
    global tree
    D[u] = d
    if not tree[u].right == -1:
        set_depth(tree[u].right, d)
    if not tree[u].left == -1:
        set_depth(tree[u].left, d+1)

def print_tree(t,D):
    for i in range(len(t)):
        children = []
        c = t[i].left
        if not c == -1:
            while True:
                children.append(c)
                c = t[c].right
                if c == -1: break
        print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children)))

n = int(raw_input().strip())

tree = {}
for i in range(n):
    tree[i] = Node(-1, -1, -1)
for _ in range(n):
    entry = map(int, raw_input().strip().split(' '))
    nid = entry[0]
    n_child = entry[1]
    for i in range(n_child):
        if i == 0: tree[nid].left = entry[i+2]
        else: tree[entry[i+1]].right = entry[i+2]
        tree[entry[i+2]].parent = nid

r = -1
for i in range(n):
    if tree[i].parent == -1: r = i

D = {}
set_depth(r, 0)

print_tree(tree, D)

### FIXED CODE ###

class Node:
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right

    def get_type(self):
        if self.parent == -1: return "root"
        elif self.left == -1: return "leaf"
        else: return "internal node"

def set_depth(u,d):
    global D
    global tree
    D[u] = d
    v = tree[u].right
    while not v == -1:
        D[v] = d
        if not tree[v].left == -1:
            set_depth(tree[v].left, d+1)
        v = tree[v].right
    if not tree[u].left == -1:
        set_depth(tree[u].left, d+1)

def print_tree(t,D):
    for i in range(len(t)):
        children = []
        c = t[i].left
        if not c == -1:
            while True:
                children.append(c)
                c = t[c].right
                if c == -1: break
        print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children)))

n = int(raw_input().strip())

tree = {}
for i in range(n):
    tree[i] = Node(-1, -1, -1)
for _ in range(n):
    entry = map(int, raw_input().strip().split(' '))
    nid = entry[0]
    n_child = entry[1]
    for i in range(n_child):
        if i == 0: tree[nid].left = entry[i+2]
        else: tree[entry[i+1]].right = entry[i+2]
        tree[entry[i+2]].parent = nid

r = -1
for i in range(n):
    if tree[i].parent == -1: r = i

D = {}
set_depth(r, 0)

print_tree(tree, D)
a=[]
for i in range(1200):
    b=input()
    if b=="":
        continue
    else:
        a=a+[str(x) for x in b.lower().replace(" ","",100)]
for i in "abcdefghijklmnopqrstuvwxyz":
    counter=0
    for j in a:
        if i==j:
            counter+=1
    print(str(i)+" : "+str(counter))

### FIXED CODE ###

import sys
cnts = {}
for line in sys.stdin:
    for c in list(line.lower()): cnts[c] = cnts.get(c,0) + 1
  
for c in range(ord('a'),ord('z')+1): print(chr(c),':',cnts.get(chr(c),0))
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c<2 :
        print('0')
    elif (math.sqrt(a*b)==c and a!=b:
        print(2*c-3)
    elif c*(c+1)<a*b:
        print(2*c-1)
    else:
        print(2*c-2)

### FIXED CODE ###

import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c*(c+1)<a*b: print(2*c-1)
    elif a*b==c*c and a!=b:  print(2*c-3)
    else:  print(2*c-2)
import numpy as np
n,d=map(int,input().split())
v=[]
for i in range(n):
  v.append(np.array(list(map(int,input().split()))))
  
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dist=np.linalg.norm(v[i]-v[j], ord = 2)
    if int(dist) == dist:
      ans += 1

print(ans)


### FIXED CODE ###

import numpy as np
n,d=map(int,input().split())
v=[]
for i in range(n):
  v.append(np.array(list(map(int,input().split()))))
  
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dist=np.linalg.norm(v[i]-v[j], ord = 2)
    if int(dist) == dist:
      ans += 1

print(ans)
n, m =map(int,input().split())
c = list(map(int,input().split()))

INF = 10**10
dp = [INF]*(n+max(c))
dp[0] = 0

for i in range (n+1):
    for j in c:
        dp[i+j] = min(dp[i+j],dp[i]+1)
print(dp[n])


### FIXED CODE ###

n, m =map(int,input().split())
c = list(map(int,input().split()))

INF = 10**100
dp = [INF]*500000
dp[0] = 0

for i in range (n+1):
    for j in c:
        dp[i+j] = min(dp[i+j],dp[i]+1)
print(dp[n])
from math import ceil

N = int(input())
ta, ao = 1, 1
for i in range(N):
    T, A = map(int, input().split())
    if ta <= T and ao <= A:
        ta = T
        ao = A
    else:
        if ta % T == 0:
            n = ta//T
        else:
            n == ta//T + 1
        if ao % A == 0:
            m = ao//A
        else:
            m = ao//A + 1
        
        ta = max(n, m) * T
        ao = max(n, m) * A
        print(n)
print(ta+ao)

### FIXED CODE ###

N = int(input())
T, A = 1, 1
for i in range(N):
    t, a = map(int, input().split())
    if T % t == 0:
        n1 = T // t
    else:
        n1 = T // t + 1
    if A % a == 0:
        n2 = A // a
    else:
        n2 = A // a + 1
    #print('--',n1, n2)
    n = max(n1, n2)
    T = n*t
    A = n*a
    #print('--------',T, A)
    
print(T+A)
n = int(input())
arr = list(map(int, input().split()))
k = int(input())
s = sum(arr)
d = {}
for i in arr:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
for _ in range(k):
    v = 0
    a,b = map(int, input().split())
    s += (b-a) * d[a]
    if b in d:
        d[b] += d[a]
    else:
        d[b] = d[a]
    print(s)
    del d[a]

### FIXED CODE ###

n = int(input())
arr = list(map(int, input().split()))
k = int(input())
s = sum(arr)
d = {}
for i in arr:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
for _ in range(k):
    v = 0
    a,b = map(int, input().split())
    if a not in d:
        print(s)
        continue
    s += (b-a) * d[a]
    if b in d:
        d[b] += d[a]
    else:
        d[b] = d[a]
    print(s)
    del d[a]