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

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
abcbdab
bdcaba
abc
abc
abc
bc

output:
4
3
2

"""
import sys


def lcs(A, B):
    m, n = len(A), len(B)
    count_list = [[0] * (n + 1) for _ in range(m + 1)]

    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if A[i - 1] == B[j - 1]:
                count_list[i][j] = count_list[i - 1][j - 1] + 1
            elif count_list[i - 1][j] >= count_list[i][j - 1]:
                count_list[i][j] = count_list[i - 1][j]
            else:
                count_list[i][j] = count_list[i][j - 1]

    return count_list[m][n]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    pair_num = int(_input[0])

    word_list = _input[1:]
    # assert len(word_list) == 2 * pair_num
    for k in range(0, len(word_list), 2):
        print(lcs(word_list[k].strip(), word_list[k + 1].strip()))

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
abcbdab
bdcaba
abc
abc
abc
bc

output:
4
3
2

"""
import sys


def lcs(A, B):
    m, n = len(A), len(B)
    count_list = [[0] * (n + 1) for _ in range(m + 1)]

    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if A[i - 1] == B[j - 1]:
                count_list[i][j] = count_list[i - 1][j - 1] + 1
            elif count_list[i - 1][j] >= count_list[i][j - 1]:
                count_list[i][j] = count_list[i - 1][j]
            else:
                count_list[i][j] = count_list[i][j - 1]

    return count_list[m][n]


def lcs_better(A, B):
    costs = [0]
    for c in B:
        for index in range(len(costs) - 1, -1, -1):
            # print(costs, index + 1)
            x_findex_index = A.find(c, costs[index])
            if x_findex_index != -1:
                if index + 1 < len(costs):
                    costs[index + 1] = min(costs[index + 1], x_findex_index + 1)
                else:
                    costs.append(x_findex_index + 1)
    return len(costs) - 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    pair_num = int(_input[0])

    word_list = _input[1:]
    # assert len(word_list) == 2 * pair_num
    for k in range(0, len(word_list), 2):
        print(lcs_better(word_list[k].strip(), word_list[k + 1].strip()))
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))

cnt = 1
s=0

for i in range(N):
  for j in range(i):
    if P[i] > P[j]:
      break
    
    elif i-1 == j:
      cnt += 1
    
    else:
      continue

print(cnt)

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
 
cnt = 0
M = 10**6

for i in range(N):
  if M >= P[i]:
    cnt += 1
    M = P[i]
    
print(cnt)
### BUGGY CODE ###

N = int(input())
L = [_ for _ in map(int,input().split())]
for i in range(1,N+1):
    print(str(L.index(i)+1),end = " ")

### FIXED CODE ###

N = int(input())
L = [_ for _ in map(int,input().split())]
res = []
for student,people in enumerate(L):
    res.append([people,student])
res.sort()
for s in res:
    print(s[1]+1,end = " ")
### BUGGY CODE ###

from heapq import heappush, heappop
from collections import defaultdict
import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
inf = float("inf")
d = defaultdict(list)

for _ in range(M):
    A, B, C = map(int, input().split())
    if C>L:continue
    d[A-1].append((B-1, C))
    d[B-1].append((A-1, C))

charged_dict = [[(inf,inf)]*N for _ in range(N)]
for j in range(N):
    charged_dict[j][j] = (0, 0)
    q = [(0, 0, j)]
    while q:
        charged, used, u = heappop(q)
        for v, next_cost in d[u]:
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if charged_dict[j][v] > c:
                charged_dict[j][v] = c
                heappush(q, c+(v,))

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = charged_dict[s-1][t-1][0]
    print(ans if ans!=inf else -1)


### FIXED CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
inf = 10**15
V = [[] for _ in range(N)]

for _ in range(M):
    A, B, C = map(int, input().split())
    if C>L:continue
    V[A-1].append((B-1, C))
    V[B-1].append((A-1, C))

dists = []
for i in range(N):
    dist = [(inf,inf)] * N
    dist[i] = (0, 0)
    u = [False] * N
    for _ in range(N):
        (charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]])
        u[j] = True
        for k, next_cost in V[j]:
            if j==k: continue
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if dist[k] > c:
                dist[k] = c
    dists.append(dist)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = dists[s-1][t-1][0]
    print(ans if ans!=inf else -1)
### BUGGY CODE ###

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

A=[]
base=0
B=[]

for i in range(N):
    sum=0
    for j in range(1,p[i]+1):
        sum+=j
    A.append(sum/p[i])
for l in range(K):
    base+=A[l]
B.append(base)
for k in range(K,N):
    base+=A[k]
    base-=A[k-K]
    B.append(base)    

print(max(B))



### FIXED CODE ###

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

A=[]
base=0
B=[]

for i in range(N):
    if p[i]%2==0:
        A.append(((p[i]+1)*p[i]//2)/p[i])
    else:
        A.append((((p[i]+1)*(p[i]//2)+((p[i]+1)//2)))/p[i])
    
for l in range(K):
    base+=A[l]
B.append(base)
for k in range(K,N):
    base+=A[k]
    base-=A[k-K]
    B.append(base)    

print(max(B))
#print(A)
### BUGGY CODE ###

import numpy as np

N=int(input())
A=[int(c) for c in input().split()]

A=np.array(A)





for i in range(sorted(A)[1],1,-1):
	if(np.sum(A%i==0)>=N-1):
		print(i)
		exit()
print(1)





### FIXED CODE ###

#import numpy as np

N=int(input())
A=[int(c) for c in input().split()]

#A=np.array(A)






#大きい方から
for i in range(sorted(A)[1],1,-1):
#	if(np.sum(A%i==0)>=N-1):
	
	#check
	b=0
	j=0
	while(b<2):
		if(j==N):
			print(i)
			exit()
		if(A[j]%i!=0):
			b+=1
		j+=1
print(1)
### BUGGY CODE ###

N = int(input())
S = input()
count = 0
for k in range(2, N):
    for j in range(1, k):
        for i in range(0, j):
            if (S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]) and j-i!=k-j:
                count += 1
print(count)

### FIXED CODE ###

N = int(input())
S = input()
r = 0
g = 0
b = 0
for a in range(N):
    if S[a] == "R":
        r += 1
    elif S[a] == "G":
        g += 1
    elif S[a] == "B":
        b += 1
all = r*g*b
count = 0
for i in range(0, N-2):
    for j in range(i+1, N-1):
        k = 2*j-i
        if k < N:
            if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
                count += 1
print(all-count)
### BUGGY CODE ###

N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

tmp = []
for _ in range(M):
    b,c = [int(i) for i in input().split()]
    tmp += [c]*b

A.sort()
tmp.sort(reverse=True)

z = len(tmp)
ans = 0
for i in range(N):
    if i < z:
        ans += max(A[i],tmp[i])
    else:
        ans += A[i]

print(ans)


### FIXED CODE ###

N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
bc = [tuple(int(i) for i in input().split()) for _ in range(M)]

A.sort()
bc.sort(key=lambda t: t[1], reverse=True)

index = 0
count = 0
for i in range(N):
    if index >= M or A[i] >= bc[index][1]:
        break
    A[i] = bc[index][1]
    count += 1
    if bc[index][0] <= count:
        index += 1
        count = 0

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

import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    H,W = map(int, input().split())
    grid = [list(input().rstrip()) for _ in range(H)]
    ans = 0
    while True:
        new_grid = [['.']*W for _ in range(H)]
        black_cnt = 0
        for y in range(H):
            for x in range(W):
                if grid[y][x] == '#':
                    black_cnt += 1
                    new_grid[y][x] = '#'
                    for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:
                        ny = y+dy
                        nx = x+dx
                        if 0<=ny<H and 0<=nx<W:
                            new_grid[ny][nx] = '#'
        if black_cnt == W*H: break

        ans += 1
        grid = deepcopy(new_grid)

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    H, W = map(int,input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        S = input()
        for x, s in enumerate(S):
            if s == "#":
                q.append((y, x))
                visited[y][x] = True

    ans = -1
    while q:
        ans += 1
        nq = []
        for y, x in q:
            if 0 < x and not visited[y][x-1]:
                visited[y][x-1] = True
                nq.append((y,x-1))
            if x < W-1 and not visited[y][x+1]:
                visited[y][x+1] = True
                nq.append((y,x+1))
            if 0 < y and not visited[y-1][x]:
                visited[y-1][x] = True
                nq.append((y-1, x))
            if y < H-1 and not visited[y+1][x]:
                visited[y+1][x] = True
                nq.append((y+1,x))
        if nq:
            q = nq
        else:
            break

    print(ans)

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

import queue
H, W = map(int, input().split())
numw = 0
S = []
for i in range(H):
  ss = input()
  numw += ss.count(".")
  S.append(ss)
#print(numw)
D = [[1000000]*W for i in range(H)]
q = queue.Queue()
q.put((0, 0, 0))
D[0][0] = 0
while not(q.empty()):
  i, j, d = q.get()
  D[i][j] = d
  if j > 0 and S[i][j-1] == "." and D[i][j-1] > d:
    q.put((i, j-1, d+1))
  if i > 0 and S[i-1][j] == "." and D[i-1][j] > d:
    q.put((i-1, j, d+1))
  if j+1 < W and S[i][j+1] == "." and D[i][j+1] > d:
    q.put((i, j+1, d+1))
  if i+1 < H and S[i+1][j] == "." and D[i+1][j] > d:
    q.put((i+1, j, d+1))
#print(D)
if D[H-1][W-1] == 1000000:
  print(-1)
  exit()
r = numw-D[H-1][W-1]-1
print(r)


### FIXED CODE ###

import queue
H, W = map(int, input().split())
numw = 0
S = []
for i in range(H):
  ss = input()
  numw += ss.count(".")
  S.append(ss)
#print(numw)
D = [[-1]*W for i in range(H)]
q = queue.Queue()
q.put((0, 0, 0))
D[0][0] = 0
while not(q.empty()):
  i, j, d = q.get()
  if j > 0 and S[i][j-1] == "." and D[i][j-1] < 0:
    D[i][j-1] = d+1
    q.put((i, j-1, d+1))
  if i > 0 and S[i-1][j] == "." and D[i-1][j] < 0:
    D[i-1][j] = d+1
    q.put((i-1, j, d+1))
  if j+1 < W and S[i][j+1] == "." and D[i][j+1] < 0:
    D[i][j+1] = d+1
    q.put((i, j+1, d+1))
  if i+1 < H and S[i+1][j] == "." and D[i+1][j] < 0:
    D[i+1][j] = d+1
    q.put((i+1, j, d+1))
#print(D)
if D[H-1][W-1] < 0:
  print(-1)
  exit()
r = numw-D[H-1][W-1]-1
print(r)
### BUGGY CODE ###

R, C, K = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]

board = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in rcv:
    board[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]

for r in range(1, R + 1):
    for c in range(1, C + 1):
        v = board[r][c]
        for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v)

ans = 0
for i in range(4):
    ans = max(ans, dp[i][R][C])

print(ans)


### FIXED CODE ###

R, C, K = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]

board = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in rcv:
    board[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]

for r in range(1, R + 1):
    for c in range(1, C + 1):
        v = board[r][c]
        for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v)

ans = 0
for i in range(4):
    ans = max(ans, dp[i][R][C])

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

def combinations(l, m):
    if m == 1:
        for element in l:
            yield [element]
    for i, element in enumerate(l):
        for combination in combinations(l[i + 1:], m - 1):
            combination.append(element)
            yield combination


def main():
    N = int(input())
    p = list(map(float, input().split()))
    dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
    p_mul = 1
    dp[0][0] = 1
    for i in range(1, N + 1):
        p_mul *= (1-p[i-1])
        dp[i][0] = p_mul
    for i in range(1, N+1):
        for j in range(1, N+1):
            dp[i][j] = dp[i - 1][j] * \
                (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
    print(sum(dp[N][N//2+1:]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    p = list(map(float, input().split()))
    dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
    p_mul = 1
    dp[0][0] = 1
    for i in range(1, N + 1):
        p_mul *= (1-p[i-1])
        dp[i][0] = p_mul
    for i in range(1, N+1):
        for j in range(1, N+1):
            dp[i][j] = dp[i - 1][j] * \
                (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
    print(sum(dp[N][N//2+1:]))


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

n=int(input())
a=[]
for i in range(n):
    b=int(input())
    a.append(b)

count=1
c=a[0]

while c != 2:
    c=a[c-1]
    if a[c-1] == b:
        print(-1)
        exit()
    b=c
    count +=1 

print(count)    

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]

count=1

for i in range(n):
    if count == 2:
        print(i)
        exit()
    count=a[count-1]

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

import sys
input = sys.stdin.readline
def main():
    K = int(input())
    for i in range(1,10**8):
        r = True
        s = str(i)
        if len(s) != 1:
            for j in range(len(s)-1):
                if abs(int(s[j])-int(s[j+1])) > 1:
                    r = False
                    break
        if r:
            K -= 1
            if K == 0:
                print(i)
                break
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def f(v,i,ans):
    if i == 0:return
    if str(v)[-1] != "0":
        x = int(str(v)+str(int(str(v)[-1])-1))
        ans.add(x)
        f(x,i-1,ans)
    y = int(str(v)+str(v)[-1])
    ans.add(y)
    f(y,i-1,ans)
    if str(v)[-1] != "9":
        z = int(str(v)+str(int(str(v)[-1])+1))
        ans.add(z)
        f(z,i-1,ans)
def main():
    K = int(input())
    ans = set()
    for i in range(1,10):
        ans.add(i)
        f(i,10,ans)
    ans = list(ans)
    ans.sort()
    print(ans[K-1])
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

d = 1
i = 2
if N == 1:
  d = P
else:
  while i <= pow(P, 1/N)+1:
    if P % i**N == 0:
      P //= i**N
      d *= i
    else:
      i += 1
print(d)

### FIXED CODE ###

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

if N == 1:
  d = P
else:
  d = 1
  i = 2
  while i <= round(pow(P, 1/N)):
    if P % i**N == 0:
      P //= i**N
      d *= i
    else:
      i += 1
print(d)
### BUGGY CODE ###

import numpy
def main():
  n,m=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  for i in range(m):
    a[-1]=a[-1]//2
    a=sorted(a)
  print(sum(a))
main()


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[-_ for _ in a]
import heapq
heapq.heapify(a)
for i in range(m):
  temp=-heapq.heappop(a)
  heapq.heappush(a,-(temp//2))
  
print(-sum(a))
### BUGGY CODE ###

a,b,c= input().split()
l=[]
m=[]
for i in range (int(b)):
    l.append([int(i) for i in input().split() ])
for i in range (int(c)):
    m.append([int(i) for i in input().split() ])
# print (l,m)
s=0
for j in m:
    for i in l:
        if j[0]<=i[0] and i[1]<=j[1]:
            s+=1
    print(s)
    s=0


### FIXED CODE ###

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

L = [[0 for x in range(N+1)] for x in range(N+1)]
for i in range(M):
    x, y = map(int,input().split())
    L[x][y] += 1
for x in range(N+1):
    for y in range(N):
        L[x][y+1] += L[x][y]  

for y in range(N+1):
    for x in range(N):
        L[x+1][y] += L[x][y]  
for _ in range(Q):
    x, y = map(int, input().split())
    print(L[N][y]-L[x-1][y])
### BUGGY CODE ###

from collections import deque

h,w = map(int,input().split())
matrix = [["a" for _ in range(w+2)]] + [list("a" + input() + "a") for _ in range(h)] + [["a" for _ in range(w+2)]]

matrix_list1 = deque()
cnt = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if matrix[i][j] == "#":
            matrix_list1.append([i,j])

while len(matrix_list1) != 0:     
    for _ in range(len(matrix_list1)):
        x,y = matrix_list1.popleft()
        if matrix[x+1][y] == ".":
            matrix[x+1][y] = "#"
            matrix_list1.append([x+1,y])
        if matrix[x-1][y] == ".":
            matrix[x-1][y] = "#"
            matrix_list1.append([x-1,y])
        if matrix[x][y+1] == ".":
            matrix[x][y+1] = "#"
            matrix_list1.append([x,y+1])
        if matrix[x][y-1] == ".":
            matrix[x][y-1] = "#"
            matrix_list1.append([x,y-1])
    else:
        if len(matrix_list1) > 0:
            cnt += 1
    
print(cnt)

### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())
matrix = [["a" for _ in range(w+2)]] + [list("a" + input() + "a") for _ in range(h)] + [["a" for _ in range(w+2)]]

matrix_list1 = deque()
cnt = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if matrix[i][j] == "#":
            matrix_list1.append([i,j])

while len(matrix_list1) != 0:     
    for _ in range(len(matrix_list1)):
        x,y = matrix_list1.popleft()
        if matrix[x+1][y] == ".":
            matrix[x+1][y] = "#"
            matrix_list1.append([x+1,y])
        if matrix[x-1][y] == ".":
            matrix[x-1][y] = "#"
            matrix_list1.append([x-1,y])
        if matrix[x][y+1] == ".":
            matrix[x][y+1] = "#"
            matrix_list1.append([x,y+1])
        if matrix[x][y-1] == ".":
            matrix[x][y-1] = "#"
            matrix_list1.append([x,y-1])
    else:
        if len(matrix_list1) > 0:
            cnt += 1
    
print(cnt)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix_2
# CreatedDate:  2020-08-09 01:27:04 +0900
# LastModified: 2020-08-09 01:48:19 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    s = input()
    q = int(input())
    for _ in range(q):
        query = list(map(str, input().split()))
        if len(query) == 1:
            s = s[::-1]
        else:
            if query[1] == '1':
                s = query[2] + s
            else:
                s = s + query[2]
    print(s)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix_3
# CreatedDate:  2020-08-30 13:22:07 +0900
# LastModified: 2020-08-30 13:41:03 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    S = input()
    Q = int(input())
    appendix_1 = ''
    appendix_2 = ''
    reverse = 0
    for _ in range(Q):
        q = list(input().split())
        if q[0] == '1':
            reverse += 1
        else:
            if q[1] == '1' and reverse % 2 == 0:
                appendix_1 += q[2]
            elif q[1] == '1' and reverse % 2 == 1:
                appendix_2 += q[2]
            if q[1] == '2' and reverse % 2 == 0:
                appendix_2 += q[2]
            elif q[1] == '2' and reverse % 2 == 1:
                appendix_1 += q[2]

    if reverse % 2 == 0:
        print(appendix_1[::-1] + S + appendix_2)
    else:
        print(appendix_2[::-1] + S[::-1] + appendix_1)



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

import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    a = list(map(int,ipt().split()))
#    n = 2*10**5
#    k = 2*10**5
#    a = [i+1 for i in range(n)]
    nxt = [-1]*(n)
    pa = [-1]*(2*10**5+1)
    for i,ai in enumerate(a*2):
        pai = pa[ai]
        if pai == -2:
            continue
        if pai == -1:
            pa[ai] = i
        else:
            nxt[pai] = i-pai+1
            if i <= n-1:
                pa[ai] = i
            else:
                pa[ai] = -2
    dbl = [nxt]
    ni = 1
    while ni <= n*k:
        nnxt = [0]*n
        pnxt = dbl[-1]
        for i in range(n):
            nnxt[i] = pnxt[i]+pnxt[(i+pnxt[i])%n]
        dbl.append(nnxt)
        if min(nnxt) > n*k:
            break
        ni *= 2
    np = 0
    ld = len(dbl)
    ni = len(dbl)-1
#    print(dbl)
    for db in dbl[::-1]:
        while True:
            if db[np%n] < n*k-1-np:
                np += db[np%n]
            else:
                break
#        print(np)
    ans = []
    np %= n
    while np < n:
        if nxt[np]+np > n:
            ans.append(a[np])
            np += 1
        elif nxt[np]+np == n:
            np = n
        else:
            np = nxt[np]+np
    print(" ".join(map(str,ans)))



    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    a = list(map(int,ipt().split()))
#    n = 2*10**5
#    k = 2*10**5
#    a = [i+1 for i in range(n)]
    nxt = [-1]*(n)
    pa = [-1]*(2*10**5+1)
    for i,ai in enumerate(a*2):
        pai = pa[ai]
        if pai == -2:
            continue
        if pai == -1:
            pa[ai] = i
        else:
            nxt[pai] = i-pai+1
            if i <= n-1:
                pa[ai] = i
            else:
                pa[ai] = -2
    dbl = [nxt]
    ni = 1
    while ni <= n*k:
        nnxt = [0]*n
        pnxt = dbl[-1]
        for i in range(n):
            nnxt[i] = pnxt[i]+pnxt[(i+pnxt[i])%n]
        dbl.append(nnxt)
        if min(nnxt) > n*k:
            break
        ni *= 2
    np = 0
    ld = len(dbl)
    ni = len(dbl)-1
#    print(dbl)
    for db in dbl[::-1]:
        while True:
            if db[np%n] < n*k-1-np:
                np += db[np%n]
            else:
                break
#        print(np)
    ans = []
    np %= n
    while np < n:
        if nxt[np]+np > n:
            ans.append(a[np])
            np += 1
        elif nxt[np]+np == n:
            np = n
        else:
            np = nxt[np]+np
    print(" ".join(map(str,ans)))



    return

if __name__ == '__main__':
    main()