n,k,*a=list(map(int,open(0).read().split()))

l,r,*b=[[]for _ in range(10**6)]

for i,v in enumerate(a):

  b[v]+=i,

  l+=len(b[v]),

s=a[0]

i=c=0

while i<n:

  j=l[i]%len(b[s])

  c+=j<1

  i=b[s][j]+1

  s=a[i%n]

k%=c+1

i=c=0

while i<n:

  j=l[i]%len(b[s])

  if(c>k-2)>j:

    r+=s,

    i+=1

  else:i=b[s][j]+1

  c+=j<1

  s=a[i%n]

print((*r))
n,k,*a=list(map(int,open(0).read().split()))

l,r,*b=[[]for _ in range(10**6)]

for i,v in enumerate(a):

  b[v]+=i,

  l+=len(b[v]),

s=a[0]

i=c=0

while 1:

  j=l[i]%len(b[s])

  if(c>k-2)>j:

    r+=s,

    i+=1

  else:i=b[s][j]+1

  c+=j<1

  if i==n:

    if c>k-2:break

    k%=c+1

    i=c=0

  s=a[i]

print((*r))
n, k, *a = list(map(int, open(0).read().split()))
l, r, *b = [[] for _ in range(10**6)]
for i, v in enumerate(a):
    b[v] += (i,)
    l += (len(b[v]),)
s = a[0]
i = c = 0
while i < n:
    j = l[i] % len(b[s])
    c += j < 1
    i = b[s][j] + 1
    s = a[i % n]
k %= c + 1
i = c = 0
while i < n:
    j = l[i] % len(b[s])
    if (c > k - 2) > j:
        r += (s,)
        i += 1
    else:
        i = b[s][j] + 1
    c += j < 1
    s = a[i % n]
print((*r))

n, k, *a = list(map(int, open(0).read().split()))
l, r, *b = [[] for _ in range(10**6)]
for i, v in enumerate(a):
    b[v] += (i,)
    l += (len(b[v]),)
s = a[0]
i = c = 0
while 1:
    j = l[i] % len(b[s])
    if (c > k - 2) > j:
        r += (s,)
        i += 1
    else:
        i = b[s][j] + 1
    c += j < 1
    if i == n:
        if c > k - 2:
            break
        k %= c + 1
        i = c = 0
    s = a[i]
print((*r))

-while i < n: -    j = l[i] % len(b[s]) -    c += j < 1 -    i = b[s][j] + 1 -    s = a[i % n] -k %= c + 1 -i = c = 0 -while i < n: +while 1: -    s = a[i % n] +    if i == n: +        if c > k - 2: +            break +        k %= c + 1 +        i = c = 0 +    s = a[i]