Problem:


Score : 700 points

Problem Statement

We have a sequence of N \times K integers: X=(X_0,X_1,\cdots,X_{N \times K-1}).
Its elements are represented by another sequence of N integers: A=(A_0,A_1,\cdots,A_{N-1}). For each pair i, j (0 \leq i \leq K-1,\ 0 \leq j \leq N-1), X_{i \times N + j}=A_j holds.

Snuke has an integer sequence s, which is initially empty.
For each i=0,1,2,\cdots,N \times K-1, in this order, he will perform the following operation:

If s does not contain X_i: add X_i to the end of s.

If s does contain X_i: repeatedly delete the element at the end of s until s no longer contains X_i. Note that, in this case, we do not add X_i to the end of s.

Find the elements of s after Snuke finished the operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 10^{12}

1 \leq A_i \leq 2 \times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_0 A_1 \cdots A_{N-1}

Output

Print the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in between.

Sample Input 1

3 2
1 2 3

Sample Output 1

2 3

In this case, X=(1,2,3,1,2,3).
We will perform the operations as follows:

i=0: s does not contain 1, so we add 1 to the end of s, resulting in s=(1).

i=1: s does not contain 2, so we add 2 to the end of s, resulting in s=(1,2).

i=2: s does not contain 3, so we add 3 to the end of s, resulting in s=(1,2,3).

i=3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1, which causes the following changes to s: (1,2,3)→(1,2)→(1)→().

i=4: s does not contain 2, so we add 2 to the end of s, resulting in s=(2).

i=5: s does not contain 3, so we add 3 to the end of s, resulting in s=(2,3).

Sample Input 2

5 10
1 2 3 2 3

Sample Output 2

3

Sample Input 3

6 1000000000000
1 1 2 2 3 3

Sample Output 3

s may be empty in the end.

Sample Input 4

11 97
3 1 4 1 5 9 2 6 5 3 5

Sample Output 4

9 2 6



Sample input:
3 2
1 2 3


Sample output:
2 3

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))

if n == 1:
    print(*(aaa * (k % 2)))
    exit()

follow = [-1] * n
tmp = {}
fix = 0
while True:
    for i in range(n):
        a = aaa[i]
        if a in tmp:
            follow[tmp[a]] = (i + 1) % n
            tmp[a] = i
            fix += 1
        else:
            tmp[a] = i
    if fix >= n:
        break
# print(follow)
loop = 0
i = 0
while True:
    j = follow[i]
    if i + 1 >= j:
        loop += 1
    # print(i, j, loop)
    if j == 0:
        break
    i = j

k %= loop
if k == 0:
    print()
    exit()


def simulate(aaa, s, follow):
    tmp = []
    exs = set()
    for a in aaa[s:]:
        if a in exs:
            while True:
                b = tmp.pop()
                exs.remove(b)
                if a == b:
                    break
        else:
            tmp.append(a)
            exs.add(a)

    # i = s
    # while i != 0:
    #     j = follow[i]
    #     if j == 0:
    #         if i == n - 1:
    #             tmp.append(aaa[i])
    #         break
    #     elif i + 1 >= j:
    #         tmp.append(aaa[i])
    #         i = (i + 1) % n
    #     else:
    #         i = j
    return tmp


i = 0
loop = 1
while loop <= k:
    j = follow[i]
    if i + 1 >= j:
        if loop == k:
            print(*simulate(aaa, i, follow))
            break
        loop += 1
    i = j

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, k = rli()
    la = rli()
    MOD = len(la)
    lb = [-1 for _ in range(len(la))]
    periods = dict()
    for i, a in enumerate(la):
        periods.setdefault(a, [])
        periods[a].append(i)
    for v in periods.values():
        for i, e in enumerate(v):
            if i == len(v)-1:
                lb[e] = (v[0] + 1) % MOD
            else:
                lb[e] = (v[i+1] + 1) % MOD
    loop = [0]
    b = 0
    while True:
        nb = lb[b]
        if nb == 0:
            break
        if nb-b <= 1:
            loop.append(nb)
        b = nb
    start = loop[(k-1)%len(loop)]

    counts = dict()
    for i, a in enumerate(la[start:]):
        periods.setdefault(a, [])
        counts.setdefault(a, 0)
        periods[a].append(i)
        counts[a] += 1

    ans = []
    target = None
    for a in la[start:]:
        if target is None:
            count = counts[a]
            if counts[a] >= 2:
                target = a
            else:
                ans.append(a)
        else:
            counts[a] -= 1
            if a == target:
                counts[a] -= 1
                target = None
    # print(la[start:])
    print(" ".join(map(str, ans)))
    # print(lb, loop)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_right
from collections import defaultdict
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))

N, K = inpl()
A = inpl()
places = defaultdict(list)
nextplace = [-1]*N
newloop = [-1]*N
for i in range(N):
    places[A[i]].append(i)
for i in range(N):
    pl = places[A[i]]
    k = bisect_right(pl,i)
    if k >= len(pl):
        nextplace[i] = (pl[0]+1)%N
        if nextplace[i] == 0:
            newloop[i] = 2
        else:
            newloop[i] = 1
    else:
        nextplace[i] = (pl[k]+1)%N
        if nextplace[i] == 0:
            newloop[i] = 1
        else:
            newloop[i] = 0

Nloop = 0
prev_loop = [-1]*N
j = 0
while prev_loop[j] < 0 and (Nloop+newloop[j] < K 
                          or (Nloop+newloop[j]==K and nextplace[j]==0) ):
    prev_loop[j] = Nloop
    Nloop += newloop[j]
    j = nextplace[j]
if Nloop == K:
    exit()
if prev_loop[j] >= 0:
    period = Nloop - prev_loop[j]
    Nloop = K - (K - Nloop) % period
    while Nloop+newloop[j] < K:
        Nloop += newloop[j]
        j = nextplace[j]

S = [0]*N
lenS = 0
XinS = defaultdict(lambda: -1)
for i in range(j,N):
    if XinS[A[i]] < 0:
        S[lenS] = A[i]
        XinS[A[i]] = lenS
        lenS += 1
    else:
        lenS = XinS[A[i]]
        XinS[A[i]] = -1
if lenS > 0:
    print(' '.join(map(str,S[:lenS])))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(input().split())
ans = A[:]
i=0
k_num = 1

Ans_list = [[]]

while 1:
    while i < len(ans)-1:
        head = ans[i]
        if head in ans[i+1:]:
            index_head = ans[i+1:].index(head) + i+1
            ans = ans[:i] + ans[index_head+1:]
        else:
            i+=1

    if ans not in Ans_list:
        Ans_list.append(ans)
        if k_num < K:
            ans = ans + A
            i=0
            k_num+=1
        elif k_num == K:
            print(*ans)
    else:
        break
#print(Ans_list)
print(*Ans_list[K%len(Ans_list)])

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(input().split())
l = []



tmp = []

T = 100000000000000000000000
h = 0
for i in range(K):
    if i!=0 and len(l[i-1]) !=0:
        h = A.index(l[i-1][0])
    for j in range(h,N):
        if A[j] not in tmp :
            tmp.append(A[j])

        else:
            index = len(tmp) - tmp[::-1].index(A[j]) -1
            del tmp[index:]

    tmp_copy = tmp.copy()
    l.append(tmp_copy)

    if l[i] in l[:i]:
        T = i
        break


ans = l[(K-1)%T]
print(' '.join(ans))

print(l)

Submission status: Wrong Answer

Solution code:
import sys
import collections
import copy
input = sys.stdin.readline
N,K = map(int,input().split())
A= list(int(i) for i in input().split())
chk = collections.Counter(A)
im_chk = copy.deepcopy(chk)
New_list=[]
ans_list = []
dup = 0
modul=1
for i in range(N*K):
	l = i%N
	if A[l] == dup:
		chk[A[l]] -= 1
		dup = 0
	elif dup == 0:
		if chk[A[l]] == 1:
			New_list.append(A[l])
		else:
			chk[A[l]] -=1
			dup = A[l]
	else:
		chk[A[l]] -= 1
	if l == N-1:
		if New_list == []:
			modul = (i+1)//N
			break
		else:
			ans_list.append(New_list)
			dup = New_list[0]
			chk = copy.deepcopy(im_chk)
			New_list = []
ans = K%modul
if ans == 0:
	print("")
else:
	print(*ans_list[ans-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

memo = {}
nxts = [None] * N
for i, x in enumerate(A + A):
  if x in memo:
    nxts[memo[x] % N] = i % N
  memo[x] = i

k = 0
visited = [-1] * N
p = 0
flag = False
ans = []
while k < K:
  if flag == False and visited[p] >= 0:
    k = visited[p] + ((K-1) - visited[p]) // (k - visited[p]) * (k - visited[p])
    flag = True
  visited[p] = k
  nxt = nxts[p]
  if k == K-1 and nxt <= p:
    ans.append(A[p])
    nxt = p + 1
    if nxt >= N:
      break
  else:
    nxt = (nxt + 1) % N
    if nxt <= p + 1:
      k += 1
  p = nxt
print(' ' .join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys

N, K, *A = map(int, sys.stdin.buffer.read().split())
b = [0] * N
d = dict()

for i, c in enumerate(A):
    if c in d.keys():
        if b[d[c]] == 0:
            for j in range(d[c], i + 1):
                b[j] = 1
        else:
            d[c] = i
    else:
        d[c] = i

x = []
for i, c in enumerate(A):
    if b[i] == 0:
        x.append(c)

if x:
    start = (K - 1) % len(x)
    print(*x[start:])
else:
    print()

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
follow = [-1] * n
tmp = {}
fix = 0
while True:
    for i in range(n):
        a = aaa[i]
        if a in tmp:
            follow[tmp[a]] = (i + 1) % n
            tmp[a] = i
            fix += 1
        else:
            tmp[a] = i
    if fix >= n:
        break
# print(follow)
loop = 0
i = 0
while True:
    j = follow[i]
    if i + 1 >= j:
        loop += 1
    # print(i, j, loop)
    if j == 0:
        break
    i = j

if loop == 1:
    k = 1
else:
    k %= loop
    if k == 0:
        print()
        exit()


def simulate(aaa, s, follow):
    tmp = []
    exs = set()
    for a in aaa[s:]:
        if a in exs:
            while True:
                b = tmp.pop()
                exs.remove(b)
                if a == b:
                    break
        else:
            tmp.append(a)
            exs.add(a)

    # i = s
    # while i != 0:
    #     j = follow[i]
    #     if j == 0:
    #         if i == n - 1:
    #             tmp.append(aaa[i])
    #         break
    #     elif i + 1 >= j:
    #         tmp.append(aaa[i])
    #         i = (i + 1) % n
    #     else:
    #         i = j
    return tmp


i = 0
loop = 1
while loop <= k:
    j = follow[i]
    if i + 1 >= j:
        if loop == k:
            print(*simulate(aaa, i, follow))
            break
        loop += 1
    i = j

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
a_list = list(map(int,input().split()))
s = []
# a_list2 = [i for i in a_list if a_list.count(i) % 2 != 0]

if k <= 20:
    for i in range(k):
        for a in a_list:
            if a in s:
                s = s[:s.index(a)]
            else:
                s.append(a)
else:
    for i in range(k - 12, k):
        for a in a_list:
            if a in s:
                s = s[:s.index(a)]
            else:
                s.append(a)
print(' '.join(map(str, s)))

Submission status: Wrong Answer

Solution code:
# import numpy as np
# np.set_printoptions(suppress=True)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N, K = LI()
    a_list = LI()

    pos_dict = {}
    for i, a in enumerate(a_list):
        if a not in pos_dict:
            pos_dict[a] = [i]
        else:
            pos_dict[a].append(i)

    from bisect import bisect_right

    # 開始のj
    head = 0
    irow = 0
    irowth_head = {}
    isloopstop = False

    while True:

        a = a_list[head]

        pos_list = pos_dict[a]
        # 次の位置
        idx = bisect_right(pos_list, head)


        if idx == len(pos_list):
            # これが末尾の場合、次の行の先頭へ
            # 次の行に行く前のこの行の last_head を記録
            irowth_head[irow] = head

            head = pos_list[0] + 1
            irow += 1


            # ループせず目的の行まで来たらいったんbreak
            if irow == K - 1:
                break

        else:
            # 同じ行の場合は続ける
            head = pos_list[idx] + 1


        # 次のheadが先頭の場合、ループするので break
        if head == len(a_list):
            isloopstop = True
            break

    # 最終行は真面目にやる
    # ループしてストップした場合は head を取り直す
    if isloopstop == True:
        nrow_loop = irow + 1
        kthrow_in_loop = (K-1) - nrow_loop * (K // nrow_loop)
        if kthrow_in_loop == - 1:
            # ちょうどループ末尾の場合は出力しない
            print('')
            return
        head = irowth_head[kthrow_in_loop]

    # head からスタートして末尾まで入れていく
    ans = []
    ans_dict = {}
    for i, j in enumerate(range(head, N)):
        a = a_list[j]
        if a not in ans_dict:
            ans.append(a_list[j])
            ans_dict[a] = i
        else:
            last = ans_dict[a]
            for k in ans[last:]:
                del ans_dict[k]
            ans = ans[:last]


    print(' '.join([str(a) for a in ans]))

solve()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    idx = [[] for _ in range(int(2e5+1))]
    for i in range(N):
        idx[A[i]].append(i)
    pos = 0
    empty = []
    visited = set()
    while pos == 0 or pos % N != 0:
        empty.append(pos)
        visited.add(pos % N)
        a = A[pos % N]
        nxt = bisect_right(idx[a], pos % N) % len(idx[a])
        npos = idx[a][nxt] + (pos//N) * N
        if npos <= pos:
            npos += N
        pos = npos + 1
    goal = N * K % pos
    cur = empty[max(0, bisect_right(empty, goal) - 1)]
    #print(cur, goal)
    ans = []
    seen = set()
    while cur < goal:
        i = cur % N
        a = A[i]
        nxt = bisect_right(idx[a], cur % N) % len(idx[a])
        ncur = idx[a][nxt] + (cur//N) * N
        if ncur <= cur:
            ncur += N
        if ncur <= goal:
            cur = ncur + 1
        else:
            ans += [a]
            cur = cur + 1
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())

X = list(map(int,input().split()))

mylist = X*2

s = []
for i in mylist:
    if i not in s:
        s += [i]
    else:
        s = s[:s.index(i)]
        
mystr = []
for i in s:
    mystr += str(i)
mystr = ' '.join(mystr)
print(mystr)

Submission status: Wrong Answer

Solution code:
n,k=map(int, raw_input().split())
a=map(int, raw_input().split())
s=[]

#for i in xrange(k):
i=0
while i < k:
#    print "i="+str(i)
    j=0
    while j < n:
#    for j in xrange(n):
#        print "j="+str(j)
        if a[j] in s:
            idx=s.index(a[j])
            s=s[0:idx]
        else:
            s.append(a[j])
        j+=1
#    print s
    if len(s)==0:
        i=(k+1)/(i+1)*(i+1)-1
    i+=1


print " ".join(map(str, s))

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
follow = [-1] * n
tmp = {}
fix = 0
while True:
    for i in range(n):
        a = aaa[i]
        if a in tmp:
            follow[tmp[a]] = (i + 1) % n
            tmp[a] = i
            fix += 1
        else:
            tmp[a] = i
    if fix >= n:
        break
# print(follow)
loop = 0
i = 0
while True:
    j = follow[i]
    if i + 1 >= j:
        loop += 1
    # print(i, j, loop)
    if j == 0:
        break
    i = j
k %= loop

if k == 0:
    print()
    exit()


def simulate(aaa, s, follow):
    tmp = []
    i = s
    while i != 0:
        j = follow[i]
        if j == 0:
            if i == n - 1:
                tmp.append(aaa[i])
            break
        elif i + 1 >= j:
            tmp.append(aaa[i])
            i = (i + 1) % n
        else:
            i = j
    return tmp


i = 0
loop = 1
while loop <= k:
    j = follow[i]
    if i + 1 >= j:
        if loop == k:
            print(*simulate(aaa, i, follow))
            break
        loop += 1
    i = j

Submission status: Wrong Answer

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # open(0).read() is a convenient method:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')

    # ----------------------------------
    # main

    N, K = R()
    A = R()
    X = A * 100 # enough??
    tmp = 0
    for i, a in enumerate(X):
        if a == tmp:
            tmp = 0
            if (i+1)%N == 0:
                turnaround = (i+1)//N
                K = K % turnaround
                X = A * K
                break
        elif tmp == 0:
            tmp = a
    
    Dic = defaultdict(int)
    i = 0
    ans = []
    for a in X:
        if a in Dic and i >= Dic[a]:
            i = Dic[a]
            if i == 0:
                ans = []
            else:
                ans = ans[:i]
        else:
            ans.append(a)
            Dic[a] = i
            i += 1
    print(*ans)
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # for
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()