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

import numpy as np

H, W, M = map(int, input().split())

h = np.zeros(H + 1, np.int64)
w = np.zeros(W + 1, np.int64)
boms = set()

for _ in range(M):
    x, y = map(int, input().split())
    h[x] += 1
    w[y] += 1
    boms.add((x, y))

h_max = h.max()
w_max = w.max()

h_idx = np.where(h == h_max)[0]
w_idx = np.where(w == w_max)[0]

minus = []
for x in h_idx:
    for y in w_idx:
        if (x, y) in boms:
            minus.append(-1)
        else:
            minus.append(0)

print(h_max + w_max + max(minus))

### FIXED CODE ###

H, W, M = map(int, input().split())

h = [0] * H
w = [0] * W
boms = set()

for _ in range(M):
    x, y = map(int, input().split())
    h[x - 1] += 1
    w[y - 1] += 1
    boms.add((x, y))

h_max = max(h)
w_max = max(w)

h_idx = [x + 1 for x, y in enumerate(h) if y == h_max]
w_idx = [x + 1 for x, y in enumerate(w) if y == w_max]

minus = -1
for x in h_idx:
    for y in w_idx:
        if not (x, y) in boms:
            minus = 0
            break

print(h_max + w_max + minus)
### BUGGY CODE ###

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    C = tuple(map(int, input().split()))

    cnt = 0
    for c in C:
        b = [i for i in B if i < c]
        lenb = len(b)
        if not lenb:
            continue
        for bi in b:
            a = [i for i in A if i < bi]
            lena = len(a)
            if not lena:
                continue
            else:
                cnt += lena

    print(cnt)

main()


### FIXED CODE ###

import bisect

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    C = tuple(map(int, input().split()))

    a = sorted(A)
    c = sorted(C)
    cnt = 0
    for i in B:
        x = bisect.bisect_left(a, i)
        y = bisect.bisect_right(c, i)
        cnt += x * (N - y)

    print(cnt)

main()
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(M):
  A[0] //= 2
  if N > 1:
    if A[0] < A[1]:
      A.sort(reverse=True)
print(sum(A))

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
A = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(A)
for i in range(M):
  m = heapq.heappop(A)
  heapq.heappush(A, (-m // 2) * (-1))

print(-sum(A))
### BUGGY CODE ###

n,C,*H=map(int,open(0).read().split());
dp=[0];
P=[0];
f=lambda I,h:dp[I]+H[I]*(H[I]-2*h)
for i in range(1,n):
    h=H[i]
    while len(P)>1 and f(P[0],h)>f(P[1],h):P.pop(0)
    dp+=[f(P[0],h)+h**2+C]
    while len(P)>1 and (H[P[-1]]-H[P[-2]])*(f(P[-1],0)-f(i,0))>(h-H[P[-1]])*(f(P[-2],0)-f(P[-1],0)):P.pop()
    P+=[i]
print(dp[-1])

### FIXED CODE ###

n,C,*H=map(int,open(0).read().split());
dp=[0];
P=[0];
def f(I,h):
    return dp[I]+H[I]*(H[I]-2*h)
def c(x,y,z):
    return (H[y]-H[x])*(f(y,0)-f(z,0))>(H[z]-H[y])*(f(x,0)-f(y,0))
for i in range(1,n):
    while len(P)>1 and f(P[0],H[i])>f(P[1],H[i]):P.pop(0)
    dp+=[f(P[0],H[i])+H[i]**2+C]
    while len(P)>1 and c(P[-2],P[-1],i):P.pop()
    P+=[i]
print(dp[-1])
### BUGGY CODE ###

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

mod = 1000000
for i in range(L, R+1):
  for j in range(i+1, R+1):
    tmp = (i * j) % 2019
    if mod > tmp:
      mod = tmp
print(mod)
    

### FIXED CODE ###

import sys
L, R = list(map(int, input().split()))

mod = 1000000
for i in range(L, R+1):
  for j in range(i+1, R+1):
    tmp = (i * j) % 2019
    if tmp == 0:
      print(tmp)
      sys.exit()
      
    if mod > tmp:
      mod = tmp
    
print(mod)
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from bisect import bisect_left as bl, bisect_right as br
n,q = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def sub(x, i):
    # i番目を取れるかどうか
    v = a[i]
    target = x - (v-x)
    num = i - bl(a, target-0.1)
    return num+1 >= n - i

anss = [None] * q
cumsum1 = [0] * n
cumsum0 = [0] * n
for i in range(n):
    if i%2:
        cumsum1[i] = cumsum1[i-1] + a[i]
        cumsum0[i] = cumsum0[i-1]
    else:
        cumsum0[i] = cumsum0[i-1] + a[i]
        cumsum1[i] = cumsum1[i-1]
        
for j in range(q):
    x = int(input())
    l = 0
    r = n-1
    while l<r-1:
        m = (r+l)//2
        if sub(x, m):
            r = m
        else:
            l = m
    # rまではxより大きくて取れる
#     print("r",  r)
    ans = sum(a[r:])
    ii = r-2 - (n-r-1)
    if ii>=0:
        if ii%2:
            ans += cumsum1[ii]
        else:
            ans += cumsum0[ii]
    anss[j] = ans
write("\n".join(map(str, anss)))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from bisect import bisect_left as bl, bisect_right as br
n,q = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def sub(x, i):
    # i番目を取れるかどうか
    v = a[i]
    target = x - (v-x)
    num = i - bl(a, target-0.1)
    return num+1 >= n - i

anss = [None] * q
cumsum1 = [0] * n
cumsum0 = [0] * n
cumsum = [0] * n
for i in range(n):
    if i%2:
        cumsum1[i] = cumsum1[i-1] + a[i]
        cumsum0[i] = cumsum0[i-1]
    else:
        cumsum0[i] = cumsum0[i-1] + a[i]
        cumsum1[i] = cumsum1[i-1]
    cumsum[i] = cumsum[i-1] + a[i]

for j in range(q):
    x = int(input())
    l = 0
    r = n-1
    while l<r-1:
        m = (r+l)//2
        if sub(x, m):
            r = m
        else:
            l = m
    # rまではxより大きくて取れる
#     ans = sum(a[r:])
    ans = cumsum[-1] - cumsum[r-1]
    ii = r-2 - (n-r-1)
    if ii>=0:
        if ii%2:
            ans += cumsum1[ii]
        else:
            ans += cumsum0[ii]
    anss[j] = ans
write("\n".join(map(str, anss)))
### BUGGY CODE ###

l = input()

dp = [[0, 0] for _ in l]

dp[0][0] = 1
dp[0][1] = 2

for i in range(1, len(l)):
    if l[i] == '0':
        dp[i][0] = dp[i-1][0] * 3
        dp[i][1] = dp[i-1][1]
    else:
        dp[i][0] = 3*dp[i-1][0] + dp[i-1][1]
        dp[i][1] = dp[i-1][1] * 2

print((dp[-1][0] + dp[-1][1]) % 1000000007)


### FIXED CODE ###

l = input()

dp = [[0, 0]] * len(l)

dp[0][0] = 1
dp[0][1] = 2

MOD = 1000000007

for i in range(1, len(l)):
    if l[i] == '0':
        dp[i][0] = (dp[i-1][0] * 3) % MOD
        dp[i][1] = dp[i-1][1] % MOD
    else:
        dp[i][0] = (3*dp[i-1][0] + dp[i-1][1]) % MOD
        dp[i][1] = (dp[i-1][1] * 2) % MOD

print((dp[-1][0] + dp[-1][1]) % MOD)
### BUGGY CODE ###

H,W,K=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
C=[]
nx=[]

for _ in range(H):
    C.append(list(input()))

def keiro(x,y,k):
    i=1
    while True:
        if y+i>W-1 or C[x][y+i]!='.' or i>k:
            break
        else:
            nx.append([x,y+i])
            i+=1
    
    i=1
    while True:
        if y-i<0 or C[x][y-i]!='.' or i>k:
            break
        else:
            nx.append([x,y-i])
            i+=1
    
    i=1
    while True:
        if x+i>H-1 or C[x+i][y]!='.' or i>k:
            break
        else:
            nx.append([x+i,y])
            i+=1
    
    i=1
    while True:
        if x-i<0 or C[x-i][y]!='.' or i>k:
            break
        else:
            nx.append([x-i,y])
            i+=1

    return 0

C[x1-1][y1-1]=str(0)
keiro(x1-1,y1-1,K)
taisho=nx.copy()
result=1
for j in nx:
    C[j[0]][j[1]]=result

while C[x2-1][y2-1]=='.':
    nx=[]
    if len(taisho)==0:
        result=-1
        break
    for l in taisho:
        keiro(l[0],l[1],K)
    result+=1
    for j in nx:
        C[j[0]][j[1]]=result
    taisho=nx.copy()

print(result)


### FIXED CODE ###

H,W,K=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
C=[]
nx=set([])

for _ in range(H):
    C.append(list(input()))

def keiro(x,y,k):
    i=1
    while True:
        if y+i>W-1 or C[x][y+i]!='.' or i>k:
            break
        else:
            if (x,y+i) not in nx:
                nx.add((x,y+i))
            i+=1
    
    i=1
    while True:
        if y-i<0 or C[x][y-i]!='.' or i>k:
            break
        else:
            if (x,y-i) not in nx:
                nx.add((x,y-i))
            i+=1
    
    i=1
    while True:
        if x+i>H-1 or C[x+i][y]!='.' or i>k:
            break
        else:
            if (x+i,y) not in nx:
                nx.add((x+i,y))
            i+=1
    
    i=1
    while True:
        if x-i<0 or C[x-i][y]!='.' or i>k:
            break
        else:
            if (x-i,y) not in nx:
                nx.add((x-i,y))
            i+=1

    return 0

C[x1-1][y1-1]=0
keiro(x1-1,y1-1,K)
taisho=nx.copy()
result=1
for j in nx:
    C[j[0]][j[1]]=result

while C[x2-1][y2-1]=='.':
    nx=set([])
    if len(taisho)==0 or result>10**6:
        result=-1
        break
    for l in taisho:
        keiro(l[0],l[1],K)
    result+=1
    for j in nx:
        C[j[0]][j[1]]=result
    taisho=nx.copy()

print(result)
### BUGGY CODE ###

def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()


### FIXED CODE ###

def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()
### BUGGY CODE ###

r,g,b,n = map(int, input().split())
ans = 0
for i in range(n // r + 1):
        for j in range((n - i * r)// g + 1):
                if ( n -  ( i * r  +  j * g )) % b == 0 and i * r + j * g <= n:
                        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 - i * r)// g + 1):
                if ( n -  ( i * r  +  j * g )) % b == 0:
                        ans += 1
print(ans)
### BUGGY CODE ###

from fractions import gcd
from functools import reduce

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


MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

l = reduce(lcm, A)
ans = 0
for a in A:
  ans += (l//a) % MOD
  ans %= MOD

print(ans)

### FIXED CODE ###

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


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


def power(n, r, mod=10**9+7):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod


MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

l = A[0]
for a in A:
  t = l%a
  if t != 0:
    l = lcm(l, a)

l %= MOD
ans = 0
for a in A:
  ans += (l * power(a, MOD-2)) % MOD
  ans %= MOD

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

import math

n=int(input())

for x in range(1,n+1):
  ans=0
  b=int(math.sqrt(x))
  for q in range(1,b+1):
    c=int(math.sqrt(x-q*q))
    for r in range(1,c+1):
      d=x-q*q-r*r-q*r
      if d>0:
        
        e=int(math.sqrt(d))
        for s in range(1,e+1):
          if q*q+r*r+s*s+q*r+r*s+s*q==x:
            ans+=1
      
  print(ans)


### FIXED CODE ###

n=int(input())

a=[0]*n

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      k=x*x+y*y+z*z+x*y+y*z+z*x
      if k <=n:
        a[k-1]+=1
        
for q in range(n):
  print(a[q])
### BUGGY CODE ###

N,K=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(N):
    for j in range(B[i]):
        C.append(A[i])
C.sort()
print(C[K-1])

### FIXED CODE ###

N,K=map(int,input().split())
A=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    T=[a,b]
    A.append(T)
A.sort()
counter=0
for i in range(N):
     counter+=A[i][1]
     if counter>=K:
         counter=i
         break   
print(A[counter][0])
### BUGGY CODE ###

from itertools import product
import math

K = int (input())
sum = 0
for a, b, c in product(range(1,K+1), repeat=3):
    sum += math.gcd(math.gcd(b,c),a)
print (sum)

### FIXED CODE ###

import math

t = int (input())
sum = 0

for i in range (1, t+1):
    for j in range (1, t+1):
        aux = math.gcd(i,j)
        for k in range (1, t+1):
            sum += math.gcd(aux, k)

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

n,m = map(int,input().split())
li = []
counter = 0
for i in range(m):
    l,r = map(int,input().split())
    for j in range(l,r+1):
        li.append(j)
import collections
c = collections.Counter(li)
for k in c.values():
    if k == m:
        counter += 1
print(counter)


### FIXED CODE ###

n,m = map(int,input().split())
l,r = map(int,input().split())
counter = 0
for i in range(m-1):
    l1,r1 = map(int,input().split())
    if l < l1:
        l = l1
    if r > r1:
        r = r1
if r < l:
    print(0)
else:
    print(r-l+1)
### BUGGY CODE ###

n = int(input())
L = sorted(list(map(int, input().split())))

tri = []
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                tri.append((L[i], L[j], L[k]))
            elif L[k] >= L[i] + L[j]:
                break

print(len(set(tri)))


### FIXED CODE ###

import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

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

k = int(input())
s = len(input())
MOD = 10 ** 9 + 7

dp1 = [0 for i in range(s + 1)]
dp1[0] = 25
dp1[1] = 1
dp2 = [0 for i in range(s + 1)]
# 1moji

# 2moji kara s+k moji
for i in range(2, s + k + 1):
    dp2[0] = dp1[0] * 25
    for j in range(s):
        dp2[j + 1] = dp1[j] + dp1[j + 1] * 25
    dp1 = dp2.copy()
#    print(dp1, (pow(26, s + k, MOD) - sum(dp1[0:-1]) % MOD) % MOD)
print(pow(26, s + k, MOD) - sum(dp1[0:s:]) % MOD)


### FIXED CODE ###

k = int(input())
s = len(input())
MOD = 10 ** 9 + 7


def mod_inv(n):
    return pow(n, MOD - 2, MOD)

total = pow(26, k + s, MOD)
tmp = pow(25, k + s, MOD)
total = (total - tmp) % MOD

for i in range(0, s-1):
    tmp = ((tmp * ((k+s) - i)) % MOD * mod_inv((i + 1) * 25)) % MOD
    total = (total - tmp) % MOD
print(total)
### BUGGY CODE ###

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

adj_list = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

for _ in range(N-1):
    a,b = map(int,input().split())
    a-=1
    b-=1
    adj_list[a].append(b)
    adj_list[b].append(a)

def df(current, score, residual):
    residual = list(set(residual)-set([current]))
    next_nodes = adj_list[current]
    next_nodes = [node for node in next_nodes
            if node in residual]
    for node in next_nodes:
        counter[node]+=score
        df(node, counter[node], residual)

for _ in range(Q):
    p,x=map(int, input().split())
    counter[p-1]+=x
df(0, counter[0], list(range(N)))
print(*counter)


### FIXED CODE ###

import sys
sys.setrecursionlimit(2*10**9)

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

adj_list = [[] for _ in range(N)]
counter = [0 for _ in range(N)]
reached = [0 for _ in range(N)]

for _ in range(N-1):
    a,b = map(int,input().split())
    a-=1
    b-=1
    adj_list[a].append(b)
    adj_list[b].append(a)

def df(current, score):
    next_nodes = adj_list[current]
    reached[current]=1
    for node in next_nodes:
        if reached[node]==0:
            counter[node]+=score
            df(node, counter[node])

for _ in range(Q):
    p,x=map(int, input().split())
    counter[p-1]+=x
df(0, counter[0])
print(*counter)
### BUGGY CODE ###


def do():
    S = input()
    l = len(S)
    S = S[::-1]
    dp =[[0 ] * 13 for _ in range(l + 1)]
    kurai = 1
    MOD = (10 ** 9) + 7
    dp[0][0] = 1

    for keta in range(len(S)):
        c =S[keta]

        if c == "?":
            for j in range(0,10):
                kurai %= 13
                temp = (j * kurai) % 13
                for i in range(13):
                    dp[keta + 1][(temp + i) % 13] += (dp[keta][i] )
                    dp[keta + 1][(temp + i) % 13] %= MOD
        else:
            temp = (int(c) * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] )
                dp[keta + 1][(temp + i) % 13] %= MOD
        kurai *= 10
        keta %= MOD
    print(dp[-1][5] % MOD)

if __name__ == "__main__":
    do()

### FIXED CODE ###


import sys

S =  sys.stdin.readline()[:-1]
l = len(S)
# S = S[::-1]
S = list(reversed(S))

dp =[[0 ] * 13 for _ in range(l + 1)]
kurai = 1
MOD = (10 ** 9) + 7
dp[0][0] = 1

for keta in range(len(S)):
    c =S[keta]

    if c == "?":
        for j in range(0,10):
            kurai %= 13
            temp = (j * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13] += (dp[keta][i] )
                dp[keta + 1][(temp + i) % 13] %= MOD
    else:
        kurai %= 13

        temp = (int(c) * kurai) % 13
        for i in range(13):
            dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] )
            dp[keta + 1][(temp + i) % 13] %= MOD
    kurai *= 10
    keta %= MOD
print(dp[-1][5] )
### BUGGY CODE ###

import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
v_w = {0: 0}
for _ in range(n):
    w, v = map(int, input().split())
    for wk, vk in sorted(v_w.items()):
        nw = w + wk
        if nw > cap: break
        if nw in v_w:
            v_w[nw] = max(v_w[nw], v + vk)
        else:
            v_w[nw] = v + vk
print(max(v_w.values()))


### FIXED CODE ###

import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap,w-1,-1):
            nv=val[wk-w]+v
            if val[wk]<nv:
                val[wk]=nv
    return max(val)
print(nap(n,cap))
### BUGGY CODE ###

import math
from functools import reduce


def gcd(*nums):
  return reduce(math.gcd, nums)


input_num = int(input()) + 1
result = 0
for a in range(1, input_num):
  for b in range(1, input_num):
    for c in range(1, input_num):
      result += gcd(a, b, c)
print(result)


### FIXED CODE ###

import math
from functools import reduce

def gcd(*nums):
  return reduce(math.gcd, nums)


input_num = int(input()) + 1
result = 0
for a in range(1, input_num):
  for b in range(1, input_num):
    for c in range(1, input_num):
        result += gcd(a, b, c)

print(result)
### BUGGY CODE ###

def main():
    n = input()
    a = list(map(lambda x:int(x),input().split(" ")))
    res = ""
    res = [str(a.index(i+1) + 1) for i in range(len(a))]
    print(" ".join(res))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
#input = sys.stdin.readline

def main():
    n = input()
    a = input().split(" ")
    # r = ""
    # for i in range(int(n)):
    #     r += str(a.index(str(i+1)) + 1) + " "
    # print(r[:-1])
    a = [(a[i],str(i+1)) for i in range(len(a))]
    a = list(map(lambda x:x[1],sorted(a,key=lambda x:int(x[0]))))
    print(" ".join(a))

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

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

"""ナイーブ
count = 0
for i in range(n-1):
    for j in range(i, n):
        if i != j and abs(i-j) == a[i] + a[j]:
            count += 1
print(count)
"""
# idxとa[idx]で別々にループ回すからO(n**2)になってしまう
# 前処理としてidxとa[idx]の二つの情報をまとめた何かがつくれれば、、ってとこまでは気付けた

a_plus = [0]*n
a_minus = [0]*n
for i in range(n):
    a_plus[i] = i + a[i]
    a_minus[i] = i - a[i]
ans = 0
already_count = []
for i in a_plus:
    if i in already_count:
        continue
    else:
        ans += a_plus.count(i)*a_minus.count(i)
        already_count.append(i)
print(ans)


### FIXED CODE ###

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

"""ナイーブ
count = 0
for i in range(n-1):
    for j in range(i, n):
        if i != j and abs(i-j) == a[i] + a[j]:
            count += 1
print(count)
"""
# idxとa[idx]で別々にループ回すからO(n**2)になってしまう
# 前処理としてidxとa[idx]の二つの情報をまとめた何かがつくれれば、、ってとこまでは気付けた
from collections import Counter
a_plus = [0]*n
a_minus = [0]*n
for i in range(n):
    a_plus[i] = i + a[i]
    a_minus[i] = i - a[i]
c1 = Counter(a_plus)
c2 = Counter(a_minus)
#print(c1)
#print(c2)
ans = 0
for key in c1.keys():
    if key in c2.keys():
        ans += c1[key]*c2[key]
print(ans)
### BUGGY CODE ###

import sys

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

# 各文字が最初に出現するインデックス
posFirst = {}
for i, A in enumerate(As):
    if A not in posFirst:
        posFirst[A] = i + N

# 次に同じ文字が出現するインデックス
nexts = [-1] * N
posLast = {}
for i in reversed(range(N)):
    A = As[i]
    if A not in posLast:
        nexts[i] = posFirst[A]
    else:
        nexts[i] = posLast[A]
    posLast[A] = i

v0s = [-1] * N
v2s = [-1] * N
for i in range(N):
    if nexts[i] < N-1:
        v2s[i] = nexts[i] + 1
        v0s[nexts[i] + 1] = i
    else:
        v2s[i] = i

v9s = [-1] * N
for i in reversed(range(N)):
    if v9s[i] == -1:
        v9s[i] = v2s[i]
    v9s[v0s[i]] = v9s[i]

numLoop = 0
vNow = 0
while True:
    vNow = nexts[vNow]
    if vNow >= N:
        numLoop += 1
    vNow %= N
    if vNow == N-1:
        break
    vNow += 1

K %= (numLoop+1)

if K == 0:
    print()
    sys.exit()

numLoop = 0
vNow = 0
while True:
    vNow = nexts[vNow] + 1
    if vNow >= N:
        numLoop += 1
    vNow %= N
    if numLoop == K-1:
        break

ss = []
s2s = set()
for v in range(vNow, N):
    X = As[v]
    if X not in s2s:
        ss.append(X)
        s2s.add(X)
    else:
        s = ss.pop()
        s2s.discard(s)
        while s != X:
            s = ss.pop()
            s2s.discard(s)

print(' '.join(map(str, ss)))



### FIXED CODE ###

def solve():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))

    def getDistNexts(As):
        lenA = len(As)
        poss = dict()
        for i, A in enumerate(As):
            if A not in poss:
                poss[A] = i + lenA

        distNexts = [0]*(lenA)
        for i in reversed(range(lenA)):
            distNexts[i] = poss[As[i]] - i
            poss[As[i]] = i
        return distNexts

    distNexts = getDistNexts(As)

    NK = N*K
    maxD = (NK).bit_length() - 1

    dp = [[0]*(N) for _ in range(maxD+1)]
    for i in range(N):
        dp[0][i] = distNexts[i] + 1
    for d in range(1, maxD+1):
        for i in range(N):
            i2 = i + dp[d-1][i]
            dp[d][i] = i2 + dp[d-1][i2%N] - i

    iNow = 0
    dist = 0
    for d in reversed(range(maxD+1)):
        if dist+dp[d][iNow] < NK:
            dist += dp[d][iNow]
            iNow = dist%N

    Ss = []
    setS = set()
    for A in As[iNow:]:
        if A in setS:
            S = ''
            while S != A:
                S = Ss.pop()
                setS.remove(S)
        else:
            Ss.append(A)
            setS.add(A)

    if Ss:
        print(' '.join(map(str, Ss)))


solve()
### BUGGY CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
b = collections.Counter(a)
c = b.most_common()
values, counts = zip(*b.most_common())
d = (counts)
ans = 0

for j in range(len(d)):
    f = d[j]
    if f > 1:
        ans = ans + (f*(f - 1)/2)

for i in range(n):
    g = a[i]
    gc = a.count(g)
    tem = ans - gc + 1
    print(int(tem))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0]*n
ans = 0

for i in range(n):
    b[a[i] - 1] += 1

for i in range(n):
    ans += b[i]*(b[i] - 1)//2

for i in range(n):
    print(ans - b[a[i] -1] + 1)
### BUGGY CODE ###

n=[]
t=[]
nq=list(map(int,input().split()))
for i in range(nq[0]):
	inp=input().split()
	n.append(int(inp[1]))
	t.append(inp[0])
cnt1=0
while len(n)!=0:	
	n[0]=n[0]-nq[1]
	if n[0]<=0:
		cnt1=cnt1+nq[1]+n[0]
		print(t[0],cnt1)
		n.pop(0)
		t.pop(0)		
	else:
		x=0
		y=0
		x=n[0]
		y=t[0]
		for j in range(len(n)-1):
			n[j]=n[j+1]
			t[j]=t[j+1]
		n[len(n)-1]=x
		t[len(t)-1]=y
		cnt1+=nq[1]
	
		


### FIXED CODE ###

n=[]
t=[]
nq=list(map(int,input().split()))
for i in range(nq[0]):
	inp=input().split()
	n.append(int(inp[1]))
	t.append(inp[0])
cnt1=0
while len(n)!=0:	
	n[0]=n[0]-nq[1]
	if n[0]<=0:
		cnt1=cnt1+nq[1]+n[0]
		print(t[0],cnt1)
		n.pop(0)
		t.pop(0)	
		
	else:
		n.append(n[0])
		t.append(t[0])
		n.pop(0)
		t.pop(0)
		cnt1+=nq[1]