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

a,b = map(int,input().split())
c = []
for i in range(2,min(a,b)+1):
    if a % i == 0 and b % i == 0:
       c.append(i)
for k in range(len(c)):
    for j in range(len(c)):
        if (c[k])%(c[j])==0:
           if c[k] != c[j]:
              c[k] =2
c.append(1)
print(len(set(c)))

### FIXED CODE ###

a,b=map(int,input().split())
def prime_factorize(n):
  a=[]
  while n%2==0:
    a.append(2)
    n//=2
  f=3
  while f*f<=n:
    if n%f==0:
      a.append(f)
      n//=f
    else:
      f+=2
  if n!=1:
    a.append(n)
  return a
print(1+len(set(prime_factorize(a))&set(prime_factorize(b))))
### BUGGY CODE ###

import sys
N,M = map(int,input().split())
shops = dict()
price = []
takahashi = 0
money = 0
for i in range(N):
    bottle,stock = map(int,input().split())
    if bottle not in shops:
        shops[bottle] = 0
    shops[bottle] += stock
    if bottle not in price:
        price.append(bottle)
price.sort()
for y in price:
    while takahashi != M:
        if shops[y] <= (M-takahashi):
            takahashi += shops[y]
            money += shops[y]*y
            shops[y] = 0
            break
        elif shops[y] != 0:
            takahashi += 1
            shops[y] -= 1
            money += y
        else:
            break
    if takahashi == M:
        print(money)
        sys.exit(0)

### FIXED CODE ###

N,M = map(int,input().split())
shops = []
for i in range(N):
    price,B = map(int,input().split())
    shops.append([price,B])
shops.sort()
i = 0
money = 0
while M > 0:
    if shops[i][1] > M:
        money += M*shops[i][0]
        break
    else:
        money += shops[i][1] * shops[i][0]
        M -= shops[i][1]
    i += 1
print(money)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = list(map(int,readline().split()))

# dp[i] = 石の残り数がiの時の勝敗
# i個の状態から遷移できる場所に負けが存在したら、それを相手に回すことが出来るため勝ち
# i個の状態から遷移できる場所に勝ちが存在したら、それを相手に回す必要はないので更新なし

dp = [False] * (K + 1)
for i in range(1, K + 1): # 石がi個の状態
  for j in range(len(A)): # それを相手に回す元が存在するかチェック
    if i - A[j] >= 0 and not dp[i -A[j]]:
      dp[i] = True

print(("Second","First")[dp[K]])  

### FIXED CODE ###

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

dp=[False]*(k+1+max(a))

for i in range(1+k):
  if not dp[i]:
    for x in a:
      dp[i+x]=True

print(("Second","First")[dp[k]])
### BUGGY CODE ###

from collections import deque

h,w=map(int,input().split())
maplis=[input() for i in range(h)]

que=deque([(0,0,1)])
used={(0,0)}
bcount =0
for i in maplis:
    bcount+=i.count("#")


def check(x,y,c):
    f=(x<0 or x>w-1 or y<0 or y>h-1)
    f=(f or maplis[y][x]=="#")
    f=(f or (x,y) in used)
    if not f:
        que.append((x,y,c+1))

f=-1
while que:
    x,y,c=que.popleft()
    if x==w-1 and y==h-1:
        f=c
        break
    used.add((x,y))
    check(x-1,y,c)
    check(x+1,y,c)
    check(x,y-1,c)
    check(x,y+1,c)
print(f if f==-1 else(h*w-f-bcount))


### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
maplis=[input() for i in range(h)]

que=deque([(0,0,1)])
used={(0,0)}
bcount =sum(s.count("#") for s in maplis)


def check(x,y,c):
    if x<0 or x>w-1 or y<0 or y>h-1:
        return
    if maplis[y][x]=="#":
        return
    if  (x,y) in used:
        return
    que.append((x,y,c+1))
    used.add((x,y))

f=-1
while que:
    x,y,c=que.popleft()
    if x==w-1 and y==h-1:
        f=c
        break
    check(x-1,y,c)
    check(x+1,y,c)
    check(x,y-1,c)
    check(x,y+1,c)
print(f if f==-1 else(h*w-f-bcount))
### BUGGY CODE ###

string=input()
length=len(string)
mod=[0]*2019
while length > 0:
  mod[int(string[length-1:])%2019]+=1
  length-=1
print(int(sum([(i*(i-1))/2 for i in mod]))+mod[0])

### FIXED CODE ###

string=input()
length=len(string)
mod=[1]+[0]*2018
s=0
for i in range(length):
  s=(s+int(string[-1-i])*pow(10,i,2019))%2019
  mod[s]+=1
print(sum([i*(i-1)//2 for i in mod]))
### BUGGY CODE ###

import heapq
def SME():
    A = []
    ANS = [None] * N
    C = set([i for i in range(N)])
    D = set([])
    E = [None] * N
    parameter = 0.999
    count = 0
    for i,x in enumerate(Whole) :
        heapq.heappush(A,[x,i])
    for j in range(N) :
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L : ANS[i] = min(Whole[:i+1])
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

n = int(input())
s = input()
count = 0

r = []
g = []
b = []
for i in range(n):
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    b.append(i)
    


for i in range(n):
  if i in r:
    for j in g:
      if i > j:
        continue
      for k in b:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in b:
      if i > j:
        continue
      for k in g:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1      
  if i in g:
    for j in r:
      if i > j:
        continue
      for k in b:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in b:
      if i > j:
        continue
      for k in r:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
  if i in b:
    for j in g:
      if i > j:
        continue
      for k in r:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in r:
      if i > j:
        continue
      for k in g:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1

print(count)

### FIXED CODE ###

n = int(input())
s = input()
r = []
g = []
b = []

ans = s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k>=n:
          break
        ans -= s[k] != s[i] != s[j] != s[k]

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

n = int(input())
a = list(map(int, input().split()))
ans = 1 
for i in range(n):
        ans = ans * a[i]
        if ans == 0:
                break
if ans > 10**18:
        ans = -1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1 
if 0 in a:
        print(0)
else:
        for i in range(n):
                ans = ans * a[i]
                if ans > 10**18:
                        ans = -1
                        break
        print(ans)
### BUGGY CODE ###

N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
list_H = sorted(H, reverse=True)
for k in range(K):
    if len(list_H) > 0:
        list_H.pop(0)
print(sum(list_H))


### FIXED CODE ###

N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
H.sort(reverse=True)
print(sum(H[K:]))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**8)
INF = float("inf")
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):

    c = np.ones(M)
    edge = csr_matrix((c, (A, B)), (N+1, N+1))
    forward_dist, pred = dijkstra(
        edge, indices=1,
        return_predecessors=True, directed=False,
        unweighted=True)

    if (pred[2:] == -9999).any():
        print("No")
    else:
        print("Yes")
        for value in pred[2:]:
            print(value)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def yes():
    print("Yes")  # type: str


import heapq
from collections import defaultdict


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, s, t, w=1):
        self.E[s].append((t, w))
        self.E[t].append((s, w))


def shortestPath(g: Graph, s: int):
    # 返り値 (dist, prev)
    # dist: 始点からの距離が格納されたリスト
    # prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト
    dist = [INF]*g.N
    dist[s] = 0

    prev = [None]*g.N
    Q = []
    heapq.heappush(Q, (dist[s], s))

    while len(Q) > 0:
        _, u = heapq.heappop(Q)
        for v, w in g.E[u]:
            if dist[v] > dist[u] + w:
                dist[v] = dist[u] + w
                prev[v] = u
                heapq.heappush(Q, (dist[v], v))
    return dist, prev


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):

    g = Graph(N)
    for a, b in zip(A, B):
        g.add_edge(a-1, b-1)

    dist, prev = shortestPath(g, 0)
    if dist == INF:
        print("No")
        return
    print("Yes")
    for i in range(1, N):
        print(prev[i]+1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


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

#coding:utf-8

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

count = 0
r_list = []
g_list = []
b_list = []
l_set = {'R','G','B'}

for k,i in enumerate(s):
    if i == 'R':
        r_list.append(k)
    elif i == 'G':
        g_list.append(k)
    elif i == 'B':
        b_list.append(k)

count = len(r_list) * len(g_list) * len(b_list)

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        c_set = l_set.copy()
        c_set = c_set - {si} - {sj}
        nk = 2 * j - i
        if c_set == {'R'} and nk in r_list:
            count -= 1
        elif c_set == {'G'} and nk in g_list:
            count -= 1
        elif c_set == {'B'} and nk in b_list:
            count -= 1        

print("{}".format(count))

### FIXED CODE ###

#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))
### BUGGY CODE ###

x = int(input())
if x >= 2000:
    print(1)
else:
    for i in range(0,21):
        for j in range(0,21):
            for k in range(0,21):
                for l in range(0,21):
                    for m in range(0,21):
                        for n in range(0,21):
                            if 100*i + 101*j + 102*k + 103*l + 104*m + 105*n == x:
                                print(1)
                                exit(0)
                            else:
                                pass
    print(0) 

### FIXED CODE ###

x = int(input())
if x >= 2000:
    print(1)
    exit(0)
else:
    for i in range(0,21):
        if 105*i + 1 <= x <= 99 + i*100:
            print(0)
            exit(0)
        else:
            pass
    print(1)
### BUGGY CODE ###

n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
a = list(filter(lambda x: x in s, [int(y) for y in input().split()]))
print(len(a))


### FIXED CODE ###

def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))
### BUGGY CODE ###

# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
L = read_ints()

from itertools import combinations
cnt = 0
for a, b, c in combinations(L, 3):
    if (a < b + c) and (b < c + a) and (c < a + b):
        cnt += 1
print(cnt)


### FIXED CODE ###

# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
L = read_ints()
L.sort()
# import numpy as np
# L = np.array(L)
from bisect import bisect_left

cnt = 0
for i in range(N):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        # ここで二分探索するか
        cnt += bisect_left(L, a+b) - (j+1)
        # L_tmp = L[j+1:]
        # cnt += np.sum(L_tmp < b+a)

print(cnt)
### BUGGY CODE ###


def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    A = sorted(ZZ(), reverse=True)
    F = sorted(ZZ())

    if sum(A) <= K:
        print(0)
        return

    cost = list()
    for a, f in zip(A, F): cost.append(a*f)

    ok = 10 ** 12
    ng = -1

    while ok - ng > 1:
        mid = (ok+ng)//2
        cc = 0
        for i in range(N): cc += max(0, (cost[i]-mid+F[i]-1)//F[i])
        if cc <= K: ok = mid
        else: ng = mid
    print(ok)

    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    A = sorted(ZZ(), reverse=True)
    F = sorted(ZZ())

    if sum(A) <= K:
        print(0)
        return

    cost = list()
    for a, f in zip(A, F): cost.append(a*f)

    ok = 10 ** 12
    ng = -1

    for _ in range(45):
        mid = (ok+ng)//2
        cc = 0
        for i in range(N): cc += max(0, (cost[i]-mid+F[i]-1)//F[i])
        if cc <= K: ok = mid
        else: ng = mid
    print(ok)

    return

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

n, p = map(int, input().split())

s = input()

ruisekiwa = [0 for _ in range(0, n + 1)]
if 10 % p == 0:
    ans = 0
    for i in range(0, n):
        if (ord(s[i]) - ord('0')) % p == 0:
            ans += i + 1
    print(ans)
    exit()

ten = 1
for i in range(0, n)[::-1]:
    ruisekiwa[n - i] = ((ord(s[i]) - ord('0')) * ten + ruisekiwa[n - i - 1]) % p
    ten *= 10

ans = 0
cnt = [0 for _ in range(0, p)]
for i in range(0, n+1):
    ans += cnt[ruisekiwa[i]]
    cnt[ruisekiwa[i]] += 1

print(ans)


### FIXED CODE ###

n, p = map(int, input().split())

s = input()

ruisekiwa = [0 for _ in range(0, n + 1)]
if 10 % p == 0:
    ans = 0
    for i in range(0, n):
        if (ord(s[i]) - ord('0')) % p == 0:
            ans += i + 1
    print(ans)
    exit()

ten = 1
for _i in range(0, n):
    i = n - _i - 1
    ruisekiwa[n - i] = ((ord(s[i]) - ord('0')) * ten + ruisekiwa[n - i - 1]) % p
    ten *= 10
    ten %= p

ans = 0
cnt = [0 for _ in range(0, p)]
for i in range(0, n+1):
    ans += cnt[ruisekiwa[i]]
    cnt[ruisekiwa[i]] += 1

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

N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

goal_max=max(time)
goal_min=0
goal=int((goal_max+goal_min)/2)

col={"-1":"NG"}
for i in range(goal_max+1):
   col[str(i)]=None

flag=True

while(flag):
   counter=0
   for i in range(N):
      counter+=(A[i]-int(goal/F[i]))

   if(counter<=K):
      if col[str(goal-1)]=="NG":
         print(goal)
         flag=False
      else:
         col[str(goal)]="OK"
         goal_max=goal
         goal=int((goal_max+goal_min)/2)

   elif(counter>K):
      if col[str(goal+1)]=="OK":
         print(goal+1)
         flag=False
      else:
         col[str(goal)]="NG"
         goal_min=goal
         goal=int((goal_max+goal_min)/2)

### FIXED CODE ###

N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

A=sorted(A)
F=sorted(F,reverse=True)

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)
### BUGGY CODE ###

s = list(input())
n = len(s)
s.reverse()
dp = [[0 for i in range(13)] for j in range(n)]
if s[0] == "?":
    for i in range(10):
        dp[0][i] = dp[0][i] + 1
else:
    s0 = int(s[0])
    dp[0][s0] = dp[0][s0] + 1
for i in range(1,n):
    if s[i] != "?":
        s1 = int(s[i])
        for j in range(13):
            k = (s1*(10**i))%13
            dp[i][(j+k)%13] = dp[i-1][j]
    else:
        p = (10**i) % 13
        for j in range(13):
            for x in range(10):
                k = (x*p)%13
                dp[i][(j+k)%13] += dp[i-1][j]
            dp[i] = [dp[i][j]%(10**9 + 7) for j in range(13)]
print(dp[n-1][5])

### FIXED CODE ###

s = list(input())
n = len(s)
s.reverse()
m = 10**9 + 7
p = 10
dp = [[0 for i in range(13)] for j in range(n)]
if s[0] == "?":
    for i in range(10):
        dp[0][i] = dp[0][i] + 1
else:
    s0 = int(s[0])
    dp[0][s0] = dp[0][s0] + 1
for i in range(1,n):
    if s[i] != "?":
        s1 = int(s[i])
        k = (s1*p)%13
        for j in range(13):
            dp[i][(j+k)%13] = dp[i-1][j]
    else:
        for x in range(10):
            k = (x*p)%13
            for j in range(13):
                dp[i][(j+k)%13] += dp[i-1][j]
                dp[i][(j+k)%13] %= m
    p = (p * 10) % 13
print(dp[n-1][5])
### BUGGY CODE ###

# -*- coding: utf-8 -*-

def input_int_array():
    return map(int, input().split())


def answer():
    n, k = input_int_array()
    spans = [tuple(input_int_array()) for x in range(k)]

    count = [0 for x in range(n)]
    count[0] = 1

    for i in range(n):
        for j in range(k):
            l, r = spans[j]
            for lr in range(l, r + 1):
                if i + lr < n:
                    count[i + lr] += count[i]
                else:
                    break
    print(count[-1] % 998244353)


answer()


### FIXED CODE ###

# -*- coding: utf-8 -*-

def input_int_array():
    return map(int, input().split())


MOD = 998244353


def answer():
    n, k = input_int_array()
    spans = [tuple(input_int_array()) for x in range(k)]

    count = [0] * (n)
    count[0] = 1
    accum = [0] * (n + 1)
    accum[1] = 1

    for i in range(1, n):
        j = i + 1
        for l, r in spans:
            start = max(0, j - r - 1)
            end = max(0, j - l)
            count[i] += accum[end] - accum[start]
        accum[j] = accum[j-1] + count[i] % MOD
    print(count[n-1] % MOD)


answer()
### BUGGY CODE ###


def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        t_c = s_li.count(v - 1) + s_li.count(v) + s_li.count(v + 1)
        t_c2 = s_li.count(v) + s_li.count(v + 1) + s_li.count(v + 2)

        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if count > len(s_li):
            break
        s_li = s_li[s_li.index(v):]
    print(count)


if __name__ == '__main__':
    main()


### FIXED CODE ###

n = int(input())
cnt = [0] * 100002
a = list(map(int, input().split()))
for v in a:
    cnt[v] += 1
    cnt[v+1] += 1
    cnt[v+2] += 1
    
print(max(cnt))
### BUGGY CODE ###

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

max = 0
if b - 1 > n:
    x = n
else:
    x = b - 1

while x <= n:
    tmp = (a * x // b) - a * (x // b)
    if max < tmp: max = tmp
    x += b

print(max)

### FIXED CODE ###

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

max = 0
if b - 1 > n:
    x = n
else:
    x = b - 1

max = (a * x // b) - a * (x // b)

print(max)
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
    dummy = input()
    S.append(dummy)
#print(S)
S = sorted(S)
#print(S)
CNT = []
for i in range(N):
    CNT.append(S.count(S[i]))
#print(CNT)
MAX = max(CNT)
i = 0
while i < N:
    if(CNT[i] == MAX):
        print(S[i])
    i += CNT[i]

### FIXED CODE ###

N = int(input())
S = []
for i in range(N):
    S.append(input())
S = sorted(S)
CNT = [1]
dummy = 1
for i in range(1, N):
    if(S[i] == S[i - 1]):
        dummy += 1
    else:
        dummy = 1
    CNT.append(dummy)
#print(S)
#print(CNT)        
MAX = max(CNT)
for i in range(N):
    if(CNT[i] == MAX):
        print(S[i])
### BUGGY CODE ###

import sys,collections
input = sys.stdin.readline

N=input().rstrip()
A=list(map(int,input().split()))
Ac = collections.Counter(A)
Q = int(input())
for i in range(Q):
    B,C = list(map(int,input().split()))
    Ac[C] += Ac[B]
    Ac[B] = 0

    ans = 0
    for key,val in Ac.items():
        ans += key*val
    print(ans)


### FIXED CODE ###

import sys,collections
input = sys.stdin.readline

N=input().rstrip()
A=list(map(int,input().split()))
Ac = collections.Counter(A)
Q = int(input())
for i in range(Q):
    B,C = list(map(int,input().split()))
    nb = Ac[B]
    Ac[C] += Ac[B]
    Ac[B] = 0

    if i==0:
        ans = 0
        for key,val in Ac.items():
            ans += key*val
    else:
        ans +=nb*C - nb*B
    
    print(ans)