Harryxun/stf_run huggingface dataset:
N,X = map(int,input().split())
towns = list(map(int,input().split()))
towns.append(X)
towns.sort()
town_diff = [0]*(len(towns)-1)
for i in range(len(towns)-1):
    town_diff[i] = towns[i+1]-towns[i]
town_diff.sort()
if(len(town_diff) == 1):
    gcd = town_diff[0]
else:
    a = town_diff[0]
    b = town_diff[1]
    for i in range(len(town_diff)-2):
        while(True):
            t = b%a
            if(t == 0):
                gcd = a
                break
            b = a
            a = t
        a = gcd
        b = town_diff[i+2]
print(gcd)

### FIXED CODE ###

N,X = map(int,input().split())
towns = list(map(int,input().split()))
towns.append(X)
towns.sort()
town_diff = [0]*(len(towns)-1)
for i in range(len(towns)-1):
    town_diff[i] = towns[i+1]-towns[i]
town_diff.sort()
if(len(town_diff) == 1):
    gcd = town_diff[0]
elif(len(town_diff) == 2):
    a = town_diff[0]
    b = town_diff[1]
    while(True):
            t = b%a
            if(t == 0):
                gcd = a
                break
            b = a
            a = t
else:
    a = town_diff[0]
    b = town_diff[1]
    for i in range(len(town_diff)-2):
        while(True):
            t = b%a
            if(t == 0):
                gcd = a
                break
            b = a
            a = t
        a = gcd
        b = town_diff[i+2]
print(gcd)
i = 0
n = input()
while !n:
  i += 1
  print 'Case {0}: {1}'.format(i,n)
  n = input()

### FIXED CODE ###

n = input()
i = 1
while n != 0:
  print "Case %d: %d" % (i, n)
  n = input()
  i += 1;
N = input()
A = list(map(int, input()))
odd, four = 0, 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
odd, four = 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
elif odd - four > 1 and four + odd == N:
  print('No')
else:
  print('Yes')
import math

H,N = map(int,input().split())
ab = [list(map(int,input().split()))for _ in range(N)]

dp=[[[float('INF'),0] for _ in range(H+1)]for i in range(N+1)]
dp[0]=[[0,0]for _ in range(H+1)]
for i in range(1,N+1):
  a = ab[i-1][0]
  b = ab[i-1][1]
  for j in range(1,H+1):
    limit = math.floor(j/a)+2
    for k in range(limit):
      mana = dp[i-1][j-(a*k)][0]+b*k
      damage = dp[i-1][j-(a*k)][1]+(a*k)
      if damage >= j:
        if dp[i][j][0] > mana:
          dp[i][j]=[mana,damage]
print(dp[N][H][0])

### FIXED CODE ###

#モンスターの体力は H
#トキはN種類の魔法が使え、
#i番目の魔法を使うと、モンスターの体力を Ai減らすことができますが、
#トキの魔力を Bi消耗します。

#dp[i] = モンスターの体力を i 減らすため消耗する魔力の最小値
#dp[i+1] = min(dp[i-Ai]+Bi,dp[i])
#dp[0]=0

import numpy as np
 
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab)
 
a = ab[:, 0]
b = ab[:, 1]
 
dp = np.zeros(100001, dtype=np.int)
for i in range(1, h+1):
    dp[i] = (dp[i-a]+b).min()
print(dp[h])
inputA,inputB,inputC = input().split()

if inputC >= inputA:
    if inputB > inputC-inputA:
        print(0,inputB -(inputC-inputA))
    else:
        print(0,0)
else:
    print(inputA-inputC,inputB)



### FIXED CODE ###


inputA,inputB,inputC = map(int, input().split())

if inputC >= inputA:
    if inputB > inputC-inputA:
        print(0,inputB -(inputC-inputA))
    else:
        print(0,0)
else:
    print(inputA-inputC,inputB)
N,K=map(int,input().split())
print(sum(p*(b-K)+max(r-K+1,0)for p,r,b in map(lambda b:(*divmod(N,b),b),range(K+1,N+1)))if K else N*N)

### FIXED CODE ###

N, K = map(int, input().split())
if K == 0:
    print(N * N)
    exit()
cnt = 0
for b in range(K + 1, N + 1):
    p, r = divmod(N, b)
    cnt += p * (b - K) + max(r - K + 1, 0)
print(cnt)
from fractions import gcd

n =int(input())
a_lis = list(map(int,input().split()))
g = 0
for i in range(a_lis):
	g = gcd(g,i)

print(g)

### FIXED CODE ###

from fractions import gcd

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

g=0

for i in range(n):
    g=gcd(g,x[i])

print(g)
a,b=input().split()
if a<b
  print("<")
elif a==b:
  print("=")
else a>b:
  print(">")


### FIXED CODE ###

a,b=input().split()
if (a<b):
  print("<")
elif (a==b):
  print("=")
else :
  print(">")
D,N=map(int,input().split())
s=0
L=[]
if D==0:
  for i in range(1,100):
    L.append(i)
elif D==1:
  for i in range(100,10000,100):
    L.append(i)
elif D==2:
  for i in range(10000,1000000,10000):
    L.append(i)
print(L[N-1])

### FIXED CODE ###

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

if D==0:
  if N!=100:
    print(N)
  else:
    print(101)
elif D==1:
  if N!=100:
    print(N*100)
  else:
    print(10100)
else:
  if N!=100:
    print(N*10000)
  else:
    print(1010000)
A, B = map(str, input().split())
A = int(A)
B1, B2, B3 = int(B[0]), int(B[2]), int(B[3])
ans = A*B1*100 + A*B2*10 + A*B3
ans = str(ans)
print(int(ans[:-2]))


### FIXED CODE ###

A, B = map(str, input().split())
A = int(A)
B1, B2, B3 = int(B[0]), int(B[2]), int(B[3])
ans = A*B1*100 + A*B2*10 + A*B3
ans = str(ans)
if len(ans)>2:
    print(int(ans[:-2]))
else:
    print(0)
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
p = []
for _ in range(N):
    p.append(int(input())

pmax = max(p)
ans = int(sum(p)-pmax/2)
print(ans)

### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
p = []
for _ in range(N):
    p.append(int(input()))

pmax = max(p)
ans = int(sum(p)-pmax/2)
print(ans)
S = list(input())
K = int(input())
i = 0
while S[i] == '1':
    i += 1
if K > i:
    print(int(S[i]))
else:
    print(1)

### FIXED CODE ###

S = list(input())
S.append('0')
K = int(input())
i = 0
while S[i] == '1':
    i += 1
if K > i:
    print(int(S[i]))
else:
    print(1)
n,k,s = [int(i) for i in input().split()]

for i in range(k):
    print(s,end="")
    if i!=k-1:
        print(" ",end="")

s = s-1 if s==10**0 else s+1

for i in range(k,n):
    print(" "+str(s),end="")

### FIXED CODE ###

n = int(input())
lr = []
for i in range(n):
    x,l=input().split()
    x=int(x)
    l=int(l)
    lr.append([x-l,x+l])

lr.sort(key=lambda x:x[1])

l = -2000000000
ans=0
for i in range(n):
    if l<=lr[i][0]:
        l=lr[i][1]
        ans+=1

print(ans)
N, M = [int(x) for x in input().split(" ")]
S = input()
T = input()

N = len(S)
M = len(T)

import sys
sys.setrecursionlimit(5000000)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    '''
    if (a < b):
        return gcd(b, a)
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)
        '''


def maxkobai(a, b):
    return a * b // gcd(a, b)


#print(gcd(N, M))
#print(maxkobai(N, M))


L = maxkobai(N, M)
ret = L
#x = ['-' for i in range(L+1)]
x = ['-'] * (L+1)

for n in range(0, N):
    x[n * (L//N) + 1] = S[n]

# print(x)

for m in range(0, M):
    idx = m * (L // M) + 1
    x_idx = x[idx]
    if x_idx != '-' and x_idx != T[m]:
        ret = -1
        break

print(ret)

### FIXED CODE ###

N, M = [int(x) for x in input().split(" ")]
S = input()
T = input()

N = len(S)
M = len(T)


S = [ord(c) for c in S]
T = [ord(c) for c in T]


def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


def maxkobai(a, b):
    return a * b // gcd(a, b)


L = maxkobai(N, M)
ret = L
x = dict()

for n in range(0, N):
    x[n * (L//N) + 1] = S[n]


for m in range(0, M):
    idx = m * (L // M) + 1
    tmp = x.get(idx, 0)

    if tmp != T[m] and tmp != 0:
        ret = -1
        break

print(ret)
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    ll tmp = 0;
    while (pow(K, tmp) <= N) {
        tmp++;
    }
    rep2(i, 1, tmp + 1) {
        if (pow(K, i - 1) <= N && N < pow(K, i)) {
            ans = max(ans, i);
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


### FIXED CODE ###

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

ans = -1
for i in range(1, 40):
    if K ** (i - 1) <= N < K ** i:
        ans = i

print(ans)
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    input()
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)


### FIXED CODE ###

import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even and len(o.most_common()) == 1:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)
import numpy as np

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

a = np.linspace(L, R, R - L + 1) % 2019
a_s = sorted(a)

print(int(a_s[0] * a_s[1]))

### FIXED CODE ###

import numpy as np

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

min_ = np.inf
for i in range(L, R):
    for j in range(i + 1, R + 1):
        if (i * j) % 2019 <= min_:
            min_ = (i * j) % 2019
            if min_ == 0:
                print(min_)
                exit()

print(min_)
print(int("x")*3)

### FIXED CODE ###

x = int(input())
print(x**3)
def rec(i, s):
    if i >= n-1:
        res = s
    elif i == n-2:
        res = rec(i+1, s + abs(dat[i+1] - dat[i]))
    else:
        res = min(rec(i+1, s + abs(dat[i+1] - dat[i])), rec(i+2, s + abs(dat[i+2]-dat[i])))
    return res


if __name__ == '__main__':
    n = int(input())
    dat = list(map(int, input().split()))

    print(rec(0, 0))

### FIXED CODE ###

def ans():
    dp = {i: 0 for i in range(n)}

    dp[1] = diff1[0]

    for i in range(2, n):
        dp[i] = min(dp[i-1] + diff1[i-1], dp[i-2] + diff2[i-2])
    return dp[n-1]


if __name__ == '__main__':
    n = int(input())
    dat = list(map(int, input().split()))

    diff1 = [abs(x-y) for (x, y) in zip(dat[1:], dat[:-1])]
    diff2 = [abs(x-y) for (x, y) in zip(dat[2:], dat[:-2])]

    print(ans())
flag=1

a=input()
b=input()

c=""
d=""

c[0]=b[2]
c[1]=b[1]
c[2]=b[0]

d[0]=a[2]
d[1]=a[1]
d[3]=a[0]

i=0

while i<3:
    if a[i]!=c[i]:
        flag=0
    i+=1

while j<3:
    if b[j]!=d[j]:
        flag=0
    j+=1

if flag=1:
    print("YES")
else:
    print("NO")

### FIXED CODE ###


up = input()
down = input()

down_re = ""

for i in down:
    down_re = i + down_re
    
if up == down_re:
    print ("YES")
    
else:
    print ("NO")
def beautiful:
     a,b,c = input().split()
      if fabs(b-a) == fabs(c-b):
            print('YES')
      else:
            print('NO')

beautiful()

### FIXED CODE ###

a,b,c= map(int, input().split())
if ((a+c)==b*2):
 print('YES')
else:
 print('NO')
def dfs_v(u):
  color[u] = 1
  t += 1
  d[u] += t
  for v in range(n):
    if M[u][v] == 0 and color[v] == 0:
      dfs_v(v)
  color[u] = 2
  t += 1
  f[u] += t

def dfs():
  color = [0 for i in range(n)]
  t = 0
  for u in range(n):
    dfs_v(u)
  for u in range(n):
    print "%d %d %d" %(u+1, d[u], f[u])

n = input()

d = [0 for i in range(n)]
f = [0 for i in range(n)]
M = [0 for i in range(n)]0 for j in range(n)]

for i in range(n):
  u, k = map(int, raw_input().split())
  for j in range(k):
   v = input()
   M[u-1][v-1] = 1

dfs()
    

### FIXED CODE ###

n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
col = [0 for i in range(n)]
t = [0]
 
def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
 
def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
     
for i in range(n):
    X = map(int, raw_input().split())
    for j in range(X[1]):
        M[X[0]-1][X[2+j]-1] = 1
 
DFS()
n,k = map(int,input().split())
if k > (n-1)*(n-2)/2:
  print(-1)
else:
  p = (n-1)*(n-2)/2 - k
  print(N-1+int(p))
  for i in range(2,n+1):
    print(1,i)
  x = 2
  y = 3
  for _ in range(int(p)):
    print(x,y)
    y = y + 1
    if y == n + 1:
      x = x + 1
      y = x + 1

### FIXED CODE ###

n,k = map(int,input().split())
if k > (n-1)*(n-2)/2:
  print(-1)
else:
  p = (n-1)*(n-2)/2 - k
  print(n-1+int(p))
  for i in range(2,n+1):
    print(1,i)
  x = 2
  y = 3
  for _ in range(int(p)):
    print(x,y)
    y = y + 1
    if y == n + 1:
      x = x + 1
      y = x + 1
import numpy as np
H,W = map(int,input().split())
grid = []
for i in range(H):
    mojiretsu = input()
    moji = []
    for k in range(len(mojiretsu)):
        moji.append(mojiretsu[k])
    grid.append(moji)
grid = np.array(grid)
flug1 = True
flug2 = True
flug3 = False
flug4 = False
while flug1:
    for i in range(grid.shape[0]):
        if np.all(grid[i,:] == "."):
            grid = np.delete(grid, i, 0)
            flug3 = False
            break
        else:
            flug3 = True
    if flug3 == True:
        flug1 = False
while flug2:
    for j in range(grid.shape[1]):
        if np.all(grid[:,j] == "."):
            grid = np.delete(grid, j, 1)
            flug4 = False
            break
        else:
            flug4 = True
    if flug4 == True:
        flug2 = False
for height in range(grid.shape[0]):
    print("".join(list(grid[height,:]))) 

### FIXED CODE ###

import numpy as np
H,W = map(int,input().split())
grid = []
for i in range(H):
    mojiretsu = input()
    moji = []
    for k in range(len(mojiretsu)):
        moji.append(mojiretsu[k])
    grid.append(moji)
grid = np.array(grid)
flug1 = True
flug2 = True
flug3 = False
flug4 = False
while flug1:
    for i in range(grid.shape[0]):
        if np.all(grid[i,:] == "."):
            grid = np.delete(grid, i, 0)
            flug3 = False
            break
        else:
            flug3 = True
    if flug3 == True:
        flug1 = False
while flug2:
    for j in range(grid.shape[1]):
        if np.all(grid[:,j] == "."):
            grid = np.delete(grid, j, 1)
            flug4 = False
            break
        else:
            flug4 = True
    if flug4 == True:
        flug2 = False
for height in range(grid.shape[0]):
    print("".join(list(grid[height,:])))
# ????????????????????????????????????

def maxHeapify(heap, i):
    left = (i + 1) * 2 - 1
    right = (i + 1) * 2
    largest = left if heap[left] > heap[i] and left < len(heap) else i
    largest = right if heap[right] > heap[largest] and right < len(heap) else largest
    if largest != i:
        heap[i], heap[largest] = heap[largest], heap[i]
        maxHeapify(heap, largest)

def buildMaxHeap(heap):
    for i in range(len(heap) // 2, -1, -1):
        maxHeapify(heap, i)

n = int(input())
heap = list(map(int, input().split()))
buildMaxHeap(heap)
print('', *heap)

'''
out = ''
for key in heap:
    out += (' {}'.format(str(key)))
print(out)
'''

### FIXED CODE ###

def maxHeapify(heap, i):
    left = (i + 1) * 2 - 1
    right = (i + 1) * 2
    largest = left if left < len(heap) and heap[left] > heap[i] else i
    largest = right if right < len(heap) and heap[right] > heap[largest] else largest
    if largest != i:
        heap[i], heap[largest] = heap[largest], heap[i]
        maxHeapify(heap, largest)

def buildMaxHeap(heap):
    for i in range(len(heap) // 2, -1, -1):
        maxHeapify(heap, i)

n = int(input())
heap = list(map(int, input().split()))
buildMaxHeap(heap)

out = ''
for key in heap:
    out += (' {}'.format(str(key)))
print(out)
K = int(input())

import math

ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      plus = int(math.gcd(a, b, c))
      ans += plus
      
print(ans)

### FIXED CODE ###

K = int(input())
 
import math
 
ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      first = int(math.gcd(a, b))
      plus = int(math.gcd(first, c))
      ans += plus
      
print(ans)
def gdc(x, y):
    if x % y == 0:
        return y
    else:
        return gdc(x, x%y)


if __name__ == '__main__':
    x, y = [int(i) for i in input().split(" ")]
    print(gcd(x, y))

### FIXED CODE ###

def gdc(x, y):
    if x % y == 0:
        return y
    else:
        return gdc(y, x%y)


if __name__ == '__main__':
    x, y = [int(i) for i in input().split(" ")]
    print(gdc(x, y))
X, Y = map(int, input().split())

l ={ "A":1, "B":2, "C":3, "D":4, "E":5, "F":6 }
res = ""
if l[X] == l[Y]:
    res = "="
elif l[X] > l[Y]:
    res = ">"
else:
    res = "<"
print(res)

### FIXED CODE ###

X, Y = input().split()

l ={ "A":1, "B":2, "C":3, "D":4, "E":5, "F":6 }
res = ""
if l[X] == l[Y]:
    res = "="
elif l[X] > l[Y]:
    res = ">"
else:
    res = "<"
print(res)
S = input()
L = len(s)

ans = L
for i in range(L - 1):
    if S[i] != S[i+1]:
        ans = min(max(L - i - 1, i + 1),ans)
print(ans)


### FIXED CODE ###

S = input()

ans = len(S)
for i in range(len(S) - 1):
    if S[i] != S[i+1]:
        ans = min(max(len(S) - i - 1, i + 1),ans)
print(ans)
N = int(input())
Sdic = {}
L = ["M","A","R","C","H"]
for i in L:
    Sdic[i] = []

tN = N
for i in range(N):
    s = input()
    if s[0] in L:
        Sdic[s[0]].append(s)
    else:
        tN -= 1


zen = tN*(tN-1)*(tN-2) / 6

one = 0
for i in ["M","A","R","C","H"]:
    c = len(Sdic[i])
    if c >= 3:
        one += c * (c-1) * (c-2)  / 6


lis = []
for i in range(N):
    for j in range(N):
        if i < j:
            lis.append(len(Sdic[L[i]]) + len(Sdic[L[j]]))

two = 0
for c in lis:
    if c >= 3:
        two += c * (c-1) * (c-2)  / 6

print(int(zen - one - two))


### FIXED CODE ###

N = int(input())
d = {}
for i in range(N):
    s = input()[0]
    if s not in d.keys():
        d[s] = 0
    d[s] += 1
march = ["M","A","R","C","H"]
lis = []
for a in d.keys():
    if a in march:
        lis.append(a)
import itertools
ans = 0
for l in list(itertools.combinations(lis,3)):
    ans += d[l[0]]*d[l[1]]*d[l[2]]
print(ans)
N=int(input())
a_list=list(map(int,input().split()))
Q=int(input())

N_list=[0]*(N+1)
sumn=0

for a in a_list:
    N_list[a]+=1
    sumn+=a


for i in range(Q):
    b,c=map(int,input().split())
    henka=(c-b)*N_list[b]

    sumn+=henka

    N_list[c]+=N_list[b]
    N_list[b]=0

    print(sumn)



### FIXED CODE ###

N=int(input())
a_list=list(map(int,input().split()))
Q=int(input())

N_list=[0]*(100001)
sumn=0

for a in a_list:
    N_list[a]+=1
    sumn+=a


for i in range(Q):
    b,c=map(int,input().split())
    henka=(c-b)*N_list[b]

    sumn+=henka

    N_list[c]+=N_list[b]
    N_list[b]=0

    print(sumn)
from sys import stdin

num = str(stdin.read())

total = 0
for n in num:
  total += int(n)
 
if total % 9 == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

from sys import stdin

num =stdin.read().strip()

lst = [int(n) for n in num]
if sum(lst) % 9 == 0:
  print("Yes")
else:
  print("No")
n = int(raw_input())
m = list(map(int, input().split()))
total = 0
for i in range(n):
    x = m[i]
    while True:
        if x % 2 == 1:
            break
        total += 1
        x = x // 2
 
print total

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
res = 0
for i in a:
    while i%2==0:
        res += 1
        i //= 2
print(res)
import math
a, b, c = map(int, input().split())
root_ab = int(math.sqrt(a)) + int(math.sqrt(b))
root_c = int(math.sqrt(c))
if root_ab < root_c:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

num_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input()) - 1
print(num_list[K])
import math
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0

for i in range(n):
  for j in range(i+1,n):
    temp = 0
    for k in range(d):
      temp += (x[i][k] - x[j][k]) ** 2
    l = math.sqrt(temp)
    if l.is_integer():
      ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
count = 0
for i in range(n):
  if i == 0:
    count += 1
  else:
    if h[i] >= max(h[:i]):
      count += 1
print(count)
w = list(map(str,input()))
w.sort()
w = "".join(w)

flag = 0
w = [w[i*2:i*2+2] for i in range(-(-len(w)//2))]
for i in w:
  if not w[0] == w[1]:
    flag = 1

print("Yes") if not flag else print("No")


### FIXED CODE ###

w = list(map(str,input()))
w.sort()
w = "".join(w)

flag = 0
w = [w[i*2:i*2+2] for i in range(-(-len(w)//2))]
for i in w:
  if len(i)==1 or not i[0] == i[1]:
    flag = 1
    break

print("Yes") if not flag else print("No")
from functools import reduce
import math
def GCD(a, b):
    if a * b == 0:
        return a + b
    return math.gcd(a, b)

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

L = [0] * n
R = [0] * n

for i in range(n - 1):
    L[i + 1] = GCD(a[i], L[i])
    R[-(i + 2)] = GCD(a[-(i + 1)], R[-(i + 1)])

M = [0] * n
for i in range(n):
    M[i] = GCD(L[i], R[i])
print(max(M))

### FIXED CODE ###

import fractions
def GCD(a, b):
    if a * b == 0:
        return a + b
    return fractions.gcd(a, b)

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

L = [0] * n
R = [0] * n

for i in range(n - 1):
    L[i + 1] = GCD(a[i], L[i])
    R[-(i + 2)] = GCD(a[-(i + 1)], R[-(i + 1)])

M = [0] * n
for i in range(n):
    M[i] = GCD(L[i], R[i])
print(max(M))
a,b,k=map(int,input().split())
d=set()
f=min(b-a+1,k)
for i in range(f):
  d.add(a+i)
for i in range(f):
  d.add(b-i)
d.sort()
for i in d:
  print(i)


### FIXED CODE ###

a,b,k=map(int,input().split())
d=set()
f=min(b-a+1,k)
for i in range(f):
  d.add(a+i)
for i in range(f):
  d.add(b-i)
d=sorted(list(d))
for i in d:
  print(i)
s = input()
n = (len(s) - 1)

ans_lst = []
for i in range(2**n):
op = ["+"] * n 
    for j in range(n):
        if ((i >> j) & 1):
            op[n-j-1] = ""
    for num,opp in zip(s, op + [""]):
        formula += (num + opp)
    ans_lst = ans_lst + [eval(formula)]

print(sum(ans_lst))

### FIXED CODE ###

s = input()
n = (len(s) - 1)

ans_lst = []
for i in range(2**n):
    op = ["+"] * n 
    for j in range(n):
        if ((i >> j) & 1):
            op[n-j-1] = ""
    formula = ""
    for num,opp in zip(s, op + [""]):
        formula += (num + opp)
    ans_lst = ans_lst + [eval(formula)]

print(sum(ans_lst))