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

N,X,M = map(int,input().split())
A = [0]*M
S = 0
r = X
A[r-1] = 1
d = 0
I = 0
for i in range(1,M):
    r = (r*r) % M
    if A[r-1] == 0:
        A[r-1] = i+1
    else:
        I = A[r-1]
        j = i+1
        d = j-I
        break
r = X
if I == 0:
    I = N
for i in range(I):
    S += r
    r = (r*r) % M
if d != 0:
    t,u = (N-I)//d,(N-I)%d
    s = 0
    for i in range(d):
        s += r
        r = (r*r) % M
    S += s*t
    for i in range(u):
        S += r
        r = (r*r) % M
print(S)

### FIXED CODE ###

N,X,M = map(int,input().split())
A = [0]*M
S = 0
r = X % M
A[r] = 1
d = 0
I = 0
for i in range(1,M+1):
    r = (r*r) % M
    if A[r] == 0:
        A[r] = i+1
    else:
        I = A[r]
        j = i+1
        d = j-I
        break
r = X
for i in range(I):
    S += r
    r = (r*r) % M
if d != 0:
    t,u = (N-I)//d,(N-I)%d
    s = 0
    for i in range(d):
        s += r
        r = (r*r) % M
    S += s*t
    for i in range(u):
        S += r
        r = (r*r) % M
print(S)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    def fr(i):
        memo = [0]*(N+1)
        if i == 1:
            return abs(h[1]-h[0])
        elif i == 0:
            return 0
        else:
            if memo[i] != 0:
                return memo[i]
            memo[i] =  min(fr(i-1)+abs(h[i]-h[i-1]),\
                        fr(i-2)+abs(h[i]-h[i-2]))
            return memo[i]

    print(fr(N-1))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    dp = [0 for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    cost = h
    for i in range(1,N-1):
        dp[i+1] = min(dp[i]+abs(cost[i+1]-cost[i]),\
            dp[i-1]+abs(cost[i+1]-cost[i-1]))
    print(dp[-1])

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

def main():
    n = int(input())
    h = input().split()
    h = [int(n) for n in h]
    max = 0
    now = 0
    i = 0
    for i in range(n-1):
        now = 0
        for j in range(i + 1, n):
            if h[j] <= h[j - 1]:
                now += 1
            else:
                i = j - 1
                break
        if now >= max:
            max = now
        i += 1
    print(max)

if __name__ == "__main__":
    main()



### FIXED CODE ###

def main():
    n = int(input())
    h = input().split()
    h = [int(n) for n in h]
    max = 0
    now = 0
    i = 0
    for i in range(n-1):
        if h[i] >= h[i+1]:
            now += 1
        else:
            if now >= max:
                max = now
            now=0
        if now >= max:
            max = now
    print(max)

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

import bisect

n=int(input())
a1=int(input())
alist=[a1]

for i in range(n-1):
    an=int(input())
    #print(alist,an)
    index = bisect.bisect_left(alist, an)
    if index==0:
        alist.insert(index, an)
    else:
        alist[index-1]=an
    #print(index)

print(len(alist))

### FIXED CODE ###

import bisect

n=int(input())
a1=int(input())
alist=[]
for al in range(n-1):
    alist.append(-2)
alist.append(a1)

for i in range(n-1):
    an=int(input())
    #print(alist,an)
    index = bisect.bisect_left(alist, an)
    alist[index-1]=an

#print(alist)
index = bisect.bisect_left(alist, -1)
#print(index)
print(len(alist)- index)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, Ma, Mb = inpl()
INF = 4001

DP = [[INF]*(411) for _ in range(411)]
DP[0][0] = 0

for n in range(N):
    DP2 = [[INF]*(411) for _ in range(411)]
    a, b, c = inpl()
    for i in range(10*(n+1) + 1):
        for j in range(10*(n+1) + 1):
            DP2[i][j] = min(DP[i][j], DP2[i][j])
            DP2[i+a][j+b] = min(DP[i+a][j+b], DP[i][j] + c)
    DP = DP2

x = 1
ans = INF
while Ma*x <= 400 and Mb*x <= 400:
    ans = min(ans, DP[Ma*x][Mb*x])
    
    x += 1

if ans < INF:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, Ma, Mb = inpl()
INF = 4001

DP = [[INF]*(411) for _ in range(411)]
DP[0][0] = 0

for _ in range(N):
    DP2 = [[INF]*(411) for _ in range(411)]
    a, b, c = inpl()
    for i in range(400):
        for j in range(400):
            DP2[i][j] = min(DP[i][j], DP2[i][j])
            DP2[i+a][j+b] = min(DP[i+a][j+b], DP[i][j] + c)
    DP = DP2

x = 1
ans = INF
while Ma*x <= 400 and Mb*x <= 400:
    ans = min(ans, DP[Ma*x][Mb*x])
    
    x += 1

if ans < INF:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

R, G, B, N = map(int,input().split())

ans = 0
for i in range(N//R+1):
    if N - R*i < 0:
        break
    for j in range(N//G+1):
        if N - R * i - G * j < 0:
            break
        if  N -R*i -G*j == 0:
            ans += 1
        elif N -R*i -G*j > 0 and (N -R*i -G*j) % B == 0:
            ans += 1

print(ans)

### FIXED CODE ###

R, G, B, N = map(int,input().split())

ans = 0
for i in range(N//R+1):
    for j in range((N- R*i)//G+1):
        if (N -R*i -G*j) % B == 0:
            ans += 1

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

N,K=map(int,input().split())
A=list(map(int,input().split()))
before=1
for i in range(K):
    before*=A[i]
for i in range(N-K):
    evaluation=before
    evaluation=evaluation//A[i]*A[i+K]
    print("Yes" if evaluation>before else "No")
    before=evaluation

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N-K):
    print("Yes" if A[i+K]>A[i] else "No")
### BUGGY CODE ###

import collections

n = int(input())
a = []
max_list = []
max_i = 1

for i in range(n):
    a.append(str(input()))

c = collections.Counter(a)
max_i = c.most_common()[0][1]

for i in range(len(c)):
    if max_i == c.most_common()[i][1]:
        max_list.append(c.most_common()[i][0])
    else:
        break

max_list.sort()

for i in max_list:
    print(i)       
    

### FIXED CODE ###

import collections

n = int(input())
a = []
max_list = []
max_i = 1

a = [str(input()) for x in range(n)]

c = collections.Counter(a)
c = c.most_common()
max_i = c[0][1]

for i in range(len(c)):
    if max_i == c[i][1]:
        max_list.append(c[i][0])
    else:
        break

max_list.sort()

for i in max_list:
    print(i)
### BUGGY CODE ###

N = int(input())
lsA = list(map(int,input().split()))
lsA += lsA
lsA.sort(reverse=True)

lsA.pop(0)
ans = 0
for i in range(N-1):
    ans += lsA.pop(0)
print(ans)

### FIXED CODE ###

N = int(input())
lsA = list(map(int,input().split()))
lsA += lsA
lsA.sort(reverse=True)

lsA.pop(0)
ans = sum(lsA[:N-1])
print(ans)
### BUGGY CODE ###

import sys
from functools import reduce
input = sys.stdin.readline

# python > pypy
MOD = 10**9 + 7
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

n = int(input())
a = list(map(int, input().split()))
a_tmp = list(set(sorted(a, reverse=True)))
lcm_ = a_tmp[0]
for i in a_tmp:
    lcm_ = lcm(lcm_, i)

b = list(map(lambda x: lcm_//x, a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)


### FIXED CODE ###

MAX = 1000001

mod = 1000000007

prime = [0 for i in range(MAX)]

max_map = dict()

# function to return a^n

def power(a, n):

    if n == 0:
        return 1
    p = power(a, n // 2) % mod
    p = (p * p) % mod

    if n & 1:
        p = (p * a) % mod
    return p

# function to find the smallest prime
# factors of numbers upto MAX


def sieve():
    prime[0], prime[1] = 1, 1
    for i in range(2, MAX):
        if prime[i] == 0:
            for j in range(i * 2, MAX, i):
                if prime[j] == 0:
                    prime[j] = i
            prime[i] = i

# function to return the LCM modulo M


def lcmModuloM(arr, n):

    for i in range(n):
        num = arr[i]

        temp = dict()

        # temp stores mapping of prime factors
        # to its power for the current element
        while num > 1:

            # factor is the smallest prime
            # factor of num
            factor = prime[num]

            # Increase count of factor in temp
            if factor in temp.keys():
                temp[factor] += 1
            else:
                temp[factor] = 1

            # Reduce num by its prime factor
            num = num // factor

        for i in temp:
            # store the higest power of every prime
            # found till now in a new map max_map
            if i in max_map.keys():
                max_map[i] = max(max_map[i], temp[i])
            else:
                max_map[i] = temp[i]

    ans = 1

    for i in max_map:

        # LCM is product of primes to their
        # higest powers modulo M
        ans = (ans * power(i, max_map[i])) % mod
    return ans


def rep_sqr(base, k, mod):
    if k == 0:
        return 1
    elif k % 2 == 0:
        return (rep_sqr(base, k / 2, mod) ** 2) % mod
    else:
        return (rep_sqr(base, k - 1, mod) * base) % mod

# a^(-1) == a^(m-2)


def flt(a, mod):
    return rep_sqr(a, mod-2, mod)

# Driver code
sieve()

# python > pypy
MOD = 10**9 + 7

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

lcm_ = lcmModuloM(a, n)

b = list(map(lambda x: lcm_ * flt(x, mod), a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)
### BUGGY CODE ###

def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N=II()
A=LI()
cnt=[0]*((10**6)+1)
for elem in A:
  cnt[elem]+=1
unique=[]
for i in range((10**6)+1):
  if cnt[i]==1:
    unique.append(i)
cnt=[0]*((10**6)+1)
for elem in A:
  for m in range(elem*2,10**6+1,elem):
    cnt[m]=1
ans=0
for i in unique:
  if cnt[i]==0:
    ans+=1
print(ans)  

### FIXED CODE ###

import sys
from collections import Counter
import numpy as np
 
n, *aaa = map(int, sys.stdin.buffer.read().split())
cnt = Counter(aaa)
duplicated = {x for x, c in cnt.items() if c > 1}
aaa.sort()
 
can = np.ones(aaa[-1] + 1, np.int8)
 
ans = 0
for a in aaa:
    if can[a] == 0:
        continue
    if a not in duplicated:
        ans += 1
    can[a * 2::a] = 0
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
AB = []

for _ in range(N):
  A, B = map(int, input().split())
  AB.append((A, B))

AB.sort()
AB.sort(key = lambda x:x[1], reverse = True)

ans = [0]*(M+1)

for a, b in AB:
  while a <= M:
    if ans[a] < b:
      ans[a] = b
      break
    a += 1

print(sum(ans))

### FIXED CODE ###

from heapq import heappop,heappush
from collections import defaultdict

N, M = map(int, input().split())
D = defaultdict(list)

for _ in range(N):
  A, B = map(int, input().split())
  D[A].append(B)

H = []
ans = [0]*(M+1)

for i in range(1, M+1):
  for j in D[i]:
    heappush(H, -j)
  if H:
    a = heappop(H)
    ans[i] = -a

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

s = input()
counts = [0] * 2019

for i in range(len(s)):
    counts[int(s[i: len(s)]) % 2019] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

ans += counts[0]

print(ans)

### FIXED CODE ###

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
### BUGGY CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

def main():
  n,x,y=LI()
  
  cost = [[inf for i in range(n)] for i in range(n)] 
  for i in range(n-1):
    cost[i][i+1]=1
    cost[i+1][i]=1
  cost[x-1][y-1]=1
  cost[y-1][x-1]=1

  ans=[0]*(n-1)
  for i in range(n):
    a=dijkstra(i,n,n,cost)
    for x in a[i:]:
      ans[x]+=1

  for x in ans[1:]:
    print(x)
  print(0)

main()
# print(main())


### FIXED CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

n,x,y=LI()
edge = [[] for i in range(n)]
for i in range(n-1):
  edge[i].append([1,i+1])
  edge[i+1].append([1,i])
edge[x-1].append([1,y-1])
edge[y-1].append([1,x-1])

ans=[0]*n
for i in range(n):
  a=dijkstra_heap(i,edge)
  # print(a)
  for x in a[i:]:
    ans[x]+=1

for x in ans[1:]:
  print(x)
### BUGGY CODE ###

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

tmp = []
for p in pl:
    tmp.append(p*(p+1)/2/p)

ans = 0
for i in range(n-k+1):
    if sum(tmp[i:i+k]) > ans:
        ans = sum(tmp[i:i+k])

print(ans)


### FIXED CODE ###

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

dp = [0] * (n + 1)

for i in range(n):
    dp[i+1] = dp[i] + (pl[i] + 1)/2

ans = 0
for i in range(k, n+1):
    ans = max(ans, dp[i] - dp[i-k])

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

from itertools import groupby
N, K = map(int, input().split())
S = groupby(list(input()))
state = []
number = []
for i, j in S:
    state.append(i)
    number.append(len(list(j)))

answer = 0

if len(state) == 1:
    print(number[0])
    exit()

if state[0] == '0':
    answer = sum(number[0:2 * K])

start = state.index('1')
for i in range(start, len(number), 2):
    answer = max(answer, sum(number[i:2 * K + i + 1]))

print(answer)

### FIXED CODE ###

from itertools import groupby, accumulate
N, K = map(int, input().split())
S = groupby(list(input()))
state = []
number = []
for i, j in S:
    state.append(i)
    number.append(len(list(j)))

answer = 0

if len(state) == 1:
    print(number[0])
    exit()

number = list(accumulate([0] + number))
l = len(number) - 1

if state[0] == '0':
    answer = number[min(l, 2 * K)] - number[0]

start = state.index('1') + 1
for i in range(start, l + 1, 2):
    answer = max(answer, number[min(2 * K + i, l)] - number[i - 1])

print(answer)
### BUGGY CODE ###

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

box = [n+1 for i in range(n)]
ans = 1
for i in range(1,n):
     if min([p[j] for j in range(i)]) >= p[i]:
          ans += 1
print(ans)


### FIXED CODE ###

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

box = [n+1 for i in range(n)]
ans = 1
min = p[0]
for i in range(1,n):
     if min >= p[i]:
          ans += 1
          min = p[i]
print(ans)
### BUGGY CODE ###


a=list(map(int,input().split(" ")))
rr=a[0]
rg=a[1]
rb=a[2]
N=a[3]
count=0
for nr in range(0,N//rr+1):
    for ng in range(0,N//rg+1):
        tb=N-rr*nr-rg*ng
        if tb>=0 and tb%rb==0:
            count+=1
print(count)


### FIXED CODE ###


a=list(map(int,input().split(" ")))
rr=a[0]
rg=a[1]
rb=a[2]
N=a[3]
count=0
for nr in range(0,N//rr+1):
    for ng in range(0,N//rg+1):
        tb=N-rr*nr-rg*ng
        if tb>=0 and tb%rb==0:
            count+=1
print(count)
### BUGGY CODE ###

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [ list(map(int,input().split(" "))) for i in range(m)]

for i in range(m):
    k = list_kard[i]
    l = [k[1]]*k[0]
    list_score.extend(l)

list_score.sort(reverse=True)
print(sum(list_score[:n]))

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [list(map(int, input().split(" "))) for i in range(m)]

list_kard.sort(key=lambda x: x[1], reverse=True)
heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])
        else:
            break

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

def main() :
    X,Y = [int(i) for i in input().split()]

    if (X == Y) :
        print(-1)
        return
    
    n = X
    while (n < 1000000000000000000) :
        if (n % X == 0 and n % Y != 0) :
            print(n)
            return
        
        n += X
    
    print(-1)

main()



### FIXED CODE ###

def main() :
    X,Y = [int(i) for i in input().split()]
    if (X % Y == 0) :
        print(-1)    
    else :
        print(X)
    

main()
### BUGGY CODE ###

h,w = map(int, input().split())

sy, sx = map(int, input().split())
sy -= 1
sx -= 1
gy, gx = map(int, input().split())
gy -= 1
gx -= 1

s = [[] for _ in range(h)]
for i in range(h):
    s[i] = input()

from collections import deque
d = deque()

visited = [[False]*w for _ in range(h)]

d.append([sy,sx,0])

while len(d) > 0:
    y,x,c = d.popleft()
    
    if visited[y][x] is True:
        continue
    
    if gy == y and gx == x:
        print(c)
        exit(0)

    dxy = [[1,0], [-1, 0], [0, 1], [0, -1]]
    for dx, dy in dxy:
        nx = dx + x
        ny = dy + y
        if nx < 0 or nx >= w or ny < 0 or ny >= h:
            continue
        if s[ny][nx] == "#":
            continue
        if visited[ny][nx] is True:
            continue
        d.appendleft([ny, nx, c])

    for dy in range(-2, 3):
        for dy in range(-2, 3):
            nx = dx + x
            ny = dy + y
            if nx < 0 or nx >= w or ny < 0 or ny >= h:
                continue
            if s[ny][nx] == "#":
                continue
            if visited[ny][nx] is True:
                continue
            d.append([ny, nx, c+1])

print(-1)


### FIXED CODE ###

h,w = map(int, input().split())

sy, sx = map(int, input().split())
sy -= 1
sx -= 1
gy, gx = map(int, input().split())
gy -= 1
gx -= 1

s = [[""] for _ in range(h)]
for i in range(h):
    s[i] = input()

from collections import deque
d = deque()

visited = [[False]*w for _ in range(h)]

d.append([sy,sx,0])

while len(d) > 0:
    y,x,c = d.popleft()
    
    if visited[y][x] is True:
        continue
    else:
        visited[y][x] = True
    
    if gy == y and gx == x:
        print(c)
        exit(0)

    dxy = [[1,0], [-1, 0], [0, 1], [0, -1]]
    for dx, dy in dxy:
        nx = dx + x
        ny = dy + y
        if nx < 0 or nx >= w or ny < 0 or ny >= h:
            continue
        if s[ny][nx] == "#":
            continue
        if visited[ny][nx] is True:
            continue
        d.appendleft([ny, nx, c])

    for dy in range(-2, 3):
        for dx in range(-2, 3):
            nx = dx + x
            ny = dy + y
            if nx < 0 or nx >= w or ny < 0 or ny >= h:
                continue
            if s[ny][nx] == "#":
                continue
            if visited[ny][nx] is True:
                continue
            d.append([ny, nx, c+1])

print(-1)
### BUGGY CODE ###

# from pprint import pprint
# import math
# import collections
from numba import jit

N = int(input())


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

@jit(cache=True)
def calc(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


p = []
p_equal = []
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            if x + y + z > 100:
                break
            #         p.append((x, y, z))
            if x == y == z:
                p_equal.append(calc(x, y, z))
            else:
                p.append(calc(x, y, z))

# print(p)

for i in range(1, N + 1):
    if i in p_equal:
        print(1)
    elif i in p:
        print(3)
    else:
        print(0)


### FIXED CODE ###

# from pprint import pprint
# import math
# import collections
from numba import jit

N = int(input())

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

@jit(cache=True)
def calc(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


res = [0] * 1000009

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = calc(x, y, z)
            res[n - 1] += 1

for i in range(N):
    print(res[i])
### BUGGY CODE ###

import numpy as np
from collections import Counter

n = map(int,input().split())
a = list(map(int,input().split()))
Q = int(input())
a_count = dict(Counter(a))



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


#change_dict_key(a_count, 1, 5)

#print(a_count)



for q in range(Q):
    num = list(map(int,input().split()))
    
    if(num[0] not in a_count):
        print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
        continue

    if(num[1] not in a_count):
        change_dict_key(a_count,num[0],num[1])

    else :
        a_count[num[1]] += a_count[num[0]] 
        del a_count[num[0]] 
    
    #print(a_count.values())

    print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
    #print((sum(list_a))  )


### FIXED CODE ###

"""
import numpy as np
from collections import Counter

n = map(int,input().split())
a = list(map(int,input().split()))
Q = int(input())
a_count = dict(Counter(a))



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


#change_dict_key(a_count, 1, 5)

#print(a_count)



for q in range(Q):
    num = list(map(int,input().split()))
    
    if(num[0] not in a_count):
        print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
        continue

    if(num[1] not in a_count):
        change_dict_key(a_count,num[0],num[1])

    else :
        a_count[num[1]] += a_count[num[0]] 
        del a_count[num[0]] 
    
    #print(a_count.values())

    print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
    #print((sum(list_a))  )
"""
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

B, C = [0]*Q, [0]*Q
for i in range(Q):
    B[i], C[i] = list(map(int, input().split()))

bucket = [0]*100001
for i in A:
    bucket[i] += 1

sum = sum(A)

for i in range(Q):
    sum += (C[i] - B[i]) * bucket[B[i]]
    bucket[C[i]] += bucket[B[i]]
    bucket[B[i]] = 0
    print(sum)
### BUGGY CODE ###

K = int(input())
cur = 7
count = 1
digit = 10
if K == 2 or K == 5 or K == 10:
    print("-1")
else:
    while cur % K != 0:
        count += 1
        cur += 7*digit
        digit = (digit*10)%K
    print(count)

### FIXED CODE ###

K = int(input())
cur = 7
count = 1
digit = 10
X = K
if X % 2 == 0 or X % 5 == 0 :
    print(-1)
else:
    while cur % K != 0:
        count += 1
        cur += 7*digit
        digit = (digit*10)%K
    print(count)
### BUGGY CODE ###

from collections import Counter
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
c = Counter(a)
ans = 0
for i in range(len(c)-k):
  ans+=c.most_common()[-i-1][1]
print(ans)

### FIXED CODE ###

from collections import Counter
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
print(sum(sorted(Counter(a).values())[:-k]))