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

import sys
input = sys.stdin.readline

def slove():
    n = int(input())
    A = list(map(int,input().split()))
    ans = [1]*n
    for i in range(n-1):
        for j in range(i+1,n):
            if A[i] % A[j] == 0:
                ans[i] = 0
            if A[j] % A[i] == 0:
                ans[j] = 0
    print(sum(ans))


if __name__ == "__main__":
    slove()


### FIXED CODE ###

import sys 
input = sys.stdin.readline

def slove():
    n = int(input())
    A = sorted(list(map(int,input().split())))
    a_max = A[-1]+1
    B = [0] * a_max
    for value in A:
        B[value] += 1
        for i in range(value*2,a_max,value):
            B[i] += 2
    #print(B)
    print(B.count(1))

if __name__ == "__main__":
    slove()

"""
import sys
input = sys.stdin.readline

def slove():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A)
    ans = 0
    flag = False
    while len(A) != 0:
        ans += 1
        tmp = A.pop(0)
        #print(A)
        k = 0
        for i in range(len(A)):
            if A[i-k] % tmp == 0:
                if A[i-k] == tmp:
                    flag = True
                A.remove(A[i-k])
                k += 1
        if flag:
            ans -= 1
            flag = False
        
    print(ans)


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

[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
C = N//L
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        count += 1
        for k in range(L) :
            if j + k not in ANS : ANS[j+k] = i
    if count  > C : break
        
for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-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,m,Q = map(int, input().split())
train = []
for i in range(n):
  a = []
  for j in range(n):
    a.append(0)
  train.append(a)
  
for i in range(m):
  l,r = map(int, input().split())
  train[l-1][r-1] += 1

for i in range(n):
  lst = [train[i][0]]
  for j in range(1,n):
    lst.append(lst[j-1]+train[i][j])
  train[i] = lst 
pq = []
for i in range(Q):
  p,q = map(int, input().split())
  ans = 0
  for i in range(p-1,q):
    if p == 1:
      ans += train[i][q-1]
    else:
      ans += train[i][q-1] - train[i][p-2]
  print(ans)

### FIXED CODE ###

n,m,Q = map(int, input().split())
train = []
for i in range(n):
  a = []
  for j in range(n):
    a.append(0)
  train.append(a)
  
for i in range(m):
  l,r = map(int, input().split())
  train[l-1][r-1] += 1
cumsum = []
list1 = []
for i in range(n+1):
  list1.append(0)
cumsum.append(list1)
for i in range(n):
  lst = [0,cumsum[i][1]+train[i][0]]
  for j in range(1,n):
    lst.append(lst[j]+train[i][j]+(cumsum[i][j+1]-cumsum[i][j]))
  cumsum.append(lst)
for i in range(Q):
  p,q = map(int, input().split())
  print(cumsum[q][q]-cumsum[p-1][q]-cumsum[q][p-1]+cumsum[p-1][p-1])
### BUGGY CODE ###

S = input()
MOD = 10**9 + 7

dp = [0] * 13
dp[0] = 1

n = len(S)
for i in range(n):
    s = S[n-i-1]
    if s == '?':
        x = [0] * 13
        for j in range(10):
            a = j * (10**i) % 13
            for k in range(13):
                x[(k+a)%13] += dp[k]
        for k in range(13):
            dp[k] = x[k] % MOD
    else:
        a = int(s) * (10**i) % 13
        x = [0] * 13
        for k in range(13):
            x[(k + a) % 13] += dp[k]
        for k in range(13):
            dp[k] = x[k] % MOD

print(dp[5])




### FIXED CODE ###

S = input()
MOD = 10**9 + 7

dp = [[0] * 13 for _ in range(2)]
dp[0][0] = 1

n = len(S)
for i in range(n):
    if i == 0:
        mod_array = [i for i in range(10)]
    else:
        mod_array = [i * 10 % 13 for i in mod_array]
    s = S[n-i-1]
    if s == '?':
        for a in mod_array:
            for k in range(13):
                dp[1][(k+a)%13] += dp[0][k]
    else:
        a = mod_array[int(s)]
        for k in range(13):
            dp[1][(k + a) % 13] += dp[0][k]
    for k in range(13):
        dp[0][k] = dp[1][k] % MOD
        dp[1][k] = 0

print(dp[0][5])
### BUGGY CODE ###

from itertools import *
from collections import Counter

def f(v,m,s):
    cnt = 0
    for j in range(N):
        if j % 2 != 0:
            if v[j] != m:
                cnt += 1
        else:
            if v[j] != s:
                cnt += 1
    return cnt

N = int(input())
v = list(map(int,input().split()))
d = Counter(v).most_common()
#print(d)
try:
    second_common = d[1][0]
except:
    print(N//2)
    exit()
J = [i[0] for i in d]
p = list(product(J,J))
p = [i for i in p if i[0] != i[1]]
#print(p)
ans = float('inf')
for i in p:
    tmp = f(v,i[0],i[1])
    ans = min(ans,tmp)

print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o = Counter(v[::2]).most_common()
o.append((0,0))
e = Counter(v[1::2]).most_common()
e.append((0,0))
if o[0][0] == e[0][0]:
    ans = min(n - o[0][1] - e[1][1], n - o[1][1] - e[0][1])
else:
    ans = n - o[0][1] - e[0][1]
print(ans)
### BUGGY CODE ###

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

# 評点計算
# s[i-1]: i学期の評点
s = [0 for _ in range(k)]
for i in range(n - k + 1):
    p = 1
    for j in range(k):
        p *= a[i + j]
    s.append(p)

# 出力
for i in range(n - k):
    print("Yes" if s[k + i + 1] > s[k + i] else "No" )


### FIXED CODE ###

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

for i in range(k-1, n-1):
    print("Yes" if a[i+1] > a[i-k+1] else "No")
### BUGGY CODE ###

# n, m, p = map(int, input().split())
 
# n, m, p = 4, 5, 10
# arr = [[1, 2, 1], [1, 4, 1], [3, 4, 1], [2, 2, 100], [3, 3, 100]]

# n, m, p = 2, 2, 10
# arr = [(1, 2, 100), (2, 2, 100)]

n, m, p = map(int, input().split())
# arr = [(1, 2, 20), (2, 3, 30), (1, 3, 45)]

# n, m, p = 3, 4, 99999
# arr= [(1, 3, 8), (3, 2, 10), (2, 2, 100000), (2, 1, 3)]

abc = []
# edge = [[] for _ in range(n)]
rev_edge = [[] for _ in range(n)]

for _ in range(m):
	a, b, c = map(int, input().split())
	abc.append((a-1, b-1, p-c))
	rev_edge[b-1].append(a-1)

def dfs(e, s):
	v_set = {s, }
	stack = [s]

	while stack:
		v = stack.pop()
		for next_v in e[v]:
			if not next_v in v_set:
				stack.append(next_v)
				v_set.add(next_v)
	return v_set

def bellman_ford(sub_abc, n):
	dist = [float('inf')]*n 
	dist[0] = 0

	for _ in range(n):
		updated = False
		for ele in sub_abc:
			a, b, d = ele
			if dist[a] + d < dist[b]:
				dist[b] = dist[a] + d 
				updated = True
		if not updated:
			break
	else:
		return -1

	return max(-dist[n-1], 0)

use = dfs(rev_edge, n-1)
print(bellman_ford([(a, b, c) for a, b, c in abc if a in use and b in use], n))

### FIXED CODE ###

import sys

n, m, p = map(int, sys.stdin.readline().split())

abc = []
# edge = [[] for _ in range(n)]
rev_edge = [[] for _ in range(n)]

for _ in range(m):
	a, b, c = map(int, sys.stdin.readline().split())
	abc.append((a-1, b-1, p-c))
	rev_edge[b-1].append(a-1)

def dfs(e, s):
	v_set = {s, }
	stack = [s]

	while stack:
		v = stack.pop()
		for next_v in e[v]:
			if not next_v in v_set:
				stack.append(next_v)
				v_set.add(next_v)
	return v_set

def bellman_ford(sub_abc, n):
	dist = [float('inf')]*n 
	dist[0] = 0

	for _ in range(n):
		updated = False
		for ele in sub_abc:
			a, b, d = ele
			if dist[a] + d < dist[b]:
				dist[b] = dist[a] + d 
				updated = True
		if not updated:
			break
	else:
		return -1

	return max(-dist[n-1], 0)

use = dfs(rev_edge, n-1)
print(bellman_ford([(a, b, c) for a, b, c in abc if a in use and b in use], n))
### BUGGY CODE ###

from sys import stdin
input = stdin.readline
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)

#累積和の計算
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
for i in range(N+1):
    left = 0
    right = M
    if K - a[i] < 0:
        break
    while left < right:
        mid = (left + right)//2
        if b[mid] < K - a[i]:
            left = mid + 1
        elif b[mid] > K - a[i]:
            right = mid - 1
    if b[left] <= K - a[i]:
        j = left
    else:
        j = left - 1
    ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
j = M
for i in range(N+1):
    if K - a[i] < 0:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,m=map(int, input().split(' '))
p = list(map(int, input().split(' ')))
ab = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
visited = [0]*(n+1)
conlist = [0]*(n+1)
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
stack = []
cnt = 0
append = stack.append
pop = stack.pop
for i in range(1,n+1):
    if visited[i] != 1:
        cnt += 1
        append(i)
    while stack:
        x = pop()
        visited[x] = 1
        conlist[x] = cnt
        for y in graph[x]:
            if visited[y] != 1:
                append(y)
ans = 0
for i in range(1,n+1):
    if conlist[p[i-1]] == conlist[i]:
        ans+=1
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m=map(int, input().split(' '))
p = list(map(int, input().split(' ')))
ab = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
visited = [0]*(n+1)
conlist = [0]*(n+1)
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
stack = []
cnt = 0
append = stack.append
pop = stack.pop
for i in range(1,n+1):
    if visited[i] != 1:
        cnt += 1
        append(i)
    while stack:
        x = pop()
        visited[x] = 1
        conlist[x] = cnt
        for y in graph[x]:
            if visited[y] != 1:
                append(y)
ans = 0
for i in range(1,n+1):
    if conlist[p[i-1]] == conlist[i]:
        ans+=1
print(ans)
### BUGGY CODE ###

#ABC142-E Get Everything
"""
宝箱の制約が12個なので、これの状態を集合とする.
鍵をcost昇順に並べる。
ある鍵について、新たに埋められる場所が存在するなら、その鍵を使ってみる
"""
import sys
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
INF = 10**10
cost_len_key = []
for i in range(m):
    a,b = map(int,readline().split())
    lst1 = list(map(int,readline().split()))
    res = 0
    for j in lst1:
        res += 1<<(j-1)
    cost_len_key.append([a,INF-b,res])

cost_len_key.sort()

#dp:状態s(か、s以上)の箱を開けた場合の最小コスト
dp = [INF for _ in range(1<<n)]

def rec(s,v,dp):
    if dp[s] < INF:
        return dp[s]
    if s == (1<<n) -1:
        return 0
    
    res = INF
    for u in range(v,m):
        if cost_len_key[u][2] & s != cost_len_key[u][2]: #sにはない場所が存在するなら
            res = min(res,rec(cost_len_key[u][2] | s,v+1,dp)
            +cost_len_key[u][0])
    dp[s] = res
    return res
res = rec(0,0,dp)
print(res if res < INF else -1)

### FIXED CODE ###

#ABC142-E Get Everything
"""
宝箱の制約が12個なので、これの状態を集合とする.
鍵をcost昇順に並べる。
ある鍵について、新たに埋められる場所が存在するなら、その鍵を使ってみる
"""
import sys
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
INF = 10**10
cost_len_key = []
for i in range(m):
    a,b = map(int,readline().split())
    lst1 = list(map(int,readline().split()))
    res = 0
    for j in lst1:
        res += 1<<(j-1)
    cost_len_key.append([a,INF-b,res])

cost_len_key.sort()

#dp:状態s(か、s以上)の箱を開けた場合の最小コスト
dp = [INF for _ in range(1<<n)]
dp[0] = 0

for i in range(1<<n):
    for j in cost_len_key:
        s = i|j[2]
        dp[s] = min(dp[s],dp[i]+j[0])

ans = dp[-1]
if ans < INF:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

N = int(input())

ai_char = map(str, input().split(" "))
Ai = []
for i in ai_char:
    Ai.append(int(i))

mod_val = 1000000007
sum = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum += Ai[i]*Ai[j]
        if sum > mod_val:
            sum = sum % mod_val
        #print("{} {}".format(i, j))

print(sum)

### FIXED CODE ###

N = int(input())

ai_char = map(str, input().split(" "))
Ai = []
for i in ai_char:
    Ai.append(int(i))

mod_val = 1000000007
N1 = N-1
sum = 0

sum_tmp = 0
for j in range(0, N):
    sum_tmp += Ai[j]

for i in range(N1):
    sum_tmp -= Ai[i]
    sum += Ai[i] * sum_tmp

    if sum > mod_val:
        sum = sum % mod_val


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

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

mul=1
for i in range(K):
    mul*=A[i]
text=""
for i in range(K,N):
    if A[i]>A[i-K] :
        text+="Yes\n"
    else:
       text+="No\n"
print("{}".format(text))





### FIXED CODE ###

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

text=""
for i in range(K,N):
    if A[i]>A[i-K] :
        text+="Yes\n"
    else:
       text+="No\n"
print("{}".format(text))
### BUGGY CODE ###

k, s = map(int, input().split())

z_list = []

for i in range(k+1):
    z_list.append(i)

count = 0

for i in z_list:
    z = i
    for x in range(k+1):
        for y in range(k+1):
            if (x+y) == (s - z):
                count+=1

print(count)


### FIXED CODE ###

k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k:
            count+=1

print(count)
### BUGGY CODE ###

from heapq import *

n,m,s,t=map(int,input().split())
s-=1
t-=1
INF=float("inf")
Gyen=[[]for i in range(n)]
Gsnu=[[]for i in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  Gyen[u].append([v,a])
  Gyen[v].append([u,a])
  Gsnu[u].append([v,b])
  Gsnu[v].append([u,b])

def dijkstra(G,s):
  que=[]
  d=[INF]*n
  d[s]=0
  visited={s}
  heappush(que,[0,s])
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    if d[v]<p[0]:
      continue
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,[d[node],node])
  return d

yen=dijkstra(Gyen,s)
snu=dijkstra(Gsnu,t)
ans=10**15
ans_list=[]
for i in reversed(range(n)):
  ans=min(ans,yen[i]+snu[i])
  ans_list.append(10**15-ans)
print(*ans_list[::-1], sep='\n')

### FIXED CODE ###

from heapq import *

n,m,s,t=map(int,input().split())
s-=1
t-=1
INF=10**19
Gyen=[[]for i in range(n)]
Gsnu=[[]for i in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  Gyen[u].append([v,a])
  Gyen[v].append([u,a])
  Gsnu[u].append([v,b])
  Gsnu[v].append([u,b])

def dijkstra(G,s):
  que=[]
  d=[INF]*n
  d[s]=0
  visited={s}
  heappush(que,[0,s])
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,[d[node],node])
  return d

yen=dijkstra(Gyen,s)
snu=dijkstra(Gsnu,t)
ans=10**15
ans_list=[]
for i in reversed(range(n)):
  ans=min(ans,yen[i]+snu[i])
  ans_list.append(10**15-ans)
print(*ans_list[::-1], sep='\n')
### BUGGY CODE ###

def main():
    n, s = map(int, input().split())
    mod = 998244353
    a = list(map(int, input().split()))
    dp = [[0]*(s+1) for _ in range(n+1)]
    dp[0][0] = 1
    dio = dp[0]
    for i in range(1, n+1):
        ai = a[i-1]
        di = dp[i]
        for j in range(min(s+1, ai)):
            di[j] += 2*dio[j]
            di[j] %= mod
        for j in range(ai, s+1):
            di[j] += 2*dio[j] + dio[j-ai]
            di[j] %= mod
        dp[i] = di
        dio = di
    print(dp[n][s])
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n, s = map(int, input().split())
    mod = 998244353
    a = list(map(int, input().split()))
    dp = [[0]*(s+1) for _ in range(n+1)]
    dp[0][0] = 1
    dio = dp[0]
    for i in range(1, n+1):
        ai = a[i-1]
        di = dp[i]
        for j in range(min(s+1, ai)):
            di[j] = (di[j]+2*dio[j])%mod
        for j in range(ai, s+1):
            di[j] = (di[j]+2*dio[j]+dio[j-ai])%mod
        dp[i] = di
        dio = di
    print(dp[n][s])
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

cnt = 0
div_times = 0

for i in ints:
    for j in ints:
        if i % j == 0:
            div_times += 1
        if div_times == 2:
            break
    if div_times == 1:
        cnt += 1
    div_times = 0

print(cnt)


### FIXED CODE ###

n = int(input())
ints = list(map(int, input().split()))
m = max(ints)
x = [0] * m
cnt = 0

for i in ints:
    if x[i-1] >= 2:
        continue
    for j in range(m // i):

        x[i * (j + 1) - 1] += 1

for i in ints:
    if x[i - 1] == 1:
        cnt += 1

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

MOD = 10**9+7

N, M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))

dp=[[1]*(M+1) for i in range(N+1)]
S_index=[[] for i in range(10**5+1)]

for i in range(N):
  S_index[S[i]].append(i)
  if len(S_index[S[i]])>=2:
    ikkomae=S_index[S[i]][-2]
    for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
  for j in range(M):
    dp[i][j]=dp[i][j-1]
    if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
      
print(dp[N-1][M-1])


### FIXED CODE ###

MOD = 10**9+7

N, M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))

dp=[[1]*(M+1) for i in range(N+1)]
S_index=[[] for i in range(10**5+1)]

for i in range(N):
  S_index[S[i]].append(i)
  if len(S_index[S[i]])>=2:
    ikkomae=S_index[S[i]][-2]
    for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
  for j in range(M):
    dp[i][j]=dp[i][j-1]
    if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
      
print(dp[N-1][M-1])
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
s =  1
f=0

for a in A:
    s = s*a

    
if s > 10**18:
    print(-1)
else:
    print(s)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
s =  1
f=0

if 0 in A:
    print(0)
else:
    for a in A:
        s = s*a
        if s > 10**18:
            f=1
            break
    if f==1:
        print(-1)
    else:
        print(s)
### BUGGY CODE ###

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab.sort()
p = [0]*n
for i in range(q):
  a, b = map(int, input().split())
  p[a - 1] += b
s = ""
for i in ab:
  p[i[1]-1] += p[i[0]-1]
print(*p)

### FIXED CODE ###

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab.sort()
p = [0]*n
for i in range(q):
  a, b = map(int, input().split())
  p[a - 1] += b
s = ""
for i in ab:
  p[i[1]-1] += p[i[0]-1]
print(*p)
### BUGGY CODE ###

from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
next_step = [0] * N
memo = dict()
cnt = 0
for i, a in enumerate(A+A):
    if a in memo.keys():
        if next_step[memo[a]%N]:
            continue
        next_step[memo[a]] = i - memo[a] + 1
        cnt += 1
    memo[a] = i

j = 0
while True:
    if j + next_step[j%N] < N*K:
        j += next_step[j%N]
        if j%N == 0:
            j = max(j, N*K//j*j)
    else:
        break

q = deque()
for k in range(j, N*K):
    a = A[k%N]
    if a not in q:
        q.append(a)
    else:
        while a in q:
            q.pop()

print(*q)


### FIXED CODE ###

from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
next_step = [0] * N
memo = [-1] * (2*10**5)
cnt = 0
for i, a in enumerate(A+A):
    if memo[a-1] >= 0:
        if next_step[memo[a-1]%N]:
            continue
        next_step[memo[a-1]%N] = i - memo[a-1] + 1
        if next_step[memo[a-1]%N] == 0:
            pass
        cnt += 1
    if cnt == N:
        break
    memo[a-1] = i

j = 0
while True:
    if j + next_step[j%N] < N*K:
        j += next_step[j%N]
        if j%N == 0:
            j = max(j, N*K//j*j)
    else:
        break

q = deque()
memo = [-1] * (2*10**5)
cnt = 0
for k in range(j, N*K):
    a = A[k%N]
    if memo[a-1] < 0:
        q.append(a)
        memo[a-1] = cnt
        cnt += 1
    else:
        while True:
            b = q.pop()
            memo[b-1] = -1
            if b == a:
                break

print(*q)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += a[i] * sum(a[i + 1 :])

print(ans % (10 ** 9 + 7))


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
r = [0] * (n + 1)
for i, v in enumerate(a, start=1):
    r[i] = v + r[i - 1]

for i in range(n - 1):
    ans += a[i + 1] * r[i + 1]

print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

from collections import defaultdict
d = defaultdict(int)
N = int(input())
for i in range(N):
    d[input()] += 1

for i in sorted([i for i, v in d.items() if v == max(d.values())]):
    print(i)


### FIXED CODE ###

from collections import defaultdict
d = defaultdict(int)
N = int(input())
MAX = 0
max_keys = []
for i in range(N):
    k = input()
    d[k] += 1
    if d[k] == MAX:
        max_keys.append(k)
    elif d[k] > MAX:
        MAX = d[k]
        max_keys = [k]

for i in sorted(max_keys):
    print(i)
# for i in sorted([i for i, v in d.items() if v == max(d.values())]):
#     print(i)
### BUGGY CODE ###

N, K = map(int, input().split())
H = [int(h) for h in input().split()]
dp = [N*10**4]*N
dp[0] = 0
for i in range(1,N):
    x = max(0, i-K)
    minimam = N*10**4
    for j in range(x, i):
        if i == 1:
            minimam = dp[0] + abs(H[i]-H[i-1])
        minimam = min(minimam, dp[j] + abs(H[i]-H[j]))
    dp[i] = minimam
print(dp[N-1])

### FIXED CODE ###

inf = 10**20
n, k = map(int, input().split())
hs = [int(s) for s in input().split()]
 
dp = [inf] * n
dp[0] = 0
 
for i in range(1, n):
    for j in range(i-1, max(0, i-k)-1, -1):
        dp[i] = min(dp[j] + abs(hs[i] - hs[j]), dp[i])
print(dp[-1])
### BUGGY CODE ###

def maxHeapify(H, A, i):
    left = 2*i
    right = left + 1
 
    if left <= H and A[left] > A[i]:
        largest = left
    else: largest = i
    if right <= H and A[right] > A[largest]:
        largest = right
    if largest != i:
        A[i], A[largest] = A[largest],A[i]
        maxHeapify(H,A,largest)
 
def buildmaxHeap(H,A):
    for i in range(H//2,0,-1):
        maxHeapify(H,A,i)

A = [None]
L = input()
while L !="end":
    L = L.split()
    if L[0] == "insert":
        A.append(int(L[1]))
    else:
        buildmaxHeap(len(A) - 1, A)
        print(str(A[1]))
        A = [None] + A[2:]
    L = input()

### FIXED CODE ###

import heapq
pq = []

def insert(S,k):
    heapq.heappush(pq, - k)

def extractMax(S):
    a = - heapq.heappop(S)
    print(str(a))

L = input()
while L != "end":
    if L =="extract":
        extractMax(pq)
    else:
        L = L.split()
        insert(pq, int(L[1]))
    L = input()