The only difference between easy and hard versions are constraints on $n$ and $k$.

You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $k$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $0$).

Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.

You (suddenly!) have the ability to see the future. You know that during the day you will receive $n$ messages, the $i$-th message will be received from the friend with ID $id_i$ ($1 \le id_i \le 10^9$).

If you receive a message from $id_i$ in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.

Otherwise (i.e. if there is no conversation with $id_i$ on the screen):  Firstly, if the number of conversations displayed on the screen is $k$, the last conversation (which has the position $k$) is removed from the screen.  Now the number of conversations on the screen is guaranteed to be less than $k$ and the conversation with the friend $id_i$ is not displayed on the screen.  The conversation with the friend $id_i$ appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. 

Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all $n$ messages.


-----Input-----

The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 200)$ — the number of messages and the number of conversations your smartphone can show.

The second line of the input contains $n$ integers $id_1, id_2, \dots, id_n$ ($1 \le id_i \le 10^9$), where $id_i$ is the ID of the friend which sends you the $i$-th message.


-----Output-----

In the first line of the output print one integer $m$ ($1 \le m \le min(n, k)$) — the number of conversations shown after receiving all $n$ messages.

In the second line print $m$ integers $ids_1, ids_2, \dots, ids_m$, where $ids_i$ should be equal to the ID of the friend corresponding to the conversation displayed on the position $i$ after receiving all $n$ messages.


-----Examples-----
Input
7 2
1 2 3 2 1 3 2

Output
2
2 1 

Input
10 4
2 3 3 1 1 2 1 2 3 3

Output
3
1 3 2 



-----Note-----

In the first example the list of conversations will change in the following way (in order from the first to last message):  $[]$;  $[1]$;  $[2, 1]$;  $[3, 2]$;  $[3, 2]$;  $[1, 3]$;  $[1, 3]$;  $[2, 1]$. 

In the second example the list of conversations will change in the following way:  $[]$;  $[2]$;  $[3, 2]$;  $[3, 2]$;  $[1, 3, 2]$;  and then the list will not change till the end.

Difficulty: EASY

Solutions:
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
p = []
for i in range(len(l)):
	if i == 0:
		p.append(l[0])
	else:
		if len(p) < k:
			if l[i] not in p:
				p.append(l[i])
		if len(p) == k:
			if l[i] not in p:
				p.pop(0)
				p.append(l[i])
print(len(p))
for i in p[::-1]:
	print(i, end=' ')


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
Res = []
for el in L:
	if el in Res[-1:-k - 1:-1]:
		continue
	Res.append(el)
Res = Res[-1:-k - 1:-1]
print(len(Res))
for x in Res:
	print(x, end=' ')
print()


(n, k) = map(int, input().split())
arr = map(int, input().split())
arr2 = []
for i in arr:
	if i in arr2:
		continue
	if len(arr2) >= k:
		arr2.pop()
	arr2.insert(0, i)
print(len(arr2))
print(*arr2)


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
A = []
a = 0
for i in x:
	if i not in A and a == k:
		A.pop(0)
		a -= 1
	if i not in A:
		A.append(i)
		a += 1
print(len(A))
A.reverse()
print(*A)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
b = []
for i in a:
	if i not in b:
		if cnt < k:
			b.append(i)
			cnt += 1
		else:
			b.remove(b[0])
			b.append(i)
b.reverse()
print(len(b))
for i in b:
	print(i, end=' ')


(m, s) = map(int, input().split())
arr = []
w = input().split()
i = 0
while i < m:
	if len(arr) == s:
		if w[i] not in arr:
			arr.insert(0, w[i])
			arr = arr[:-1]
	elif w[i] not in arr:
		arr.insert(0, w[i])
	i += 1
print(len(arr))
print(*arr)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = []
for i in range(n):
	if a[i] in l:
		continue
	else:
		if len(l) + 1 > k:
			l.pop()
		l.insert(0, a[i])
print(len(l))
print(*l)


(n, k) = input().split()
(n, k) = (int(n), int(k))
ID = [int(i) for i in input().split()]
from collections import deque
from itertools import islice
d = deque([], maxlen=k)
for i in ID:
	if i in islice(d, 0, k):
		pass
	else:
		d.appendleft(i)
print(len(d))
for i in islice(d, 0, k):
	print(i, end=' ')


from sys import stdin as cin
(n, k) = list(map(int, input().split()))
(b, b1, m) = ([], set(), 0)
while n - 1:
	n -= 1
	a = ''
	s = cin.read(1)
	while s != ' ':
		a += s
		s = cin.read(1)
	if a not in b1:
		b.append(a)
		b1.add(a)
		if len(b1) > k:
			b1.discard(b[m])
			m += 1
a = ''
s = cin.read(1)
o = set(map(str, range(10)))
while s in o:
	a += s
	s = cin.read(1)
if a not in b1:
	b.append(a)
	b1.add(a)
	if len(b1) > k:
		b1.discard(b[m])
		m += 1
print(len(b) - m)
print(*b[m:][::-1])


str0 = input().split()
n = int(str0[0])
k = int(str0[1])
screen = []
messages = input().split()
for id_ in messages:
	id_ = int(id_)
	if id_ not in screen[:k]:
		screen.insert(0, id_)
if len(screen) < k:
	print(len(screen))
else:
	print(k)
for i in range(k):
	try:
		print(screen[i], end=' ')
	except IndexError:
		pass


a = input()
a = a.split(' ')
n = int(a[0])
k = int(a[1])
b = input()
b = b.split(' ')
liste = []
for i in b:
	i = int(i)
	if i in liste:
		continue
	if len(liste) == k:
		liste.pop(0)
		liste.append(i)
		continue
	liste.append(i)
n = len(liste) - 1
print(len(liste))
while n >= 0:
	print(liste[n], end=' ')
	n -= 1


class uniset:

	def __init__(self, k):
		self.k = k
		self.eles = []
		self.has = {}

	def add(self, v):
		if v in self.has:
			return
		if len(self.eles) == self.k:
			e = self.eles.pop(0)
			self.has.pop(e)
		self.has[v] = 1
		self.eles.append(v)

	def print(self):
		self.eles.reverse()
		print(len(self.eles))
		for e in self.eles:
			print(e, end=' ')
(n, k) = (int(i) for i in input().split(' '))
ids = input().split(' ')
us = uniset(k)
for i in ids:
	us.add(i)
us.print()


(n, k) = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
a = [0] * n
p = 0
for i in range(n):
	if x[i] not in a:
		if p < k:
			p += 1
		a.insert(0, x[i])
		a = a[:k]
print(p)
for i in range(p):
	if i == p - 1:
		print(a[i])
	else:
		print(a[i], end=' ')


(n, k) = map(int, input().split())
no = list(map(int, input().split()))
out = []
for i in range(len(no)):
	if no[i] not in out:
		out.insert(0, no[i])
	if len(out) > k:
		del out[-1]
print(len(out))
for i in out:
	print(i, end=' ')


a = list(map(int, input().split()))
sc = a[1]
m = a[0]
a = list(map(int, input().split()))
d = {}
s = []
for i in a:
	if i in d:
		continue
	if len(s) < sc:
		s.append(i)
		d[i] = 1
	else:
		d.pop(s.pop(0))
		s.append(i)
		d[i] = 1
print(len(s))
print(*s[::-1])


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
curr = []
for i in l:
	if i in curr:
		pass
	elif len(curr) == k:
		curr.pop()
		curr.insert(0, i)
	else:
		curr.insert(0, i)
print(len(curr))
print(*curr)


(n, k) = input().split()
x = input().split()
l = [0 for i in range(int(k))]
for i in x:
	if not int(i) in l:
		l.insert(0, int(i))
		l.pop()
if 0 in l:
	print(l.index(0))
else:
	print(int(k))
if 0 in l:
	for i in l[0:l.index(0)]:
		print(int(i), end=' ')
	print()
else:
	for i in l:
		print(int(i), end=' ')
	print()


import sys
import math
from collections import deque
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass

def takeInput():
	return [int(x) for x in input().strip().split()]
(n, k) = takeInput()
friends = takeInput()
phone = deque()
msgs = 0
display = set()
for f in friends:
	if f not in display:
		if msgs < k:
			display.add(f)
			msgs += 1
			phone.appendleft(f)
		elif msgs == k:
			display.remove(phone.pop())
			phone.appendleft(f)
			display.add(f)
print(len(phone))
print(*phone)


(n, k) = list(map(int, input().split(' ')))
messages = list(map(int, input().split(' ')))
display = []
for num in messages:
	if str(num) not in display:
		if len(display) < k:
			display.insert(0, str(num))
		else:
			display.pop()
			display.insert(0, str(num))
	else:
		continue
show = ' '.join(display)
print(len(display))
print(show)


import sys
from collections import deque, defaultdict
(n, k) = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
dq = deque()
on_dq = defaultdict(int)
length = 0
for ele in a:
	if not on_dq[ele]:
		on_dq[ele] = 1
		length += 1
		dq.appendleft(ele)
		if length > k:
			item = dq.pop()
			on_dq[item] = 0
			length -= 1
print(length)
print(*dq)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
res = []
for i in range(n):
	if a[i] not in res:
		if len(res) < k:
			res = [a[i]] + res
		else:
			res = [a[i]] + res[:len(res) - 1]
print(len(res))
print(*res)


li = list(map(int, input().split(' ')))
n = li[0]
k = li[1]
li = list(map(int, input().split(' ')))
lio = []
for i in range(0, len(li)):
	if len(lio) == 0:
		lio.append(li[i])
	elif len(lio) < k:
		if li[i] in lio:
			continue
		else:
			lio.insert(0, li[i])
	elif li[i] in lio:
		continue
	else:
		lio.remove(lio[-1])
		lio.insert(0, li[i])
print(len(lio))
for x in lio:
	print(x, end=' ')


(n, k) = map(int, input().split())
ids = input().split()
mess = [0] * k
for i in ids:
	if i not in mess:
		mess.append(i)
		mess.pop(0)
kk = k - mess.count(0)
print(kk)
mess.reverse()
print(' '.join(mess[:kk]))


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = []
for i in l:
	if i in ans:
		continue
	elif len(ans) < k:
		ans.insert(0, i)
	else:
		ans.pop()
		ans.insert(0, i)
print(min(min(n, k), len(ans)))
for i in ans:
	print(i, end=' ')


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
ans = []
for i in range(n):
	if lis[i] not in ans:
		ans.append(lis[i])
		if len(ans) > k:
			ans.pop(0)
print(len(ans))
print(*ans[::-1])


import math
from math import gcd
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_input = lambda : map(int, stdin.readline().split())
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
(n, k) = multi_input()
id = list_input()
final_list = []
for i in id:
	if i not in final_list and len(final_list) < k:
		final_list = [i] + final_list
	elif i not in final_list and len(final_list) == k:
		final_list.pop(-1)
		final_list = [i] + final_list
print(len(final_list))
print(*final_list)


(n, k) = input().split()
l = input().split()
l2 = []
for i in l:
	if i not in l2 and len(l2) < int(k):
		l2.insert(0, i)
	elif i not in l2 and len(l2) == int(k):
		l2.insert(0, i)
		l2.pop()
print(len(l2))
print(' '.join(l2))


from collections import defaultdict
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = [0] * (n + 1)
d = set()
c = 0
r = 0
x = 0
for i in range(n):
	if a[i] in d:
		pass
	else:
		l[x] = a[i]
		x += 1
		c += 1
		d.add(a[i])
	if c > k:
		c -= 1
		d.remove(l[r])
		r += 1
print(c)
for i in range(x - 1, x - 1 - min(c, k), -1):
	print(l[i], end=' ')


import heapq
import math
import sys
input = sys.stdin.readline

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def value():
	return int(input())
(n, k) = li()
a = li()
curr = []
currd = {}
currd2 = {}
for i in range(n):
	if a[i] not in currd2:
		if len(curr) == k:
			currd2.pop(currd.pop(heapq.heappop(curr)))
		heapq.heappush(curr, i)
		currd[i] = a[i]
		currd2[a[i]] = i
curr.sort(reverse=1)
ans = []
for i in curr:
	ans.append(currd[i])
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
arr = map(int, input().split())
lis = []
for i in arr:
	if i not in lis:
		lis.insert(0, i)
		if len(lis) == k + 1:
			lis.pop()
print(len(lis))
print(*lis)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = []
for i in range(n):
	if len(a) < k:
		if l[i] in a:
			pass
		else:
			a.insert(0, l[i])
	elif l[i] in a:
		pass
	else:
		a.pop()
		a.insert(0, l[i])
print(len(a))
print(*a)


from sys import stdin

def main():
	(nt, kt) = map(int, input().split())
	A = list(map(int, input().split()))
	u = set(A)
	d1 = {}
	d2 = {}
	indx = 0
	for i in u:
		d1[indx] = i
		d2[i] = indx
		indx += 1
	rt = []
	cn = 0
	p = [0] * len(u)
	for i in A:
		if cn == kt:
			if p[d2[i]] == 0:
				p[d2[i]] = 1
				x = rt.pop()
				p[d2[x]] = 0
				rt.insert(0, i)
		elif p[d2[i]] == 0:
			p[d2[i]] = 1
			rt.insert(0, i)
			cn += 1
	print(len(rt))
	print(*rt)
main()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
l = [] * k
for i in arr:
	if i not in l:
		l.insert(0, i)
	if len(l) > k:
		l.pop()
print(len(l))
print(*l)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = []
for i in l:
	if len(a) < k:
		if i not in a:
			a.insert(0, i)
	elif len(a) == k:
		if i in a:
			pass
		elif i not in a:
			a.pop(k - 1)
			a.insert(0, i)
print(len(a))
print(*a, sep=' ')


(n, k) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
curr = []
for i in a:
	if i in curr:
		continue
	elif len(curr) >= k:
		curr.pop()
		curr.insert(0, i)
	else:
		curr.insert(0, i)
print(len(curr))
for i in curr:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
	if a[i] in b:
		continue
	elif len(b) < k:
		b = [a[i]] + b
	else:
		b = [a[i]] + b[:len(b) - 1]
print(len(b))
print(*b)


(n, k) = map(int, input().split())
messages = list(map(int, input().split()))
stack = []
for i in messages:
	if i not in stack and len(stack) < k:
		stack.insert(0, i)
	elif i not in stack and len(stack) == k:
		del stack[-1]
		stack.insert(0, i)
	else:
		pass
print(len(stack))
print(*stack)


(n, k) = list(map(int, input().split()))
id = list(map(int, input().split()))
vet = []
for i in id:
	if i not in vet[:k]:
		vet.insert(0, i)
print(len(vet[:k]))
print(*vet[:k])


def main():
	(N, K) = (int(i) for i in input().split())
	D = [int(i) for i in input().split()]
	from collections import deque
	screen = deque()
	screen_set = set()
	for d in D:
		if d in screen_set:
			continue
		if K == len(screen):
			bye = screen.pop()
			screen_set.discard(bye)
		screen.appendleft(d)
		screen_set.add(d)
	print(len(screen))
	print(*screen)
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = []
for i in range(len(a)):
	if len(s) == 0:
		s.append(a[i])
	elif len(s) < k:
		if a[i] not in s:
			s.insert(0, a[i])
	elif len(s) == k:
		if a[i] not in s:
			s.remove(s[-1])
			s.insert(0, a[i])
print(len(s))
for i in range(len(s)):
	print(s[i], end=' ')


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = deque()
s = set()
for i in range(n):
	if a[i] not in s:
		q.appendleft(a[i])
		s.add(a[i])
		if len(q) > k:
			x = q.pop()
			s.discard(x)
print(len(q))
print(*q)


def solve(n, k, msgs):
	sc_dic = {}
	sc = []
	for m in msgs:
		if m not in sc_dic:
			sc_dic[m] = 1
			sc.append(m)
		if len(sc) > k:
			sc_dic.pop(sc.pop(0))
	sc = sc[::-1]
	print(len(sc))
	for a in sc:
		print(a, end=' ')

def main():
	(n, k) = map(int, input().split())
	msgs = list(map(int, input().split()))
	solve(n, k, msgs)
main()


(n, k) = map(int, input().split())
msgs = map(int, input().split())
screen_msg = []
screen_msg_dict = dict()
for msg in msgs:
	if screen_msg_dict.get(msg, 0) == 0:
		screen_msg.append(msg)
		screen_msg_dict[msg] = 1
	if len(screen_msg) > k:
		screen_msg_dict.pop(screen_msg.pop(0))
print(len(screen_msg))
print(*screen_msg[::-1])


from collections import deque
(n, k) = list(map(int, input().split()))
lst = list(map(int, input().split()))
q = deque()
for i in range(n):
	if lst[i] not in q:
		if len(q) == k:
			q.popleft()
			q.append(lst[i])
		else:
			q.append(lst[i])
res = []
num = len(q)
print(num)
q.reverse()
print(' '.join(map(str, q)))


import queue
D = dict()
(N, K) = map(int, input().split())
arr = list(map(int, input().split()))
Q = queue.Queue(maxsize=K + 1)
size_of_Q = 0
for i in range(N):
	if arr[i] not in D:
		D[arr[i]] = 1
		Q.put(arr[i])
		size_of_Q += 1
		if size_of_Q > K:
			D[Q.get()] = 0
			size_of_Q -= 1
	elif D[arr[i]] == 0:
		D[arr[i]] = 1
		Q.put(arr[i])
		size_of_Q += 1
		if size_of_Q > K:
			D[Q.get()] = 0
			size_of_Q -= 1
ans = [Q.get() for i in range(size_of_Q)]
ans = list(reversed(ans))
print(size_of_Q)
print(' '.join(list(map(str, ans))))


from collections import deque
import sys
import heapq

def inp():
	return sys.stdin.readline().strip()
(n, k) = map(int, inp().split())
a = list(map(int, inp().split()))
mintime = 1
cache = {}
inverse = {}
time = 1
for i in a:
	if i in cache:
		continue
	cache[i] = time
	inverse[time] = i
	time += 1
	k -= 1
	while k < 0:
		if mintime not in inverse:
			mintime += 1
			continue
		if cache[inverse[mintime]] == mintime:
			k += 1
			j = inverse[mintime]
			del inverse[mintime]
			del cache[j]
		else:
			del inverse[mintime]
		mintime += 1
res = []
for i in range(mintime, time + 1):
	if i in inverse:
		if cache[inverse[i]] == i:
			res.append((i, inverse[i]))
res.sort()
res = [i[1] for i in res]
res = res[::-1]
print(len(res))
print(*res)


import heapq

def read_str():
	return list(map(int, input().split(' ')))
(n, k) = read_str()
id = read_str()
screen = set()
li = []
heapq.heapify(li)
for i in range(n):
	if id[i] not in screen:
		screen.add(id[i])
		heapq.heappush(li, i)
	if len(li) > k:
		j = heapq.heappop(li)
		screen.remove(id[j])
print(len(li))
print(*[id[heapq.heappop(li)] for _ in range(len(li))][::-1])


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
ans = []
for id in ids:
	if id not in ans:
		ans.insert(0, id)
		if len(ans) > k:
			ans.pop()
print(len(ans))
print(*ans)


(inps, box) = input().split()
inps = int(inps)
box = int(box)
ms = [int(x) for x in input().split()]
outs = []
store = {}
for i in ms:
	if store.get(i) == None:
		store.update({i: 1})
		outs.insert(0, i)
	elif store.get(i) == 0:
		store[i] = 1
		outs.insert(0, i)
	if len(outs) > box:
		store[outs.pop(-1)] = 0
print(len(outs))
for i in outs:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sol = []
for i in range(len(a)):
	if not a[i] in sol:
		sol.insert(0, a[i])
	if len(sol) > k:
		sol.pop()
print(len(sol))
for i in range(len(sol)):
	print(sol[i], end=' ')


import sys
from collections import deque

def rint():
	return map(int, sys.stdin.readline().split())
(n, k) = rint()
ids = list(rint())
q = deque()
id_dict = dict()
for i in range(n):
	id = ids[i]
	if id in id_dict:
		if id_dict[id] > 0:
			continue
	else:
		id_dict[id] = 0
	id_dict[id] += 1
	if len(q) >= k:
		tmp = q.pop()
		id_dict[tmp] -= 1
	q.appendleft(id)
lq = list(q)
print(len(lq))
print(*lq)


from sys import stdin
from collections import deque

def main():
	(n, k) = list(map(int, stdin.readline().strip().split()))
	nums = list(map(int, stdin.readline().strip().split()))
	queue = deque()
	onScreen = set()
	for num in nums:
		if num not in onScreen:
			if len(queue) == k:
				onScreen.remove(queue.popleft())
				queue.append(num)
				onScreen.add(num)
			else:
				onScreen.add(num)
				queue.append(num)
	print(len(queue))
	queue.reverse()
	print(*queue)
main()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = i = 0
li = []
s = set()
for i in range(n):
	if l[i] in s:
		continue
	if m == k:
		s.discard(li.pop(0))
		m -= 1
	li.append(l[i])
	s.add(l[i])
	m += 1
print(m)
li.reverse()
print(*li)


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
K = []
for i in range(n):
	if K.count(L[i]) == 0:
		K.insert(0, L[i])
		if len(K) > k:
			K.pop()
		else:
			pass
	else:
		pass
print(len(K))
for item in K:
	print(item, end=' ')


a = input().split()
arr = input().split()
n = int(a[0])
k = int(a[1])
res = []
for i in range(n):
	x = arr[i]
	if x not in res:
		if len(res) >= k:
			res.pop(0)
		res.append(x)
print(len(res))
print(*res[::-1])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
(li, m) = ([], 0)
for item in l:
	if item in li:
		continue
	if m == k:
		li.pop()
		m -= 1
	li.insert(0, item)
	m += 1
print(m)
print(*li)


def messaging(n, k, A):
	res = []
	res.append(A[0])
	for i in range(1, len(A)):
		if A[i] not in res:
			if len(res) != k:
				res.insert(0, A[i])
			else:
				res.insert(0, A[i])
				res.pop(-1)
	print(len(res))
	for i in res:
		print(i, end=' ')
(n, k) = list(map(int, input().strip().split()))
message = list(map(int, input().strip().split()))
messaging(n, k, message)


import sys
sys.setrecursionlimit(10000000)

def input():
	return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
import itertools
import math
INF = 10 ** 9
MOD = 10 ** 9 + 7
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
dq = deque()
s = set()
for x in a:
	if not x in s:
		s.add(x)
		dq.appendleft(x)
		if len(dq) > k:
			s.remove(dq[-1])
			dq.pop()
print(len(dq))
print(*dq)


import math
(n, k) = map(int, input().split())
messages = [int(x) for x in input().split()]
q = []
qs = set()
for m in messages:
	if m not in qs:
		if len(q) == k:
			qs.remove(q[0])
			q.pop(0)
		qs.add(m)
		q.append(m)
print(len(q))
print(*q[::-1])


(x, y) = map(int, input().split())
k = list(map(int, input().split()))
q = []
m = min(x, y)
for i in k:
	if len(q) < m:
		if i in q:
			continue
		else:
			q.insert(0, i)
	elif len(q) == m:
		if i in q:
			continue
		else:
			q.remove(q[-1])
			q.insert(0, i)
print(len(q))
print(*q)


(n, k) = list(map(int, input().split(' ')))
a = list(map(lambda x: x, input().split(' ')))
tmp = []
last = []
for i in a:
	if i in tmp:
		continue
	if len(tmp) < k:
		tmp.insert(0, i)
	else:
		tmp.insert(0, i)
		tmp = tmp[:k]
print(len(tmp))
print(' '.join(tmp))


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
ans = []
ans.append(p[0])
for i in range(1, n):
	if len(ans) < k and p[i] not in ans:
		ans.insert(0, p[i])
	elif len(ans) == k and p[i] not in ans:
		ans[1:] = ans[:-1]
		ans[0] = p[i]
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
from collections import *
queue = deque()
curSet = set()
for a in A:
	if a in curSet:
		continue
	if len(curSet) == k:
		curSet.remove(queue[-1])
		queue.pop()
	curSet.add(a)
	queue.appendleft(a)
print(len(queue))
queue = list(map(str, queue))
print(' '.join(queue))


(n, k) = (int(x) for x in input().split())
msg = [int(x) for x in input().split()]
stk = []
for m in msg:
	if m in stk:
		continue
	stk.insert(0, m)
	while len(stk) > k:
		stk.pop()
print(len(stk))
for i in stk:
	print(i, end=' ')
print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in a:
	if i not in b:
		b.insert(0, i)
	if len(b) > k:
		b.pop()
print(len(b))
print(*b)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		r = []
		s = set()
		for c in a:
			if c in s:
				continue
			if len(s) == k:
				s.remove(r[-1])
				r = [c] + r[:-1]
			else:
				r = [c] + r
			s.add(c)
		rr.append(len(r))
		rr.append(JA(r, ' '))
	return JA(rr, '\n')
print(main())


import math
(n, k) = [int(x) for x in input().split()]
i = [int(x) for x in input().split()]
o = []
for x in range(n):
	if i[x] not in o:
		if len(o) == 0:
			o.append(i[x])
		else:
			o.insert(0, i[x])
	if len(o) > k:
		del o[-1]
print(len(o))
for i in o:
	print(i, end=' ')


(m, n) = map(int, input().split())
(*a,) = map(int, input().split())
bb = []
for x in a:
	if x not in bb:
		if len(bb) == n:
			bb.pop()
		bb.insert(0, x)
print(len(bb))
print(*bb)


(n, k) = [int(x) for x in input().split()]
ms = [int(x) for x in input().split()]
s = []
for m in ms:
	if m not in s[-k:]:
		s.append(m)
print(min(k, len(s)))
print(*reversed(s[-k:]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
i = 0
r = []
for t in a:
	if len(d) == k and t not in d:
		d.pop(r.pop(0))
		d[t] = i
		r.append(t)
		i -= 1
	elif t in d:
		pass
	else:
		d[t] = i
		i -= 1
		r.append(t)
print(len(d))
y = sorted(d.items(), key=lambda kv: (kv[1], kv[0]))
for i in y:
	print(i[0], end=' ')


class Qu:

	def __init__(self, ss):
		self.items = []
		self.ss = ss

	def isEmpty(self):
		return self.items == []

	def enqueue(self, item):
		if item in self.items:
			pass
		elif len(self.items) < self.ss:
			self.items.insert(0, item)
		else:
			self.dequeue()
			self.items.insert(0, item)

	def dequeue(self):
		return self.items.pop()

	def size(self):
		return len(self.items)

	def view(self):
		sa = [str(_s) for _s in self.items]
		print(' '.join(sa))
(n, k) = map(int, input().split())
x = [int(_) for _ in input().split()]
q = Qu(k)
for i in x:
	q.enqueue(i)
print(q.size())
q.view()


from collections import deque
(n, k) = [int(x) for x in input().split()]
msg = input().split()
resp = deque([])
oi = set([])
for e in msg:
	if e not in oi:
		resp.append(e)
		oi.add(e)
		if len(resp) > k:
			oi.discard(resp.popleft())
print(len(resp))
resp.reverse()
print(' '.join(resp))


import collections
(n, k) = map(int, input().split())
ls = [int(x) for x in input().split()]
d = {}
a = collections.deque([])
c = 0
for i in range(n):
	d[ls[i]] = 0
for j in range(n):
	i = ls[j]
	if d[i] == 0:
		if c == k:
			x = a.popleft()
			d[x] = 0
			c -= 1
		a.append(i)
		c += 1
		d[i] = 1
print(c)
for i in range(c - 1, -1, -1):
	print(a[i], end=' ')


(n, k) = tuple([int(i) for i in input().split()])
ids = input().split()
res = []
for i in ids:
	if i not in res:
		res.insert(0, i)
	if len(res) > k:
		res.pop(-1)
print(len(res))
print(' '.join(res))


import heapq

def order_of_contacts(k, ids_arr):
	time = 0
	contacts = set()
	times = []
	for id in ids_arr:
		if id not in contacts:
			if len(contacts) == k:
				min_time_id = heapq.heappop(times)
				contacts.remove(min_time_id[1])
			contacts.add(id)
			heapq.heappush(times, (time, id))
			time += 1
	print(len(contacts))
	ids_str = ''
	while times:
		min_time_id = heapq.heappop(times)
		ids_str = str(min_time_id[1]) + ' ' + ids_str
	return ids_str[:-1]

def get_input(flag=0):
	if flag:
		return int(input())
	return [int(i) for i in input().split()]
(n, k) = get_input()
arr = get_input()
print(order_of_contacts(k, arr))


(n, k) = map(int, input().split())
ans = [0] * k
ids = list(map(int, input().split()))
for i in ids:
	if i not in ans:
		ans = [i] + ans
	ans = ans[:k]
while ans[-1] == 0:
	ans.remove(ans[-1])
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
a = []
b = list(map(int, input().split()))
for i in range(n):
	if len(a) < k and b[i] not in a:
		a.insert(0, b[i])
	if b[i] in a:
		pass
	if len(a) == k and b[i] not in a:
		a.pop()
		a.insert(0, b[i])
print(len(a))
print(' '.join(map(str, a)))


import math
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
p = [l[0]]
c = 1
for i in range(1, n):
	if c < k and l[i] not in p:
		c += 1
		p.insert(0, l[i])
	elif l[i] not in p:
		p.pop()
		p.insert(0, l[i])
print(min(k, c))
print(*p)


(n, k) = map(int, input().split())
id = list(map(int, input().split()))
d = {}
for i in id:
	d[i] = 0
lis = []
for i in id:
	if d[i] == 0:
		if len(lis) == k:
			d[lis.pop(-1)] = 0
			lis.insert(0, i)
			d[i] = 1
		else:
			lis.insert(0, i)
			d[i] = 1
print(len(lis))
print(*lis)


(n, k) = [int(i) for i in input().split(' ')]
arr = [int(i) for i in input().split(' ')]
disSet = set()
display = []
count = 0
for a in arr:
	if a not in disSet:
		disSet.add(a)
		display.insert(0, a)
		if len(display) > k:
			disSet.remove(display[-1])
			del display[-1]
print(len(display))
for i in display:
	print(i, end=' ')


(n, k) = map(int, input().split())
ida = list(map(int, input().split()))
ans = []
search = set()
for i in range(n):
	if ida[i] not in search:
		if len(ans) == k:
			t = ans.pop(0)
			ans.append(ida[i])
			search.remove(t)
			search.add(ida[i])
		elif len(ans) < k:
			ans.append(ida[i])
			search.add(ida[i])
print(len(ans))
ans = ans[::-1]
print(*ans)


(n, k) = map(int, input().split())
all = [int(i) for i in input().split()]
a = []
for i in all:
	if len(a) <= k:
		if i not in a and len(a) < k:
			a.insert(0, i)
		elif i not in a and len(a) == k:
			a.insert(0, i)
			a.pop()
print(len(a))
for i in a:
	print(i, end=' ')


from sys import stdin
(n, k) = map(int, stdin.readline().split())
l = list(map(int, stdin.readline().split()))
from collections import deque
count = 0
from collections import defaultdict
vis = defaultdict(int)
ans = []
ans = deque(ans)
for i in range(n):
	if count < k:
		if vis[l[i]] == 0:
			ans.append(l[i])
			vis[l[i]] = 1
			count += 1
	elif vis[l[i]] == 0:
		a = ans.popleft()
		vis[a] = 0
		ans.append(l[i])
		vis[l[i]] = 1
ans.reverse()
print(count)
print(*ans)


(n, k) = list(map(int, input().split()))
ls = []
messages = list(map(int, input().split()))
for i in messages:
	if i in ls:
		continue
	else:
		ls.insert(0, i)
		if len(ls) > k:
			ls = ls[:k]
print(len(ls))
print(*ls, sep=' ')


import collections
(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
de = collections.deque([])
for i in ids:
	if i not in de:
		if len(de) == k:
			de.pop()
			de.appendleft(i)
		else:
			de.appendleft(i)
print(len(de))
l = list(de)
print(*l)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {}
b = []
l = 0
for x in a:
	d[x] = d.get(x, True)
	if d[x]:
		d[x] = False
		b.append(x)
		l += 1
		if l > k:
			d[b[l - k - 1]] = True
print(min(l, k))
if l > k:
	print(*b[l - k:][::-1])
else:
	print(*b[::-1])


(n, k) = map(int, input().split())
calls = list(map(int, input().split()))
rec = set()
newlist = []
j = 0
for i in calls:
	if i not in rec:
		rec.add(i)
		newlist += [i]
		if len(newlist) > k:
			rec -= {newlist[j]}
			j += 1
print(len(newlist) - j)
print(*reversed(newlist[j:]))


I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
(n, m) = M()
a = LI()
d = [0] * min(n, m)
b = min(len(set(a)), n, m)
ans = 0
for i in range(n):
	if a[i] not in d:
		d.insert(0, a[i])
		d = d[0:m]
print(b)
print(*d[0:b])


import sys

def main():

	def input():
		return sys.stdin.readline()[:-1]
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = []
	for e in a:
		if len(l) == k:
			if e not in l:
				l = [e] + l[:-1]
			else:
				pass
		elif e not in l:
			l = [e] + l
		else:
			pass
	print(len(l))
	print(*l, sep=' ')

def __starting_point():
	main()
__starting_point()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k) = value()
a = array()
inStack = defaultdict(bool)
stack = []
for i in range(n):
	if not inStack[a[i]]:
		if len(stack) < k:
			stack.append(a[i])
			inStack[a[i]] = True
		else:
			X = stack.pop(0)
			inStack[X] = False
			inStack[a[i]] = True
			stack.append(a[i])
print(len(stack))
print(*stack[::-1])


(n, k) = map(int, input().split())
a = input().split()
r = []
for i in a:
	if i not in r[-k:]:
		r.append(i)
print(min(len(r), k))
print(' '.join(reversed(r[-k:])))


from queue import Queue

def main():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	checked = {}
	for a in A:
		checked[a] = False
	q = Queue()
	for (i, a) in enumerate(A):
		if checked[a]:
			continue
		else:
			checked[a] = True
			q.put(a)
			if q.qsize() > K:
				b = q.get()
				checked[b] = False
	L = q.qsize()
	ans = []
	for i in range(L):
		a = q.get()
		ans.append(a)
	print(L)
	print(' '.join([str(a) for a in ans[::-1]]))
main()


(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
a = list(map(int, input().strip().split(' ')))
cnt = 0
d = {}
ans = []
for i in a:
	if cnt < k and i not in d:
		ans.append(i)
		cnt += 1
		d[i] = 1
	elif cnt == k and i not in d:
		del d[ans[0]]
		ans = ans[1:]
		ans.append(i)
		d[i] = 1
print(cnt)
for i in range(cnt - 1, -1, -1):
	print(ans[i], end=' ')
print()


from collections import *
(n, k) = map(int, input().split())
(*a,) = map(int, input().split())
d = deque()
sein = defaultdict(int)
for i in a:
	if not sein[i]:
		sein[i] = 1
		d.appendleft(i)
		if len(d) > k:
			sein[d.pop()] = 0
print(len(d))
print(*d)


a = list(map(int, input().split()))
l = []
for i in range(a[1]):
	l.append(0)
a = list(map(int, input().split()))
for i in a:
	if l.count(i) == 0:
		l.insert(0, i)
		l.pop()
a = l.count(0)
for i in range(a):
	l.pop()
print(len(l))
print(*l)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = dict()
ids = []
count = 0
for i in l:
	if count < k:
		if i in d:
			continue
		else:
			d[i] = True
			ids.append(i)
			count += 1
	elif count == k:
		if i in d:
			continue
		elif i not in d:
			d[i] = True
			ids.append(i)
			z = ids.pop(0)
			del d[z]
ids = ids[::-1]
print(count)
for j in ids:
	print(j, end=' ')


(nMes, kConv) = map(int, input().split())
idF = list(map(int, input().split()))
fila = []
tamanhoFila = 0
for e in idF:
	if e not in fila and tamanhoFila < kConv:
		fila.insert(0, e)
		tamanhoFila += 1
	elif e not in fila and tamanhoFila == kConv:
		fila.pop()
		fila.insert(0, e)
print(len(fila))
print(*fila)


(N, K) = [*map(int, input().split(' '))]
IDs = input().split(' ')
screen = [] * K
for i in IDs:
	if i not in screen:
		screen.insert(0, i)
		if len(screen) > K:
			screen.pop()
print(len(screen))
print(' '.join(screen))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = []
for i in range(n):
	if a[i] in l:
		pass
	else:
		l.reverse()
		l.append(a[i])
		if len(l) > k:
			l.remove(l[0])
		l.reverse()
print(len(l))
for i in range(len(l)):
	print(l[i], end=' ')
print()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l2 = list()
for i in l:
	if i not in l2:
		if len(l2) == k:
			l2.remove(l2[0])
		l2.append(i)
print(len(l2))
for i in range(len(l2) - 1, -1, -1):
	print(l2[i], end=' ')
print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = 0
c = []
s = set()
for i in range(n):
	if a[i] not in s:
		s.add(a[i])
		c.append(a[i])
		if len(s) > k:
			s -= {c[m]}
			m += 1
print(len(c) - m)
print(*reversed(c[m:]))


(n, k) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
if k <= len(set(l)):
	print(k)
else:
	print(len(set(l)))
l1 = []
for i in l:
	if len(l1) <= k:
		if i in l1:
			pass
		elif len(l1) < k:
			l1.append(i)
		else:
			l1.append(i)
			l1.pop(0)
	elif i in l1:
		l1.pop(0)
	else:
		l1.append(i)
		l1.pop(0)
		l1.pop(0)
l1.reverse()
for i in l1:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
h = {}
ans = []
for i in range(n):
	if a[i] not in h:
		if len(ans) < k:
			ans.insert(0, a[i])
			h[a[i]] = 1
		else:
			del h[ans[-1]]
			del ans[-1]
			ans.insert(0, a[i])
			h[a[i]] = 1
print(len(ans))
print(*ans)


from math import *
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y, z) = mi()
		if x not in d:
			d[x] = [[z, y]]
		else:
			d[x].append([z, y])
		if y not in d:
			d[y] = [[z, x]]
		else:
			d[y].append([z, x])
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')
(n, k) = mi()
l = li()
a = []
for i in range(n):
	if len(a) == k:
		if l[i] not in a:
			a.pop(-1)
			a.insert(0, l[i])
	elif len(a) < k:
		if l[i] not in a:
			a.insert(0, l[i])
print(len(a))
print(' '.join(map(str, a)))


s = input('')
(n, k) = (int(x) for x in s.split())
s = input('')
l1 = [int(x) for x in s.split()]
l2 = []
for i in l1:
	if i not in l2:
		if len(l2) >= k:
			l2.pop()
		l2.insert(0, i)
print(len(l2))
for i in l2:
	print(i, end=' ')


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
(n, k) = arrIN()
a = arrIN()
st = []
ls = 0
f = defaultdict(int)
j = 0
for i in a:
	if f[i] == 0:
		if ls < k:
			st.append(i)
			f[i] = 1
			ls += 1
		else:
			f[st[j]] = 0
			j += 1
			st.append(i)
			f[i] = 1
print(len(st) - j)
for i in range(len(st) - 1, j - 1, -1):
	print(st[i], end=' ')


import math
(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
message = []
for i in range(n):
	if A[i] in message:
		continue
	elif len(message) == k:
		message.pop()
		message.insert(0, A[i])
	else:
		message.insert(0, A[i])
print(len(message))
for i in message:
	print(i, end=' ')
print()


def main():
	(n, k) = map(int, input().split())
	messages = list(map(int, input().split()))
	present = set()
	friends = []
	for i in messages:
		if len(friends) < k:
			if i not in present:
				friends.append(i)
				present.add(i)
		elif i not in present:
			present.remove(friends.pop(0))
			friends.append(i)
			present.add(i)
	friends.reverse()
	print(len(friends))
	for i in friends:
		print(i, end=' ')
main()


import sys
import itertools
import math
import collections
from collections import Counter

def pow(x, y, mod):
	r = 1
	x = x % mod
	while y > 0:
		if y & 1:
			r = r * x % mod
		y = y >> 1
		x = x * x % mod
	return r

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
(n, k) = mi()
d = li()
id = set()
res = []
dl = 0
f = True
for i in d:
	if i not in id:
		if len(id) == k:
			id.remove(res[dl])
			dl += 1
		id.add(i)
		res.append(i)
print(len(res) - dl)
ans = [res[i] for i in range(len(res) - 1, max(len(res) - k - 1, -1), -1)]
prr(ans)


from collections import deque
(n, k) = map(int, input().split())
s = [int(x) for x in input().split()]
q = deque()
kk = dict()
c = 0
for i in range(0, len(s)):
	if c < k:
		if kk.get(s[i]) == None or kk[s[i]] == 0:
			q.appendleft(s[i])
			kk[s[i]] = 1
			c += 1
	elif kk.get(s[i]) == None or kk[s[i]] == 0:
		r = q.pop()
		kk[r] = 0
		q.appendleft(s[i])
		kk[s[i]] = 1
print(c)
print(*q)


a = input().split()
n = int(a[0])
k = int(a[1])
d = list(map(int, input().split()))
b = []
for x in d:
	if x not in b:
		if len(b) == k:
			b.pop(0)
		b.append(x)
if len(b) > k:
	print(k)
else:
	print(len(b))
b = b[::-1]
for x in b:
	print(x, end=' ')


from array import array
(n, k) = map(int, input().split())
ids = array('i', map(int, input().split()))
l = array('i')
for var in ids:
	if var in l:
		pass
	else:
		l.insert(0, var)
		if len(l) > k:
			l.pop()
print(len(l))
print(*l, sep=' ')


from collections import deque
(n, k) = list(map(int, input().split(' ')))
x = list(map(int, input().split(' ')))
a = deque()
for i in range(n):
	if x[i] not in a:
		if len(a) < k:
			a.appendleft(x[i])
		else:
			a.pop()
			a.appendleft(x[i])
print(len(a))
print(*a, sep=' ')


from sys import stdin
input = stdin.readline
from collections import deque
(s, q) = (set(), deque())
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
for i in arr:
	if i in s:
		continue
	elif count == k:
		t = q.pop()
		q.appendleft(i)
		s.remove(t)
		s.add(i)
	else:
		count += 1
		q.appendleft(i)
		s.add(i)
print(len(q))
print(*q)


import collections
[n, k] = map(int, input().split())
a = [*map(int, input().split())]
answ = collections.deque()
inScreen = set()
for item in a:
	if item in inScreen:
		pass
	else:
		answ.appendleft(item)
		inScreen.add(item)
		if len(answ) > k:
			removed = answ.pop()
			inScreen.remove(removed)
print(len(answ))
print(*answ)


(n, k) = map(int, input().split())
a = []
val1 = input()
val = val1.split(' ')
for i in val:
	i = int(i)
	if i in a:
		continue
	elif len(a) == k and i not in a:
		a.pop()
		a.insert(0, i)
	elif len(a) < k and i not in a:
		a.insert(0, i)
print(len(a))
for i in a:
	print(i, end=' ')


import collections
(n, k) = map(int, input().split())
li = list(map(int, input().split()))
l = collections.deque([])
dic = {}
count = 0
for i in li:
	if dic.get(i) == None or dic.get(i) == 0:
		if count == k:
			temp = l.pop()
			dic[temp] -= 1
			count -= 1
		l.appendleft(i)
		count += 1
		dic[i] = 1
print(len(l))
print(*l)


(n, k) = [int(x) for x in input().split()]
idd = list(map(int, input().split()))
msg = [-1] * k
x = 0
for i in range(n):
	if idd[i] in msg:
		continue
	else:
		for j in range(k - 1):
			msg[j] = msg[j + 1]
		msg[k - 1] = idd[i]
co = 0
for i in range(len(msg)):
	if msg[i] == -1:
		co -= -1
msg = msg[::-1]
print(len(msg) - co)
print(*msg[:len(msg) - co])


(x, y) = map(int, input().split())
(*li,) = map(int, input().split())
li1 = []
for i in range(x):
	if li[i] in li1:
		continue
	elif len(li1) < y:
		li1 = [li[i]] + li1
	else:
		li1 = [li[i]] + li1[:-1]
print(len(li1))
print(*li1)


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
t = []
for i in l:
	if i not in t:
		if len(t) == k:
			t.remove(t[0])
			t.append(i)
		else:
			t.append(i)
print(len(t))
print(*t[::-1])


from collections import deque
(n, k) = map(int, input().split())
q = deque()
x = [int(n) for n in input().split()]
c = 0
ct = 0
for i in range(n):
	if x[i] not in q:
		c += 1
		q.appendleft(x[i])
	ct += 1
	if c == k:
		break
for i in range(ct, n):
	if x[i] not in q:
		q.appendleft(x[i])
		q.pop()
print(len(q))
print(*q)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
ans = []
for t in l:
	if len(ans) < k:
		val = d.get(t, 0)
		if val == 0:
			ans.insert(0, t)
			d[t] = val + 1
	elif len(ans) == k:
		val1 = d.get(t, 0)
		if val1 == 0:
			xc = ans[-1]
			vc = d.get(xc, 0)
			ans.pop(-1)
			d[xc] = vc - 1
			ans.insert(0, t)
			vb = d.get(t, 0)
			d[t] = vb + 1
print(len(ans))
print(*ans)


from collections import deque

def solve2():
	(n, k) = map(int, input().split())
	s_a = input()
	a = [int(x) for x in s_a.split()]
	hash_dic = {}
	reverse_hash = {}
	cnt = 0
	for item in a:
		if item not in hash_dic:
			cnt += 1
			hash_dic[item] = cnt
			reverse_hash[cnt] = item
	b = [hash_dic[x] for x in a]
	q = deque()
	st = set()
	get = [False for x in range(n + 1)]
	for item in b:
		if get[item] == False:
			get[item] = True
			if len(q) == k:
				q.appendleft(item)
				get[q[-1]] = False
				q.pop()
			else:
				q.appendleft(item)
	res = [reverse_hash[x] for x in q]
	print(len(res))
	for item in res:
		print(item, end=' ')
solve2()


(n, k) = map(int, input().split())
a = map(int, input().split())
d = []
for aa in a:
	if aa in d:
		continue
	if len(d) >= k:
		d.pop()
	d.insert(0, aa)
print(len(d))
print(*d)


(n, k) = map(int, input().split(' '))
a = [int(x) for x in input().strip().split(' ')]
l = []
c = 0
for i in range(n):
	if a[i] not in l:
		if c < k:
			l.insert(0, a[i])
			c += 1
		else:
			l.pop()
			l.insert(0, a[i])
print(len(l))
print(*l)


(n, k) = map(int, input().split())
idi = [*map(int, input().split())]
op = [-1] * k
nop = 0
for i in range(n):
	if idi[i] in op:
		continue
	else:
		if nop < k:
			nop += 1
		op = [idi[i]] + op[:-1]
print(nop)
for i in range(nop):
	print(str(op[i]) + ' ', end='')


from collections import deque
(x, y) = map(int, input().split())
a = list(map(int, input().split()))
b = deque()
i = 0
s = set()
while i < x:
	if a[i] not in s:
		b.appendleft(a[i])
		s.add(a[i])
		if len(b) > y:
			s.remove(b.pop())
	i += 1
print(len(b))
print(*b)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
x = []
o = 0
for i in range(a):
	if o < b and l[i] not in x:
		x = x[::-1]
		x.append(l[i])
		x = x[::-1]
		o = o + 1
	elif l[i] not in x:
		x.pop(-1)
		x = x[::-1]
		x.append(l[i])
		x = x[::-1]
print(len(x))
print(*x)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
new = []
if n <= k:
	for i in range(n):
		if new.__contains__(l[i]):
			pass
		else:
			new.insert(0, l[i])
if n > k:
	for i in range(n):
		if new.__contains__(l[i]):
			pass
		elif len(new) < k:
			new.insert(0, l[i])
		else:
			new.remove(new[-1])
			new.insert(0, l[i])
print(len(new))
print(*new)


from collections import deque
(n, k) = [int(x) for x in input().split()]
vals = [int(x) for x in input().split()]
S = set()
Q = deque()
for ids in vals:
	if not ids in S:
		S.add(ids)
		Q.appendleft(ids)
		if len(Q) > k:
			S.remove(Q.pop())
print(len(Q))
print(*Q)


(n, k) = map(int, input().split())
ids = [int(x) for x in input().split()]
a = []
for i in ids:
	if i in a:
		pass
	elif i not in a and len(a) != k:
		a.insert(0, i)
	elif i not in a and len(a) == k:
		a.insert(0, i)
		a.remove(a[-1])
print(len(a))
print(' '.join(map(str, a)))


from collections import deque

def solve(a, n, k):
	if k == 1:
		return [a[-1]]
	temp = deque()
	d = {}
	for i in a:
		if d.get(i):
			pass
		else:
			d[i] = 1
			if len(temp) >= min(n, k):
				x = temp.popleft()
				d[x] -= 1
			temp.append(i)
	return temp
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = solve(arr, n, k)
print(len(ans))
while len(ans):
	print(ans.pop(), end=' ')


R = lambda : map(int, input().split())
(n, k) = R()
a = []
d = {}
i = 1
for x in R():
	if d.get(x, -k) < i - k:
		d[x] = i
		a += (x,)
		i += 1
a = a[::-1][:k]
print(len(a))
print(*a)


from collections import deque
(n, k) = [int(x) for x in input().split()]
a = [int(j) for j in input().split()]
s = set()
q = deque()
for x in a:
	if x in s:
		continue
	else:
		q.appendleft(x)
		s.add(x)
		if len(q) > k:
			t = q.pop()
			s.remove(t)
print(len(q))
for x in q:
	print(x, end=' ')


(n, k) = [int(i) for i in input().split()]
a = set()
b = []
id = [int(i) for i in input().split()]
for i in range(n):
	if len(b) < k and id[i] not in a:
		b.insert(0, id[i])
	elif len(b) == k and id[i] not in a:
		b.insert(0, id[i])
		a.discard(b.pop())
	a.add(id[i])
print(len(b))
print(*b)


(s, k) = map(int, input().split())
a = list(map(int, input().split()))
l = [] * k
for i in a:
	if i not in l:
		l.insert(0, i)
	if len(l) > k:
		l.pop()
print(len(l))
print(*l)


from collections import deque
(N, K) = map(int, input().split())
(*A,) = map(int, input().split())
S = set()
que = deque()
for a in A:
	if a in S:
		continue
	if len(que) == K:
		b = que.popleft()
		S.remove(b)
	que.append(a)
	S.add(a)
print(len(que))
print(*reversed(que))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = set()
new = []
for i in l:
	if i in s:
		continue
	s.add(i)
	if len(new) < k:
		new.insert(0, i)
	else:
		new.insert(0, i)
		s.discard(new[len(new) - 1])
		new.pop(len(new) - 1)
print(len(s))
for i in new:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
kc = 0
for i in a:
	if i not in b[0:kc]:
		if kc < k:
			b.insert(0, i)
			kc += 1
		elif kc == k:
			b.insert(0, i)
	else:
		continue
print(kc)
print(*b[0:kc])


(n, k) = map(int, input().split())
ms = []
m = list(map(int, input().split()))
for i in range(n):
	if m[i] not in ms:
		if len(ms) == k:
			ms.pop()
		ms.insert(0, m[i])
print(len(ms))
print(*ms)


(n, k) = list(map(int, input().split()))
queue = [0] * k
cache = set()
last = k - 1
ip = list(map(int, input().split()))
for elem in ip:
	if elem not in cache:
		cache.add(elem)
		if queue[last] in cache:
			cache.remove(queue[last])
		queue[last] = elem
		last = (last + 1) % k
m = len(cache)
print(m)
i = 0
while i != m:
	last -= 1
	if last < 0:
		last = k - 1
	if queue[last] != 0:
		print(queue[last], end=' ')
		i += 1


import sys
line1 = sys.stdin.readline()
line2 = sys.stdin.readline()
line1 = line1.split()
nIds = int(line1[0])
nConvers = int(line1[1])
line2 = line2.split()
messages = []
for i in range(len(line2)):
	messages.append(int(line2[i]))
Shown = []
for i in range(len(messages)):
	if messages[i] in Shown:
		continue
	if len(Shown) < nConvers:
		Shown.insert(0, messages[i])
	else:
		del Shown[-1]
		Shown.insert(0, messages[i])
print(len(Shown))
st = ''
for i in range(len(Shown)):
	st += str(Shown[i])
	if i == len(Shown) - 1:
		break
	st += ' '
print(st)


(n, k) = map(int, input().split())
x = map(int, input().split())
ans = []
for i in x:
	if i not in ans:
		if len(ans) == k:
			del ans[-1]
		ans.insert(0, i)
print(len(ans))
for i in range(0, len(ans) - 1):
	print(ans[i], end=' ')
print(ans[-1])


def main():
	(N, K) = (int(i) for i in input().split())
	ID = [int(i) for i in input().split()]
	from collections import deque
	screen = deque([], maxlen=K)
	now = set()
	for i in ID:
		if i not in now:
			if len(screen) == K:
				now.discard(screen.pop())
			screen.appendleft(i)
			now.add(i)
	print(len(screen))
	print(*screen)
main()


import collections
(n, k) = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
de = collections.deque([])
se = set([])
p = 0
for item in x:
	if item not in se:
		if p < k:
			p += 1
			de.appendleft(item)
			se.add(item)
		else:
			de.appendleft(item)
			se.add(item)
			se.discard(de[len(de) - 1])
			de.pop()
print(len(de))
print(*list(de)[:])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
nu = 3 * 10 ** 5
dis = [0] * nu
fl = nu
fil = 0
re = 3 * 10 ** 5
s = set([])
for i in l:
	if i not in s:
		if fil != k:
			dis[fl - 1] = i
			s.add(i)
			fl -= 1
			fil = fil + 1
		else:
			s.remove(dis[re - 1])
			dis[re - 1] = 0
			re -= 1
			dis[fl - 1] = i
			s.add(i)
			fl -= 1
print(min(fil, k))
for i in dis:
	if i != 0:
		print(i, end=' ')


(n, k) = map(int, input().split(' '))
lis = [int(k) for k in input().split(' ')]
(tot, ltot) = ([], 0)
for i in range(n):
	next = lis[i]
	if next not in tot and ltot < k:
		ltot += 1
		tot = [next] + tot
	elif next not in tot:
		tot.pop(ltot - 1)
		tot = [next] + tot
print(ltot)
print(' '.join((str(k) for k in tot)))


(n, k) = input().split()
n = int(n)
k = int(k)
a = [int(i) for i in input().split()]
x = []
t = 0
for i in a:
	if i not in x:
		if t != k:
			x.insert(0, i)
			t = t + 1
		else:
			x.insert(0, i)
			x.pop()
y = len(x)
print(y)
for i in x:
	print(i, end=' ')


(n, k) = (int(x) for x in input().split(' '))
m = [int(y) for y in input().split(' ')]
l = []
count = 0
for i in range(n):
	if len(l) < k and m[i] not in l:
		l.append(m[i])
	elif m[i] not in l:
		l.pop(0)
		l.append(m[i])
print(len(l))
l.reverse()
print(*l, sep=' ')


(n, k) = map(int, input().split())
l1 = []
s = set(l1)
inp = list(map(int, input().split()))
for i in range(n):
	element = inp[i]
	if element not in s:
		if len(l1) == k:
			l1.pop(k - 1)
		l1 = [element] + l1
		s = set(l1)
print(len(l1))
for j in l1:
	print(j, end=' ')


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = deque()
for i in a:
	if i not in q:
		q.appendleft(i)
		if len(q) > k:
			q.pop()
print(len(q))
print(*q, sep=' ')


(n, k) = list(map(int, input().split()))
id = list(map(int, input().split()))
q = []
for i in range(len(id)):
	if not id[i] in q:
		if len(q) == k:
			q.pop(-1)
			q.insert(0, id[i])
		else:
			q.insert(0, id[i])
print(len(q))
for elem in q:
	print(elem, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
dic = {}
out = []
l = 0
for i in range(n):
	if dic.get(arr[i], 0) == 0:
		dic[arr[i]] = 1
		out.append(arr[i])
		if len(out) > k:
			x = out.pop(0)
			dic[x] = 0
print(len(out))
print(*out[::-1])


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
display = []
for i in arr:
	if i not in display[-1:-k - 1:-1]:
		display.append(i)
print(min(k, len(display)))
print(' '.join((str(i) for i in display[-1:-k - 1:-1])))


import queue
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
myset = set()
Q = [0] * n
head = tail = 0
for x in arr:
	if x in myset:
		continue
	if tail - head == k:
		myset.remove(Q[head])
		head += 1
	Q[tail] = x
	myset.add(x)
	tail += 1
print(tail - head)
for i in range(tail - 1, head - 1, -1):
	print(Q[i], end=' ')


__author__ = 'Esfandiar'
from collections import defaultdict, Counter, deque
import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
res = deque()
tol = 0
d = dict()
for i in range(n):
	if d.get(a[i], -1) == -1:
		d[a[i]] = 1
		res.appendleft(a[i])
		tol += 1
		if tol > k:
			w = res.pop()
			tol -= 1
			d[w] = -1
	else:
		pass
print(tol)
print(*res)


(n, k) = map(int, input().split())
ID = list(map(int, input().split()))
S = list()
for i in range(n):
	if len(S) != k:
		if ID[i] not in S:
			S.append(ID[i])
		else:
			continue
	elif ID[i] not in S:
		del S[0]
		S.append(ID[i])
	else:
		continue
print(len(S))
print(' '.join(map(str, S[::-1])))


(n, k) = tuple(map(int, input().split()))
ids = list(map(int, input().split()))
stack = []
i = 0
while i < n:
	if len(stack) <= k and ids[i] not in stack:
		stack.insert(0, ids[i])
		if len(stack) > k:
			stack.pop()
	i = i + 1
print(len(stack))
for j in range(0, len(stack)):
	print(stack[j], end=' ')


a = input()
b = input()
y = a.split(' ')
n = int(y[0])
k = int(y[1])
b = b.split(' ')
conversationlist = []
for x in b:
	if len(conversationlist) < k:
		if x not in conversationlist:
			conversationlist.append(x)
	elif x not in conversationlist:
		conversationlist.pop(0)
		conversationlist.append(x)
print(len(conversationlist))
for z in conversationlist[::-1]:
	print(int(z), end=' ')


from collections import defaultdict, deque
(n, k) = map(int, input().split())
num = list(map(int, input().split()))
q = deque([])
flag = defaultdict(int)
for i in range(n):
	if flag[num[i]] == 0:
		q.appendleft(num[i])
		flag[num[i]] = 1
		if len(q) > k:
			a = q.pop()
			flag[a] = 0
print(len(q))
print(*q)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
b = []
c = 0
for i in range(n):
	if len(b) == 0:
		d[a[i]] = 0
		b.append(a[i])
	elif len(b) < k:
		if a[i] not in d:
			d[a[i]] = 0
			b.append(a[i])
	elif len(b) == k:
		if a[i] not in d:
			d[a[i]] = 0
			b.append(a[i])
			del d[b[0]]
			del b[0]
print(len(b))
print(*b[::-1])


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
sc = []
for i in range(n):
	if a[i] in sc:
		pass
	elif len(sc) < k:
		sc.insert(0, a[i])
	else:
		sc.pop(len(sc) - 1)
		sc.insert(0, a[i])
print(len(sc))
print(*sc)


from collections import *
(n, k) = map(int, input().split())
d = defaultdict()
a = list(map(int, input().split()))
b = deque()
for i in range(n):
	d[a[i]] = 0
for i in range(n):
	if d[a[i]] == 1:
		ch = 1
	else:
		ch = 0
	if ch == 0:
		d[a[i]] = 1
		if len(b) == k:
			d[b.pop()] = 0
		b.appendleft(a[i])
if len(b) > k:
	print(k)
	for i in range(k):
		print(b[i], end=' ')
else:
	print(len(b))
	for i in range(len(b)):
		print(b[i], end=' ')


(n, k) = map(int, input().split())
id = list(map(int, input().split()))
m = []
for i in id:
	if i not in m:
		if len(m) == k:
			m.pop(0)
			m.append(i)
		else:
			m.append(i)
m.reverse()
print(len(m))
for i in m:
	print(i, end=' ')


(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
A = []
dic = {}
(ptr, cnt) = (0, 0)
for i in ids:
	if dic.get(i, 0) == 0:
		dic[i] = 1
		A.append(i)
		cnt += 1
	if cnt > k:
		dic[A[ptr]] = 0
		ptr += 1
		cnt -= 1
print(len(A) - ptr)
A1 = A[ptr:len(A)]
A2 = A1[::-1]
print(*A2)


(n, k) = map(int, input().split())
id_list = input().split()
stack = []
curr = {}
count = 1
for ids in id_list:
	if curr.get(ids, 0) < count:
		curr[ids] = count + k
		stack += [ids]
		count += 1
stack = stack[::-1][:k]
print(len(stack))
print(' '.join(stack))


a = input().split()
n = int(a[0])
k = int(a[1])
ids = list(map(int, input().split()))
T = list([])
for i in ids:
	if i not in T and len(T) < k:
		T.append(i)
	elif i not in T and len(T) == k:
		T.remove(T[0])
		T.append(i)
print(len(T))
for i in range(len(T)):
	print(T[-i - 1], end=' ')


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
(n, k) = mi()
id = li()
l = []
for i in id:
	if i not in l:
		if len(l) == k:
			l.insert(0, i)
			l.remove(l[k])
		else:
			l.insert(0, i)
	else:
		continue
print(len(l))
print(*l)


mod = 10 ** 9 + 7
from sys import stdin, stdout
import bisect
import queue
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import collections
import math
import heapq
from random import randint as rn

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	(n, k) = cin()
	a = ain()
	l = queue.Queue(maxsize=k + 1)
	d = {}
	j = 0
	for i in a:
		if i not in d or d[i] == 0:
			if k != 0:
				d[i] = 1
				l.put(i)
				k -= 1
			elif k == 0:
				f = l.get()
				d[f] -= 1
				l.put(i)
				d[i] = 1
	x = []
	while 1:
		if l.empty():
			break
		j = l.get()
		x.append(j)
	print(len(x))
	print(*x[::-1])
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
x = 0
for i in range(n):
	m = 0
	if a[i] in b:
		m = 1
	if m == 0 and x == k:
		b = [a[i]] + b[0:k - 1]
	if m == 0 and x != k:
		x += 1
		b = [a[i]] + b
print(len(b))
print(*b)


from collections import deque
(n, k) = list(map(int, input().split()))
s = set()
d = deque()
for i in map(int, input().split()):
	if i in s:
		continue
	if len(d) == k:
		s.discard(d.pop())
	d.appendleft(i)
	s.add(i)
print(len(d))
print(*d)


from collections import OrderedDict
(n, size) = map(int, input().split())
window = OrderedDict()
arr = list(map(int, input().split()))
for i in range(n):
	if arr[i] not in window:
		if len(window) == size:
			window.popitem(last=False)
		window[arr[i]] = 1
show = []
for x in window:
	show.append(x)
print(len(show))
for i in range(len(show) - 1, -1, -1):
	print(show[i], end=' ')


from sys import stdin
from collections import deque, defaultdict
input = stdin.readline
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
d = defaultdict(lambda : False)
ans = deque()
for i in range(n):
	if len(ans) < k:
		if not d[arr[i]]:
			ans.append(arr[i])
			d[arr[i]] = True
	elif not d[arr[i]]:
		ans.append(arr[i])
		d[arr[i]] = True
		t = ans.popleft()
		d[t] = False
print(len(ans))
for i in range(len(ans)):
	print(ans[-(i + 1)], end=' ')


(n, k) = map(int, input().split())
conv = []
IDs = list(map(int, input().split()))
for ID in IDs:
	while len(conv) < k and conv.count(ID) < 1:
		conv.insert(0, ID)
	if conv.count(ID) == 1:
		continue
	else:
		for i in range(len(conv), 0, -1):
			conv[i - 1] = conv[i - 2]
		conv[0] = ID
print(len(conv))
print(*conv)


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = set()
b = deque([], k)
for i in a:
	if i not in s:
		if len(b) >= k:
			x = b.popleft()
			s.remove(x)
		b.append(i)
		s.add(i)
print(len(b))
print(*list(b)[::-1])


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
p = []
for i in ids:
	if i not in p:
		if len(p) == k:
			p.pop()
		p.insert(0, i)
print(len(p))
print(*p)


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
L1 = []
for i in range(len(L)):
	p = L[i]
	if len(L1) < k:
		flag = True
		j = 0
		while j < len(L1):
			if L1[j] == p:
				flag = False
			j = j + 1
		if flag == True:
			L1 = [p] + L1
	elif len(L1) == k:
		flag = True
		j = 0
		while j < len(L1):
			if L1[j] == p:
				flag = False
			j = j + 1
		if flag == True:
			L1.pop(-1)
			L1 = [p] + L1
print(len(L1))
for i in range(len(L1)):
	print(L1[i], end=' ')


from collections import deque
(n, k) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
screen = deque()
for i in range(len(arr)):
	if not arr[i] in screen:
		screen.appendleft(arr[i])
	if len(screen) > k:
		screen.pop()
print(len(screen))
print(' '.join(map(str, screen)))


from collections import deque
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
cur = 0
scr = deque()
ss = set()
for a in A:
	if cur < k:
		if not a in ss:
			scr.append(a)
			ss.add(a)
			cur += 1
	elif not a in ss:
		ss.add(a)
		tmp = scr.popleft()
		ss.remove(tmp)
		scr.append(a)
scr = list(scr)
print(len(scr))
print(' '.join(map(str, reversed(scr))))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
for t in l:
	if len(ans) < k and t not in ans:
		ans.insert(0, t)
	if len(ans) == k and t not in ans:
		ans.pop(len(ans) - 1)
		ans.insert(0, t)
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
lst = []
cn = 0
for num in arr:
	if len(lst) < k:
		if num not in lst:
			lst.insert(0, num)
	elif len(lst) >= k:
		if num not in lst:
			lst.pop()
			lst.insert(0, num)
print(len(lst))
for i in lst:
	print(i, end=' ')


from collections import deque

def main():
	(n, k) = map(int, input().split(' '))
	gl = list(map(int, input().split(' ')))
	main_list = deque()
	s = set()
	for i in gl:
		if len(main_list) < k:
			if i in s:
				continue
			main_list.appendleft(i)
			s.add(i)
		elif len(main_list) == k:
			if i in s:
				continue
			s.discard(main_list.pop())
			main_list.appendleft(i)
			s.add(i)
	print(len(main_list))
	print(*main_list)
main()


from collections import deque
(n, k) = map(int, input().split())
id_list = list(map(int, input().split()))
active_set = set()
screen_q = deque()
for id in id_list:
	if id not in active_set:
		active_set.add(id)
		if len(screen_q) == k:
			id_out = screen_q[-1]
			active_set.remove(id_out)
			screen_q.pop()
		screen_q.appendleft(id)
print(len(screen_q))
for elem in screen_q:
	print(elem, end=' ')


import collections
a = list(map(int, input().split()))
n = a[0]
k = a[1]
ids = list(map(int, input().split()))
s = set()
displayed = collections.deque()
for i in range(n):
	if ids[i] not in s:
		s.add(ids[i])
		displayed.appendleft(ids[i])
		if len(s) > k:
			l = displayed.pop()
			s.remove(l)
print(len(displayed))
print(' '.join(map(str, displayed)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ansList = []
for i in range(n):
	if a[i] not in ansList:
		ansList.append(a[i])
	if len(ansList) == k + 1:
		ansList.pop(0)
z = len(ansList)
ansList.reverse()
print(min(n, k, z))
print(*ansList)


from collections import deque
(n, k) = [int(x) for x in input().split()]
screen = deque()
screenSet = set()
for id in [int(x) for x in input().split()]:
	if id not in screenSet:
		screen.appendleft(id)
		screenSet.add(id)
		if len(screen) > k:
			screenSet.remove(screen.pop())
print(len(screen))
print(*screen)


from collections import deque
(n, k) = map(int, input().split())
q = deque()
a = list(map(int, input().split()))
vis = set()
for i in range(n):
	if len(q) < k:
		if a[i] not in vis:
			q.append(a[i])
			vis.add(a[i])
	elif a[i] not in vis:
		q.append(a[i])
		vis.remove(q.popleft())
		vis.add(a[i])
print(len(q))
print(str(list(q)[::-1]).replace('[', '').replace(']', '').replace(', ', ' '))


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	(n, k) = mp()
	a = li()
	q = [a[0]]
	q = deque(q)
	d = {a[0]: 1}
	for i in range(1, n):
		if a[i] not in d:
			if len(q) == k:
				del d[q.popleft()]
				q.append(a[i])
				d[a[i]] = 1
			else:
				q.append(a[i])
				d[a[i]] = 1
	print(len(q))
	q = list(q)
	print(*q[::-1])
for _ in range(1):
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections
(n, k) = map(int, input().split())
vals = list(map(int, input().split()))
dis = collections.deque([])
cur = set([])
for s in range(n):
	if len(cur) < k:
		if not vals[s] in cur:
			cur.add(vals[s])
			dis.appendleft(vals[s])
		else:
			continue
	elif not vals[s] in cur:
		v0 = dis.pop()
		cur.remove(v0)
		cur.add(vals[s])
		dis.appendleft(vals[s])
	else:
		continue
print(len(dis))
print(*dis)


from collections import deque

def main():
	(n, k) = [int(x) for x in input().split()]
	ids = [int(x) for x in input().split()]
	convos = deque()
	for i in ids:
		if i in convos:
			continue
		if len(convos) < k:
			convos.appendleft(i)
		else:
			convos.pop()
			convos.appendleft(i)
	print(len(convos))
	print(' '.join(list((str(x) for x in convos))))
main()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
msg = [0] * k
(head, tail) = (0, -1)
conv = set()
for x in a:
	if x not in conv:
		if tail >= head or tail == -1:
			length = tail - head + 1
		else:
			length = k - head + (tail + 1)
		if length == k:
			conv.remove(msg[head])
			head = (head + 1) % k
		tail = (tail + 1) % k
		msg[tail] = x
		conv.add(msg[tail])
if tail >= head:
	ans = msg[head:tail + 1]
else:
	ans = msg[head:] + msg[:tail + 1]
print(len(ans))
print(' '.join(list(map(str, reversed(ans)))))


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def mex(li):
	check = [0] * 1001
	for i in li:
		check[i] += 1
	for i in range(len(check)):
		if check[i] == 0:
			return i

def sumdigits(n):
	ans = 0
	while n != 0:
		ans += n % 10
		n //= 10
	return ans
from math import *
from collections import deque
for _ in range(1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	q = deque([])
	s = set()
	for i in a:
		if i in s:
			continue
		elif len(q) < k:
			q.appendleft(i)
			s.add(i)
		else:
			t = q.pop()
			s.remove(t)
			s.add(i)
			q.appendleft(i)
	print(len(q))
	print(*q)


from collections import deque
(n, k) = map(int, input().split())
ids_in = input().split()
d = {}
ids_out_size = 0
ids_out = deque([])
for id_ in ids_in:
	try:
		in_d = d[id_]
	except:
		in_d = False
	if not in_d:
		ids_out.appendleft(id_)
		d[id_] = True
		if ids_out_size + 1 > k:
			d[ids_out[-1]] = False
			ids_out.pop()
		else:
			ids_out_size += 1
print(ids_out_size)
print(*ids_out)


(n, k) = [int(i) for i in input().split()]
stack = input()
messages = []
for message in stack.split():
	messages.append(int(message))
del stack
chats = []
for i in messages:
	if not i in chats:
		if len(chats) == k:
			chats.pop()
		chats.insert(0, i)
print(len(chats))
chat_list = str(chats.pop(0))
for i in chats:
	chat_list += ' ' + str(i)
print(chat_list)


class MyQueue:

	def __init__(self, length):
		self.li = []
		self.in_q = {}
		self.q_len = length

	def insert(self, it):
		if not self.in_q.get(it, 0):
			self.in_q[it] = 1
			if len(self.li) < self.q_len:
				self.li.insert(0, it)
			else:
				el = self.li.pop()
				self.li.insert(0, it)
				del self.in_q[el]

	def get_li(self):
		return self.li
(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
my_qu = MyQueue(k)
for Id in ids:
	my_qu.insert(Id)
ans = my_qu.get_li()
print(len(ans))
for Id in ans[:-1]:
	print(Id, end=' ')
print(ans[-1])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = list(set(l))
m = {i: -1 for i in s}
for i in l:
	if m[i] == -1:
		for j in s:
			if m[j] < k and m[j] != -1:
				m[j] += 1
			else:
				m[j] = -1
		m[i] = 1
aas = [0] * (k + 1)
for i in s:
	if m[i] != -1:
		aas[m[i]] = i
print(min(len(s), k))
print(*aas[1:min(len(s), k) + 1])


from math import *
from sys import *
from heapq import *
from collections import defaultdict
import os, sys
from io import IOBase, BytesIO
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def alldivisors(n):
	list = []
	arr = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				arr += [i]
			else:
				arr += [i]
				list.append(n // i)
	arr += list[::-1]
	return arr

def primefactorisation(n):
	potentional_p = 3
	itog_list = defaultdict(int)
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			itog_list[n] += 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			itog_list[potentional_p] += 1
		potentional_p += 2
	return itog_list

def main():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	dict = defaultdict(int)
	win = []
	ln = 0
	for x in a:
		if dict[x] == 0:
			win = [x] + win
			ln += 1
			if ln > k:
				dict[win[-1]] = 0
				win = win[:-1]
			dict[x] = 1
	print(len(win[:k]))
	print(*win[:k])
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = dict()
for i in range(n):
	d[a[i]] = 0
ans = deque()
for i in range(n):
	if d[a[i]] == 0:
		ans.appendleft(a[i])
		if len(ans) > k:
			d[ans.pop()] = 0
		d[a[i]] = 1
print(len(ans))
print(' '.join(map(str, ans)))


import sys
from collections import deque
input = sys.stdin.readline
MyDict = {}
X = list(map(int, input().split()))
Messages = list(map(int, input().split()))
(Check, size) = (deque(), 0)
for i in range(X[0]):
	if MyDict.get(Messages[i]) == None:
		MyDict[Messages[i]] = 0
		if size >= X[1]:
			del MyDict[Check[X[1] - 1]]
		Check.appendleft(Messages[i])
		size += 1
print(size if size < X[1] else X[1])
print(*list(Check)[:X[1]])


from collections import defaultdict, deque
(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = deque([])
d = {}
uni1 = list(set(arr))
for i in uni1:
	d[i] = 0
for i in arr:
	if d[i] == 0:
		if len(ans) == k:
			d[ans[-1]] = 0
			ans.pop()
			ans.appendleft(i)
			d[i] = 1
		else:
			ans.appendleft(i)
			d[i] = 1
print(len(ans))
ans = list(ans)
print(*ans)


(a, b) = map(int, input().split(' '))
c = list(map(int, input().split(' ')))
d = []
for i in range(0, a):
	if c[i] not in d[0:b]:
		d.insert(0, c[i])
if len(d) < b:
	print(len(d))
	for i in range(0, len(d)):
		print(d[i], end=' ')
else:
	print(b)
	for i in range(0, b):
		print(d[i], end=' ')


from collections import deque
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
a = deque()
s = set()
for id in ids:
	if id in s:
		continue
	if len(a) < k:
		a.append(id)
		s.add(id)
	else:
		lastId = a.popleft()
		s.remove(lastId)
		a.append(id)
		s.add(id)
print(len(a))
print(*list(reversed(a)))


(n, a) = map(int, input().split())
li = list(map(int, input().split()))
li1 = []
for i in li:
	if len(li1) == a:
		if i not in li1:
			li1.pop(0)
			li1.append(i)
	elif i not in li1:
		li1.append(i)
li1 = li1[::-1].copy()
print(len(li1))
print(*li1, sep=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
temp = []
c = 0
for i in range(len(a)):
	if a[i] in temp:
		continue
	temp.insert(0, a[i])
	if len(temp) > k:
		temp = temp[:k]
print(len(temp))
print(*temp)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
conversation = []
new = set()
for i in arr:
	if i not in new:
		if len(conversation) == 0:
			conversation.append(i)
			new.add(i)
		elif len(conversation) < k:
			conversation.append(i)
			new.add(i)
		else:
			x = conversation[0]
			conversation.pop(0)
			new.remove(x)
			conversation.append(i)
			new.add(i)
print(len(conversation))
conversation.reverse()
print(*conversation, sep=' ')


def f():
	(n, k) = list(map(int, list(input().split())))
	l = list(map(int, list(input().split())))
	r = []
	for i in l:
		if i not in r and len(r) < k:
			r.insert(0, i)
		elif i not in r and len(r) == k:
			r.pop()
			r.insert(0, i)
	return r
l = f()
print(len(l))
print(*l)


def solve(nums, k):
	l = list()
	h = set()
	for j in nums:
		if j not in h:
			if len(l) == k:
				h.remove(l[0])
				l.pop(0)
			l.append(j)
			h.add(j)
	return l

def main():
	(_, k) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	sol = solve(nums, k)
	print(len(sol))
	for i in reversed(sol):
		print(i, end=' ')
main()


(n, k) = map(int, input().split())
S = list(map(int, input().split()))
now = [S[0]]
for i in range(1, n):
	was = 0
	for j in range(len(now)):
		if now[j] == S[i]:
			was = 1
	if was == 0:
		now = [S[i]] + now
		if len(now) > k:
			now.pop(k)
print(len(now))
print(*now, sep=' ')


(n_msgs, n_tela) = map(int, input().split(' '))
msgs = input().split(' ')
tela = {}
posicao_tela = []
for msg in msgs:
	if tela.get(msg) == None:
		if len(posicao_tela) >= n_tela:
			tela[posicao_tela.pop(0)] = False
		posicao_tela.append(msg)
		tela[msg] = True
	elif tela[msg] == False:
		tela[posicao_tela.pop(0)] = False
		posicao_tela.append(msg)
		tela[msg] = True
posicao_tela.reverse()
print(len(posicao_tela))
print(' '.join(posicao_tela))


import sys
import math
import collections

def read_two_lines():
	(num_messages, k) = [int(x) for x in input().split()]
	message_ids = input().split()
	queue = de = collections.deque()
	queue_set = set()
	queue_len = 0
	message_count = 0
	for m in message_ids:
		if message_count == num_messages:
			break
		m = int(m)
		if m in queue_set:
			continue
		else:
			if queue_len == k:
				to_remove = queue.pop()
				queue_set.remove(to_remove)
				queue_len -= 1
			queue.appendleft(m)
			queue_set.add(m)
			queue_len += 1
		message_count += 1
	print(queue_len)
	print(' '.join([str(x) for x in queue]))
	return queue
read_two_lines()


from os import environ
from sys import stdin, stdout
from math import gcd
from collections import deque

class Input:

	def read(self, func):
		return func(stdin.readline().strip())

	def readn(self, func):
		return list(map(func, stdin.readline().strip().split()))

	def readiter(self):
		return iter(stdin.readline().strip().split())

	def next(self, it, func):
		return func(next(it))
pin = Input()
LOCAL = environ.get('LOCAL')

def local(func):

	def innerFunc(*args, **kwargs):
		if LOCAL:
			return func()
	return innerFunc

def testcases(func):

	def innerFunc(*args, **kwargs):
		T = pin.read(int)
		for tt in range(T):
			func(*args, **kwargs)
	return innerFunc

@local
def debug(*args):
	print(*args)

class Task:

	def solveOne(self):
		(n, k) = pin.readn(int)
		A = pin.readn(int)
		Q = deque()
		check = {}
		for i in range(0, n):
			if len(Q) == k:
				if not check.get(A[i]):
					check[Q[-1]] = False
					Q.pop()
					Q.appendleft(A[i])
					check[A[i]] = True
			elif not check.get(A[i]):
				Q.appendleft(A[i])
				check[A[i]] = True
		print(len(Q))
		for i in Q:
			print(i, end=' ')
task = Task()
task.solveOne()


(m, n) = list(map(int, input().split()))
arr = list(map(int, input().split()))
stack = []
for el in arr:
	if el in stack:
		continue
	elif len(stack) == n:
		del stack[-1]
		stack.append(el)
		stack = [stack[-1]] + stack[:-1]
	else:
		stack.insert(0, el)
print(len(stack))
print(' '.join(list(map(str, stack))))


a = input().split()
n = int(a[0])
k = int(a[1])
friend = [-5 for i in range(0, n)]
seq = [0 for i in range(0, k)]
a = input().split()
for i in range(0, n):
	friend[i] = int(a[i])
for i in range(0, n):
	b = friend[i]
	if b in seq:
		pass
	else:
		seq.insert(0, b)
		seq = seq[0:k]
ans = 0
for i in range(0, k):
	if seq[i] != 0:
		ans = ans + 1
print(ans)
for i in range(0, ans):
	print(seq[i], end=' ')


from queue import Queue
(n, k) = map(int, input().split())
q = Queue(maxsize=k)
id = list(map(int, input().split()))
d = set()
for i in id:
	if i not in d:
		d.add(i)
		if q.qsize() < k:
			q.put(i)
		else:
			x = q.get()
			d.remove(x)
			q.put(i)
print(q.qsize())
res = []
for i in range(q.qsize()):
	res.append(q.get())
print(*res[::-1])


def __starting_point():
	l = [int(i) for i in input().split(' ')]
	n = l[0]
	k = l[1]
	l = [int(i) for i in input().split(' ')]
	a = []
	for i in l:
		if i not in a:
			if len(a) >= k:
				a.pop()
			a.insert(0, i)
	print(len(a))
	for i in a:
		print(i, end=' ')
__starting_point()


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, k) = mi()
d = li()
b = []
for i in range(n):
	if len(b) < k and d[i] not in b:
		b.insert(0, d[i])
	elif d[i] not in b:
		b.pop()
		b.insert(0, d[i])
print(len(b))
for i in range(len(b)):
	print(b[i], end=' ')


import math
import copy
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = []
i2 = 0
c = {}
for i in range(n):
	if len(b) < k:
		if a[i] - 1 not in c:
			c[a[i] - 1] = 1
			b.append(a[i])
	elif a[i] - 1 not in c:
		b.append(a[i])
		c[a[i] - 1] = 1
		del c[b[i2] - 1]
		i2 += 1
if len(b) <= k:
	print(len(b))
	for i in b[::-1]:
		print(i, end=' ')
else:
	print(k)
	for i1 in range(len(b) - 1, i2 - 1, -1):
		print(b[i1], end=' ')
print()


from collections import deque
(n, k) = map(int, input().split())
screen = deque(maxlen=k)
already_in_screen = set()
j = list(map(int, input().split()))
for elem in j:
	if elem not in already_in_screen:
		if len(screen) >= k and len(already_in_screen) >= k:
			need_to_del = screen[0]
			already_in_screen.discard(need_to_del)
		screen.append(elem)
		already_in_screen.add(elem)
print(len(screen))
print(*reversed(screen))


while True:
	try:
		(i, cons) = [int(i) for i in input().split(' ')]
		nums = [int(i) for i in input().split(' ')]
		displayed = []
		for n in nums:
			if n in displayed:
				continue
			else:
				displayed.insert(0, n)
				displayed = displayed[:cons]
		print(len(displayed))
		print(' '.join([str(c) for c in displayed]))
	except EOFError as E:
		break


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
nums = []
disp = {}
for num in c:
	if num not in disp:
		if len(nums) < k:
			nums.insert(0, num)
			disp[num] = 1
		else:
			del disp[nums[len(nums) - 1]]
			del nums[len(nums) - 1]
			nums.insert(0, num)
			disp[num] = 1
print(len(nums))
print(*nums)


import math
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
d = {}
stack = []
left = 0
for i in arr:
	if i not in d.keys():
		d[i] = True
		if len(stack) - left == k:
			stack.append(i)
			d[stack[left]] = False
			left += 1
		else:
			stack.append(i)
	elif d[i] == False:
		stack.append(i)
		d[i] = True
		d[stack[left]] = False
		left += 1
print(len(stack) - left)
for i in range(len(stack) - 1, left - 1, -1):
	print(stack[i], end=' ')


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
l1 = [0] * 100003
(c, p) = (0, 0)
for i in range(n):
	if l[i] not in l1[p:c]:
		l1[c] = l[i]
		c += 1
	if c > m - 1:
		p = c - m
l2 = l1[p:c]
print(c - p)
for i in range(c - p):
	print(l2[c - p - i - 1], end=' ')


from collections import Counter
(n, k) = list(map(int, input().split()))
lst = list(map(int, input().split()))
lst1 = []
for i in lst:
	if not lst1:
		lst1.insert(0, i)
	elif len(lst1) < k:
		if i in lst1:
			pass
		else:
			lst1.insert(0, i)
	elif len(lst1) >= k:
		if i in lst1:
			pass
		else:
			lst1.pop()
			lst1.insert(0, i)
m = len(Counter(lst1).keys())
print(m)
for i in range(m):
	print(lst1[i], end=' ')


(n, k) = map(int, input().split())
msgs = list(map(int, input().split()))
scr = []
for m in msgs:
	if m in scr:
		pass
	else:
		if len(scr) == k:
			scr.pop()
		scr.insert(0, m)
print(len(scr))
print(*scr)


(x, y) = map(int, input().split())
m = [int(x) for x in input().split()]
mm = []
f = 0
for i in m:
	if f < y and mm.count(i) == 0:
		mm.insert(0, i)
		f = f + 1
	elif mm.count(i) != 0:
		continue
	else:
		mm.insert(0, i)
		mm.pop()
print(len(mm))
print(*mm, sep=' ')


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
l = []
for i in range(n):
	if a[i] not in l:
		l.append(a[i])
		if len(l) - 1 == k:
			del l[0]
l.reverse()
print(len(l))
print(*l)


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		from collections import deque
		(n, k) = invr()
		q = deque()
		d = {}
		a = inlt()
		c = 0
		for i in range(n):
			if a[i] not in d:
				d[a[i]] = 1
				q.appendleft(a[i])
				if c < k:
					c += 1
				else:
					del d[q.pop()]
		print(c)
		print(*q, sep=' ')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
from collections import deque
(n, k) = map(int, sys.stdin.readline().split())
n = input()
l = [int(i) for i in n.split()]
sol = deque(maxlen=k)
for i in l:
	if i not in sol:
		sol.appendleft(i)
print(len(sol))
for i in sol:
	print(i, end=' ')


from collections import deque
(n, k) = list(map(int, input().strip().split()))
deq = deque()
s = set()
for i in list(map(int, input().strip().split())):
	if i not in s:
		if len(deq) == k:
			s.remove(deq.pop())
		deq.appendleft(i)
		s.add(i)
print(len(deq))
print(*deq)


(n, k) = list(map(int, input().split()))
l1 = map(int, input().split())
l2 = []
for x in l1:
	if x in l2:
		continue
	else:
		l2.insert(0, x)
		if len(l2) > k:
			l2 = l2[:k]
print(len(l2))
for x in l2:
	print(x, end=' ')


import collections
(n, k) = input().split()
n = int(n)
k = int(k)
l = [int(x) for x in input().split()]
q = collections.deque(maxlen=k)
for s in l:
	if s not in q:
		q.appendleft(s)
print(len(q))
for i in q:
	print(i, end=' ')


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
i = 0
stack = []
s = set()
while i < n:
	if len(stack) == 0:
		stack.append(arr[i])
		s.add(arr[i])
		i += 1
	elif arr[i] in s:
		i += 1
	elif len(stack) <= m - 1:
		stack.append(arr[i])
		s.add(arr[i])
		i += 1
	else:
		s.remove(stack[-m])
		stack.append(arr[i])
		s.add(arr[i])
		i += 1
ans = stack[-m:][::-1]
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
indexes = list(map(int, input().split()))
a = []
for i in range(len(indexes)):
	if len(a) == k and indexes[i] not in a:
		a.pop()
		a = [0] + a
		a[0] = indexes[i]
	elif indexes[i] in a:
		continue
	else:
		a = [0] + a
		a[0] = indexes[i]
print(len(a))
print(' '.join(map(str, a)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = []
d = {}
for i in range(n):
	if len(m) != k:
		try:
			if d[l[i]] != 1:
				m.append(l[i])
		except KeyError:
			d[l[i]] = 1
			m.append(l[i])
	else:
		try:
			if d[l[i]] != 1:
				m.append(l[i])
				del d[m[0]]
				m.pop(0)
		except KeyError:
			d[l[i]] = 1
			m.append(l[i])
			del d[m[0]]
			m.pop(0)
s = ''
for i in range(len(m) - 1, -1, -1):
	s += str(m[i]) + ' '
print(len(m))
print(s)


(a, b) = map(int, input().split())
ar = list(map(int, input().split()))
ar1 = []
for i in ar:
	if i not in ar1:
		if len(ar1) == b:
			ele = ar1[0]
			ar1.remove(ele)
			ar1.append(i)
		else:
			ar1.append(i)
print(len(ar1))
print(*ar1[::-1])


(n, k) = list(map(int, input().split()))
id = list(map(int, input().split()))
screen = []
for i in range(n):
	if len(screen) < k:
		if id[i] not in screen:
			screen.insert(0, id[i])
	elif id[i] not in screen:
		screen = screen[:k - 1]
		screen.insert(0, id[i])
print(len(screen))
for i in screen:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
sc = []
for i in range(0, len(a)):
	if a[i] in sc:
		continue
	if len(sc) == k:
		sc.pop()
		sc = a[i:i + 1] + sc[:]
		continue
	sc = a[i:i + 1] + sc[:]
print(len(sc))
print(*sc)


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
ans = []
aa = set()
for i in range(n):
	if lis[i] not in aa:
		ans.append(lis[i])
		aa.add(lis[i])
		if len(ans) > k:
			g = ans.pop(0)
			aa.remove(g)
print(len(ans))
print(*ans[::-1])


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
import collections
b = collections.deque([])
d = {}
j = 0
for i in range(n):
	if a[i] not in d:
		d[a[i]] = 1
		b.appendleft(a[i])
		j = j + 1
		if j > k:
			cu = b.pop()
			del d[cu]
			j = j - 1
s = min(len(b), k)
print(s)
for i in range(s):
	print(b[i], end=' ')


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
sc = []
for x in ls:
	if x in sc:
		continue
	if len(sc) == k:
		sc = [x] + sc[:k - 1]
	else:
		sc = [x] + sc
print(len(sc))
print(' '.join(map(str, sc)))


from collections import deque
(x, y) = map(int, input().split())
(*li,) = map(int, input().split())
li1 = deque()
set1 = set()
for i in li:
	if i not in set1:
		if len(li1) == y:
			set1.discard(li1.pop())
		li1.appendleft(i)
		set1.add(i)
print(len(li1))
print(*li1)


(n, k) = map(int, input().split())
id = list(map(int, input().split()))
arr = []
count = 0
for i in id:
	if i not in arr:
		arr.append(i)
		count += 1
if count < k:
	print(count)
else:
	print(k)
arr2 = []
for j in id:
	if len(arr2) < k and j not in arr2:
		arr2.insert(0, j)
	elif j not in arr2:
		arr2.insert(0, j)
		del arr2[-1]
	else:
		continue
print(*arr2)


(n, k) = (int(x) for x in input().split())
b = list(map(int, input().split()))
q = []
s = 0
j = 0
while j < n:
	if s < k:
		if not b[j] in q:
			q.append(b[j])
			s += 1
	elif not b[j] in q:
		q.append(b[j])
		q.pop(0)
	j += 1
print(min(n, k, s))
print(*q[::-1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in a:
	if i not in b[-k:]:
		b.append(i)
b.reverse()
if len(b) < k:
	print(len(b))
	k = len(b)
else:
	print(k)
for i in range(k):
	print(b[i], end=' ')


import time
import collections
LOCAL = False
start_time = None
if LOCAL:
	start_time = time.time()
(n, k) = list(map(lambda x: int(x), input().split(' ')))
poses = list(map(lambda x: int(x), input().split(' ')))
q = collections.deque()
s = set()
for i in poses:
	if i not in s:
		if len(q) == k:
			removed = q.pop()
			s.remove(removed)
		q.appendleft(i)
		s.add(i)
print(len(q))
print(' '.join([str(i) for i in q]))
if LOCAL:
	print('--- %s seconds ---' % (time.time() - start_time))


n = input()
n = n.split()
n = list(map(int, n))
arr = input()
arr = arr.split()
arr = list(map(int, arr))
mapi = dict()
out = list()
cnt = 0
st = 0
for i in range(n[0]):
	if arr[i] not in mapi.keys():
		if cnt < n[1]:
			mapi[arr[i]] = 1
			out.append(arr[i])
			cnt += 1
		else:
			mapi.pop(out[st], None)
			st = st + 1
			mapi[arr[i]] = 1
			out.append(arr[i])
print(cnt)
for i in range(len(out) - 1, st - 1, -1):
	print(out[i], end=' ')


from collections import *
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
deq = deque()
for i in range(n):
	if len(deq) == k:
		if l[i] not in deq:
			deq.pop()
			deq.appendleft(l[i])
	elif l[i] not in deq:
		deq.appendleft(l[i])
print(len(deq))
print(*deq)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = set()
cur = set()
d = {}
r = 0
for i in range(n):
	if len(ans) < k and a[i] not in ans:
		d[a[i]] = len(ans)
		ans.add(a[i])
		cur.add((len(ans), a[i]))
		r = len(ans)
	elif a[i] not in ans:
		x = min(cur)
		cur.remove(x)
		ans.remove(x[1])
		ans.add(a[i])
		r += 1
		cur.add((r, a[i]))
print(len(cur))
for c in sorted(cur, reverse=True):
	print(c[1], end=' ')
print()


(n, k) = map(int, input().split())
id = [int(i) for i in input().split()]
scr = []
for i in range(n):
	if id[i] not in scr:
		scr = [id[i]] + scr[:k - 1]
ln = len(scr)
print(ln)
for i in range(ln):
	print(scr[i], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
window = []
contained = set()
for i in a:
	if i in contained:
		continue
	else:
		if len(window) == k:
			contained.remove(window[0])
			del window[0]
		window.append(i)
		contained.add(i)
print(len(window))
for i in range(len(window) - 1, -1, -1):
	print(window[i], end=' ')
print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = []
for i in a:
	if i not in s:
		s.append(i)
		if len(s) > k:
			s = s[1:len(s)]
s.reverse()
print(len(s))
print(*s)


from collections import deque
ints = list(map(int, input().split()))
(n, k) = (ints[0], ints[1])
conversations = list(map(int, input().split()))
screen = deque()
cache = {}
for i in range(len(conversations)):
	if conversations[i] in cache:
		continue
	if len(screen) >= k:
		remove = screen.popleft()
		cache.pop(remove)
		screen.append(conversations[i])
		cache[conversations[i]] = 1
	else:
		screen.append(conversations[i])
		cache[conversations[i]] = 1
print(len(screen))
screen.reverse()
print(*screen)


from sys import stdin
from collections import deque
import math
(n, k) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
myq = deque([])
myset = set()
for i in range(n):
	if arr[i] in myset:
		pass
	else:
		if len(myq) == k:
			el = myq[-1]
			myset.remove(el)
			myq.pop()
		myq.appendleft(arr[i])
		myset.add(arr[i])
print(len(myq))
print(*myq)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
(b, b1, m) = ([], set(), 0)
for i in a:
	if i not in b1:
		b.append(i)
		b1.add(i)
		if len(b1) > k:
			b1 -= {b[m]}
			m += 1
print(len(b) - m)
print(*reversed(b[m:]))


import collections
from collections import defaultdict
(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
de = collections.deque([])
cnt = defaultdict(lambda : 0)
for i in ids:
	if cnt[i] == 0:
		if len(de) == k:
			cnt[de[-1]] = 0
			de.pop()
			de.appendleft(i)
			cnt[i] = 1
		else:
			de.appendleft(i)
			cnt[i] = 1
print(len(de))
l = list(de)
print(*l)


import math
import array
arr1 = array.array('l', [])
arr2 = array.array('l', [])
arr3 = array.array('l', [])
arr1 = [int(j) for j in input().split()]
n = arr1[0]
k = arr1[1]
arr2 = [int(j) for j in input().split()]
for i in range(0, n, 1):
	a = arr2[i]
	if a in arr3:
		continue
	else:
		arr3.insert(0, a)
		l = len(arr3)
		if l > k:
			arr3.pop(-1)
l1 = len(arr3)
print(l1)
print(*arr3)


(count, limit) = list(map(lambda num: int(num), input().split()))
message = []
message = list(map(lambda num: int(num), input().split()))
queue = []
for m_id in message:
	if len(queue) < limit and (not str(m_id) in queue):
		queue.insert(0, str(m_id))
	elif len(queue) == limit:
		if str(m_id) in queue:
			continue
		else:
			queue.pop()
			queue.insert(0, str(m_id))
print(len(queue))
print(' '.join(queue))


(n, k) = map(int, input().split())
conv = list(map(int, input().split()))
scr = []
for i in range(n):
	if len(scr) <= k and conv[i] not in scr:
		scr.append(conv[i])
	while len(scr) > k:
		scr.pop(0)
scr.reverse()
sarr = [str(a) for a in scr]
print(len(scr))
print(' '.join(sarr))


(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
s = list(set(sorted(nums)))
r = {k: s.index(k) for k in s}
mark = []
for i in range(len(s)):
	mark.append(0)
vis = []
len = 0
l = 0
for num in nums:
	if mark[r[num]] == 0 and len < k:
		vis.append(num)
		mark[r[num]] = 1
		len += 1
	elif mark[r[num]] == 0 and len == k:
		vis.append(num)
		mark[r[num]] = 1
		mark[r[vis[l]]] = 0
		l += 1
print(min(len, k))
for i in range(l + len - 1, l - 1, -1):
	print(vis[i], end=' ')


from collections import deque

def solve(k, ids):
	mes = deque(maxlen=k)
	for i in ids:
		if i not in mes:
			mes.appendleft(i)
	return (len(mes), mes)
(n, k) = map(int, input().split())
ids = input().split()
(m, ids) = solve(k, ids)
print(m)
print(' '.join(ids))


(n, k) = map(int, input().split())
mem = set()
ret = []
arr = list(map(int, input().split()))
for v in arr:
	if v not in mem:
		ret = [v] + ret
		mem.add(v)
		if len(ret) > k:
			mem.remove(ret.pop(-1))
print(len(ret))
print(*ret)


(N, K) = map(int, input().split())
data = list(map(int, input().split()))
queue = []
st = set()
for i in data:
	if len(queue) < K:
		if i not in st:
			st.add(i)
			queue.append(i)
	elif i not in st:
		st.remove(queue[0])
		st.add(i)
		queue.append(i)
		queue.pop(0)
print(len(queue))
for i in range(len(queue)):
	print(queue[-i - 1], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
st = []
d = {}
for i in a:
	if d.get(i, 0) == 0:
		st.append(i)
		d[i] = 1
	if len(st) > k:
		d.pop(st.pop(0))
st = st[::-1]
print(len(st))
print(*st)


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = []
for i in range(n):
	if l1[i] in l2:
		pass
	elif len(l2) != k and l1[i] not in l2:
		l2.insert(0, l1[i])
	elif len(l2) == k and l1[i] not in l2:
		l2.insert(0, l1[i])
		l2.pop()
print(len(l2))
print(*l2)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
newl = []
f = 0
for i in l:
	if i not in newl[f:len(newl)]:
		if len(newl) - f >= k:
			f += 1
		newl.append(i)
print(len(newl) - f)
for i in range(len(newl) - 1, f - 1, -1):
	print(newl[i], end=' ')


(n, k) = map(int, input().split())
id1 = [int(i) for i in input().split()]
arr = []
ar_se = set()
for i in range(n):
	if id1[i] in ar_se:
		continue
	elif len(arr) == k:
		temp = arr.pop(0)
		arr.append(id1[i])
		ar_se.remove(temp)
		ar_se.add(id1[i])
	elif len(arr) < k:
		arr.append(id1[i])
		ar_se.add(id1[i])
	else:
		break
print(len(arr))
arr = arr[::-1]
print(*arr)


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
l1 = []
if n == 1:
	print(1)
	print(l[0])
else:
	for j in range(min(k, n)):
		if l[j] not in l1:
			l1.insert(0, l[j])
	for i in range(k, n):
		if l[i] not in l1:
			l1.insert(0, l[i])
			if len(l1) > k:
				l1.pop()
	print(len(l1))
	print(*l1)


(a, b) = map(int, input().strip().split())
d = []
for i in list(map(int, input().strip().split())):
	if i in d:
		pass
	else:
		d.insert(0, i)
		d = d[:b]
print(len(d))
for i in d:
	print(i, end=' ')
print()


import queue
m = input().split()
a = int(m[0])
b = int(m[1])
l = queue.Queue(maxsize=b)
e = input().split()
w = []
for j in range(a):
	e[j] = int(e[j])
	w.append(e[j])
for i in range(a):
	if w[i] not in l.queue:
		if l.full():
			l.get()
			l.put(w[i])
		else:
			l.put(w[i])
print(l.qsize())
d = []
for k in range(l.qsize()):
	d.append(l.get())
d.reverse()
for k in range(len(d)):
	print(d[k], end=' ')


(a, b) = [int(i) for i in input().split()]
c = list()
temp = [int(i) for i in input().split()]
for tmp in temp:
	if tmp in c:
		continue
	elif len(c) < b:
		c.reverse()
		c.append(tmp)
		c.reverse()
	else:
		c.pop()
		s = list()
		s.append(tmp)
		s.extend(c)
		c = s.copy()
print(len(c))
for i in c:
	print(i, end=' ')


__author__ = 'Esfandiar'
from collections import defaultdict, Counter, deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
res = deque()
tol = 0
for i in range(n):
	if a[i] not in res:
		if tol + 1 > k:
			res.pop()
			res.appendleft(a[i])
		else:
			res.appendleft(a[i])
			tol += 1
print(tol)
print(*res)


(n, k) = [int(i) for i in input().split()]
id = [int(i) for i in input().split()]
ans = []
for i in range(n):
	if len(ans) < k:
		if id[i] not in ans:
			ans.append(id[i])
	elif id[i] not in ans:
		ans.pop(0)
		ans.append(id[i])
print(len(ans))
print(*ans[::-1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
phone = []
fast = set()
length = 0
for i in a:
	if i not in fast:
		if length == k:
			fast.remove(phone[0])
			phone.pop(0)
			length -= 1
		phone.append(i)
		fast.add(i)
		length += 1
print(length)
print(*reversed(list(phone)))


import sys
import os
from io import IOBase, BytesIO

def main():
	(n, k) = get_ints()
	from collections import deque
	arr = deque()
	tmp = get_array()
	d = {}
	for i in tmp:
		if i in d:
			continue
		if len(arr) != 0:
			x = arr.popleft()
			arr.appendleft(x)
			arr.appendleft(i)
			d[x] = 1
			d[i] = 1
			if len(arr) > k:
				t = arr.pop()
				del d[t]
		else:
			arr.append(i)
			d[i] = 1
	print(len(arr))
	print(*arr)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()
main()


def mapIntInput():
	return map(int, input().split())
(n, k) = mapIntInput()
userIds = list(mapIntInput())
usersDict = {}
reverseChats = []
chats = []
allChatsCount = 1
for i in range(n):
	currentUser = userIds[i]
	lenChats = len(reverseChats)
	appendV = False
	if not usersDict.get(currentUser) or usersDict.get(currentUser) < allChatsCount - k:
		appendV = True
	if appendV:
		reverseChats.append(currentUser)
		usersDict[currentUser] = allChatsCount
		allChatsCount += 1
chats = reverseChats[-k:]
chats.reverse()
print(len(chats))
print(' '.join(map(str, chats)))


import math
(n, k) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
arr = []
arr.insert(0, a[0])
for i in range(1, n):
	if a[i] not in arr:
		arr.insert(0, a[i])
		if len(arr) > k:
			arr.pop(-1)
print(len(arr))
print(*arr, sep=' ')


import collections
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = collections.deque(maxlen=k)
for i in range(n):
	if l[i] not in d:
		d.append(l[i])
ans = list(d)[::-1]
print(len(ans))
sarr = [str(a) for a in ans]
print(' '.join(sarr))


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = [0 for i in range(k)]
for i in range(n):
	if ans.count(a[i]) == 0:
		ans = [a[i]] + ans
		ans = ans[:k]
s = []
for i in range(k):
	if ans[i]:
		s.append(ans[i])
print(len(s))
print(*s, sep=' ')


(n, k) = map(int, input().split())
list_ids = list(map(int, input().split()))
final_array = []
for id_val in list_ids:
	if id_val in final_array:
		continue
	elif len(final_array) < k:
		final_array.insert(0, id_val)
	else:
		final_array.insert(0, id_val)
		final_array.pop(k)
print(len(final_array))
print(*final_array)


a = list((int(x) for x in input().split()))
b = list((int(x) for x in input().split()))
k = min(a[1], len(set(b)))
l = []
print(k)
for i in b:
	if i not in l[-k:]:
		l.append(i)
for i in range(1, k + 1):
	print(l[-i], end=' ')


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = []
for el in A:
	if el not in s:
		if len(s) == k:
			s = s[1:]
		s.append(el)
print(len(s))
print(' '.join(map(str, s[::-1])))


(n, k) = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().strip().split()))
counter = 0
msg = []
for i in a:
	if i in msg:
		continue
	elif counter == k:
		msg.pop()
		msg.insert(0, i)
	else:
		msg.insert(0, i)
		counter += 1
print(counter)
print(*msg)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = []
simple = set([])
ans = set([])
l = -1
r = -1
for i in range(0, n):
	if l == -1 and r == -1:
		s.append(a[i])
		simple.add(a[i])
		l = 0
		r = 0
	elif a[i] not in simple:
		if r - l + 1 < k:
			s.append(a[i])
			simple.add(a[i])
			r += 1
		elif r - l + 1 == k:
			simple.remove(s[l])
			s.append(a[i])
			simple.add(a[i])
			r += 1
			l += 1
print(r - l + 1)
for i in range(r, l - 1, -1):
	print(s[i], end=' ')


from collections import OrderedDict, deque
for i in range(1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	q = deque()
	w = OrderedDict()
	c = 0
	for j in range(len(a)):
		w[a[j] - 1] = 0
	for j in range(len(a)):
		if w[a[j] - 1] == 0:
			q.appendleft(a[j])
			c = c + 1
			w[a[j] - 1] = 1
		if c > k:
			qw = q.pop()
			w[qw - 1] = 0
			c = c - 1
	print(len(q))
	print(*q)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = set()
ans = []
last = 0
for i in range(n):
	if a[i] not in c:
		if len(ans) < k:
			ans.append(a[i])
		else:
			c.remove(ans[last])
			ans.append(a[i])
			last += 1
		c.add(a[i])
print(min(len(ans), k))
for i in range(min(len(ans), k)):
	print(ans[-i - 1], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = [0] * k
for i in l:
	if i not in m:
		a = i
		for j in range(k):
			b = m[j]
			m[j] = a
			a = b
for i in range(k):
	if m[-1] == 0:
		m.pop()
print(len(m))
print(*m)


a = input().split()
n = int(a[0])
k = int(a[1])
ids = list(input().split())
T = list([])
ids_set = set(ids)
j = 0
if k == 1:
	print('1')
	print(ids[-1])
elif k < len(ids_set):
	ids_set = set()
	for i in ids:
		if i not in ids_set:
			ids_set.add(i)
			T.append(i)
			if len(T) > k:
				ids_set -= {T[j]}
				j += 1
	print(len(T) - j)
	B = T[j:]
	B.reverse()
	print(' '.join(B))
else:
	print(len(ids_set))
	T = []
	for i in ids:
		if i in ids_set:
			T.append(i)
			ids_set.remove(i)
			if len(ids_set) == 0:
				break
	T.reverse()
	print(' '.join(T))


from collections import deque
(n, k) = map(int, input().split())
ids = map(int, input().split())
screen = deque(maxlen=k)
screen_set = set()
for i in ids:
	if i in screen_set:
		continue
	if len(screen) == k:
		left = screen.pop()
		screen_set.remove(left)
	screen_set.add(i)
	screen.appendleft(i)
print(len(screen))
print(' '.join(map(str, screen)))


from collections import deque
import sys
(n, k) = list(map(int, sys.stdin.readline().split()))
ar = list(map(int, sys.stdin.readline().split()))
lol = deque([])
kek = set()
i = 0
for elem in ar:
	if elem not in kek:
		if i == k:
			i -= 1
			kek.discard(lol[-1])
			lol.pop()
		lol.appendleft(elem)
		kek.add(elem)
		i += 1
print(i)
print(' '.join(map(str, lol)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
l = []
for i in a:
	if i not in d:
		d[i] = 1
		if len(l) == k:
			del d[l[len(l) - 1]]
			del l[len(l) - 1]
		l.insert(0, i)
print(len(l))
for i in l:
	print(i, end=' ')


t = input()
t = t.split(' ')
n = int(t[0])
k = int(t[1])
a = []
s = list(map(int, input().split()))
for i in range(0, len(s)):
	if s[i] not in a:
		if len(a) == k:
			a = a[:-1]
		a.insert(0, s[i])
print(len(a))
a = list(a)
p = ''
for i in range(0, len(a)):
	p = p + str(a[i]) + ' '
p = p[:-1]
print(p)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(n, k) = sep()
	a = lis()
	have = {}
	queue = deque([])
	for i in range(n):
		if a[i] in have:
			continue
		elif len(queue) == k:
			temp = queue.pop()
			del have[temp]
			have[a[i]] = 1
			queue.appendleft(a[i])
		else:
			queue.appendleft(a[i])
			have[a[i]] = 1
	print(len(queue))
	print(' '.join((str(queue[i]) for i in range(len(queue)))))
testcase(1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
q = []
for i in range(n):
	if l[i] not in q:
		if len(q) == k:
			del q[-1]
		q.insert(0, l[i])
print(len(q))
print(*q)


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(s, q) = (set(), deque())
count = 0
for i in a:
	if i not in s:
		if count == k:
			t = q.pop()
			q.appendleft(i)
			s.remove(t)
			s.add(i)
		else:
			count += 1
			q.appendleft(i)
			s.add(i)
print(len(q))
for num in q:
	print(num, end=' ')


def convertCellData(inpt: str) -> (int, int):
	(message, converse) = inpt.split()
	return (int(message), int(converse))

def messageFun(msgLimit: int, cnvrseList: list, cnvrseLimit: int) -> str:
	phoneScreen = []
	cnvrseMem = []
	for msg in cnvrseList:
		if msg not in phoneScreen:
			if len(phoneScreen) >= msgLimit:
				phoneScreen.append(msg)
				phoneScreen.pop(0)
			else:
				phoneScreen.append(msg)
	return phoneScreen[::-1]

def main():
	cellData = input()
	(cnvrsLimit, msgLimit) = convertCellData(cellData)
	cnvrsData = input()
	cnvrsList = cnvrsData.split()
	answerList = messageFun(msgLimit, cnvrsList, cnvrsLimit)
	print(len(answerList))
	print(*answerList)
main()


ints = list(map(int, input().split()))
(n, k) = (ints[0], ints[1])
conversations = list(map(int, input().split()))
screen = []
cache = {}
for i in range(len(conversations)):
	if conversations[i] in cache:
		continue
	if len(screen) >= k:
		remove = screen.pop()
		cache.pop(remove)
		screen.insert(0, conversations[i])
		cache[conversations[i]] = 1
	else:
		screen.insert(0, conversations[i])
		cache[conversations[i]] = 1
print(len(screen))
print(*screen)


(n, k) = input().split()
(n, k) = (int(n), int(k))
h = list(map(int, input().split()))
a = []
for i in h:
	if a.count(i):
		pass
	else:
		if len(a) == k:
			del a[0]
		a.append(i)
s = a[::-1]
print(len(s))
for i in s:
	print(i, end=' ')


import sys
input = sys.stdin.readline
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = []
for i in a:
	if i in b:
		continue
	else:
		if len(b) == k:
			b.pop()
		b.insert(0, i)
print(len(b))
for i in b:
	print(i, end=' ')


(n, k) = [int(i) for i in input().split(' ')]
arr = [int(i) for i in input().split(' ')]
disSet = set()
display = []
count = 0
for a in arr:
	if a not in disSet:
		disSet.add(a)
		display.append(a)
		count += 1
		if count > k:
			disSet.remove(display[-k - 1])
			count -= 1
print(count)
for i in range(len(display) - 1, len(display) - 1 - min(k, count), -1):
	print(display[i], end=' ')


(n, k) = list(map(int, input().split()))
id = list(map(int, input().split()))
p = []
kick_one = False
for i in id:
	if len(p) == k:
		kick_one = True
	if len(p) == 0:
		p.append(i)
		continue
	if i not in p:
		if kick_one:
			p.pop()
			p.insert(0, i)
		else:
			p.insert(0, i)
	else:
		pass
print(len(p))
for i in p:
	print(i, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
conversation = []
for i in arr:
	if i not in conversation:
		if len(conversation) < k:
			conversation.append(i)
		elif len(conversation) == k:
			conversation.pop(0)
			conversation.append(i)
	else:
		continue
conversation.reverse()
print(len(conversation))
print(*conversation, sep=' ')


(n_sms, max_sms) = map(int, input().split())
a = list(map(int, input().split()))
stek = []
for x in a:
	if x in stek:
		continue
	stek.insert(0, x)
	if len(stek) > max_sms:
		stek.pop(-1)
print(len(stek))
res = ' '.join(map(str, stek))
print(res)


(n, k) = [int(x) for x in input().split()]
idd = list(map(int, input().split()))
msg = []
co = 0
dic = {}
for i in idd:
	dic[i] = 0
ans = 0
x = 0
for i in range(n):
	if co == k:
		if dic[idd[i]] == 0:
			dic[msg[x]] = 0
			x -= -1
			msg.append(idd[i])
			dic[idd[i]] = 1
	elif dic[idd[i]] == 0:
		msg.append(idd[i])
		dic[idd[i]] = 1
		co -= -1
		ans -= -1
msg = msg[::-1]
print(ans)
print(*msg[:k])


import collections
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
de = collections.deque(b)
de.append(a[0])
for i in range(1, len(a)):
	if len(de) <= k:
		if a[i] in de:
			continue
		else:
			if len(de) == k:
				de.pop()
			de.appendleft(a[i])
b = list(de)
print(len(b))
print(*b)


(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
ans = []
for i in ids:
	if i not in ans[-k:]:
		ans.append(i)
print(len(ans[-k:]))
ans_ = ''
for i in ans[:-k - 1:-1]:
	ans_ += str(i) + ' '
print(ans_)


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
convs = []
for i in ids:
	if str(i) in convs:
		continue
	if len(convs) == k:
		convs.pop(0)
		convs.append(str(i))
	else:
		convs.append(str(i))
print(len(convs))
print(' '.join(convs[::-1]))


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
s = set()
for i in range(n):
	if not a[i] in s:
		queue.appendleft(a[i])
		s.add(a[i])
		if len(queue) > k:
			removed = queue.pop()
			s.remove(removed)
print(len(queue))
print(*queue)


(a, b) = map(int, input().split())
p = list(map(int, input().split()))
(x, l) = ([], set())
for i in p:
	if i not in l:
		l.add(i)
		x.append(i)
	if len(x) > b:
		j = x.pop(0)
		l.remove(j)
print(len(x))
print(*x[::-1])


from collections import deque

def solution(arr, k: int) -> None:
	s = set()
	d = deque()
	for x in arr:
		if x not in s:
			if len(d) == k:
				s.discard(d.popleft())
			s.add(x)
			d.append(x)
	print(len(d))
	print(*reversed(d))

def main():
	(_, k) = map(int, input().split())
	arr = map(int, input().split())
	solution(arr, k)
main()


from collections import defaultdict as d
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = d(int)
b = [-1] * k
for i in a:
	if c[i] == 0:
		b.append(i)
		c[i] += 1
		c[b[-k - 1]] -= 1
b = b[k:][::-1]
print(min(k, len(b)))
print(*b[:k])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = []
x = 0
for i in l:
	if i not in s:
		s.append(i)
		x += 1
	if x > k:
		s.pop(0)
		x -= 1
print(x)
print(*s[::-1])


(n, k) = [int(x) for x in input().split()]
l = [int(y) for y in input().split()]
scr = []
s = set()
i = 0
for msg in l:
	if msg not in s:
		s.add(msg)
		scr.append(msg)
		if len(s) > k:
			s -= {scr[i]}
			i += 1
print(len(scr) - i)
print(*reversed(scr[i:]))


(n, k) = [int(ele) for ele in input().split()]
id1 = [int(ele) for ele in input().split()]
lst = []
size = 0
for ele in id1:
	if ele not in lst:
		if size < k:
			if size == 0:
				lst.append(ele)
			else:
				lst.insert(0, ele)
			size += 1
		else:
			lst.insert(0, ele)
			del lst[-1]
print(size)
for ele in lst:
	print(ele, end=' ')


inp = input().split()
n = int(inp[0])
k = int(inp[1])
ids = input().split()
ids = [int(x) for x in ids]
top = -1
arr = [None] * k
count = 0
for i in ids:
	if i in arr:
		continue
	if top == -1:
		top = 0
		arr[top] = i
		count += 1
		continue
	if top == k - 1:
		top = 0
		arr[top] = i
		count += 1
		continue
	top += 1
	arr[top] = i
	count += 1
if count > k:
	count = k
t = top
print(count)
for c in range(count):
	print(arr[t], end=' ')
	t -= 1
	if t == -1:
		t = count - 1


n = list(map(int, input().split()))
b = list(map(int, input().split()))
a = []
for i in b:
	if i in a:
		continue
	else:
		a.append(i)
		if len(a) > n[1]:
			a = a[1:]
a = list(reversed(a))
print(len(a))
print(*a)


(n, k) = map(int, input().split())
g = {}
s = list(map(int, input().split()))
h = []
for i in range(n):
	if not g.get(s[i]):
		if len(g) == k:
			g.pop(h.pop(-1))
		g[s[i]] = 1
		h = [s[i]] + h
print(len(h))
print(*h)


from collections import deque
(n, k) = (int(i) for i in input().split(' '))
ids = [int(i) for i in input().split(' ')]
current_screen_list = deque()
current_screen_set = set()
for _id in ids:
	if _id not in current_screen_set:
		if len(current_screen_set) == k:
			last = current_screen_list.pop()
			current_screen_set.discard(last)
		current_screen_list.appendleft(_id)
		current_screen_set.add(_id)
print(len(current_screen_list))
print(' '.join([str(i) for i in current_screen_list]))


from collections import defaultdict
import queue
(n, k) = map(int, input().split())
idarr = [int(j) for j in input().split()]
s = set({})
q = queue.Queue(maxsize=0)
ind = 0
while len(s) != k and ind != n:
	if idarr[ind] not in s:
		s.add(idarr[ind])
		q.put(idarr[ind])
	ind += 1
if ind != n:
	while ind != n:
		if idarr[ind] not in s:
			s.add(idarr[ind])
			a = q.get()
			s.remove(a)
			q.put(idarr[ind])
		ind += 1
	ans = []
	while not q.empty():
		ans += [q.get()]
	ans = ans[::-1]
	print(len(ans))
	print(*ans)
else:
	ans = []
	while not q.empty():
		ans += [q.get()]
	ans = ans[::-1]
	print(len(ans))
	print(*ans)


import sys
inf = float('inf')
from functools import reduce
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd, log10, atan, tan
from bisect import bisect_left, bisect_right, insort_left

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
Arr = get_array()
Q = deque()
mydict = dict()
length = 0
i = 0
while length < k and i < n:
	if Arr[i] not in mydict:
		mydict[Arr[i]] = 1
		Q.appendleft(Arr[i])
		length += 1
	else:
		mydict[Arr[i]] += 1
	i += 1
for j in range(i, n):
	if Arr[j] in mydict:
		mydict[Arr[j]] += 1
	else:
		mydict[Arr[j]] = 1
		Q.appendleft(Arr[j])
		length += 1
		while length > k:
			element = Q.pop()
			del mydict[element]
			length -= 1
print(len(Q))
for i in Q:
	print(i, end=' ')


lst = []
(n, k) = [int(x) for x in input().split()]
lst = [int(x) for x in input().split()]
import collections
de = collections.deque()
for i in range(n):
	if lst[i] not in de and len(de) >= k:
		de.pop()
		de.appendleft(lst[i])
	elif lst[i] not in de and len(de) < k:
		de.appendleft(lst[i])
print(len(de))
for i in de:
	print(i, end=' ')


from collections import deque
from collections import defaultdict
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
deq = deque()
di = defaultdict(lambda : 0)
for i in range(n):
	if di[a[i]] == 0:
		di[a[i]] = 1
		deq.appendleft(a[i])
		if len(deq) > k:
			x = deq.pop()
			di[x] = 0
print(len(deq))
print(*deq)


from collections import deque

def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	queue = deque()
	s = set()
	for i in range(n):
		if arr[i] not in s:
			if len(queue) < k:
				queue.appendleft(arr[i])
				s.add(arr[i])
			else:
				a = queue.pop()
				s.remove(a)
				queue.appendleft(arr[i])
				s.add(arr[i])
	print(len(queue))
	for i in range(len(queue)):
		print(queue[i], end=' ')
main()


from queue import deque
(n, k) = [int(x) for x in input().split()]
idi = [int(x) for x in input().split()]
q = deque()
container = set()
for i in range(n):
	x = idi[i]
	if x in container:
		continue
	else:
		if len(q) == k:
			container.remove(q.popleft())
		q.append(x)
		container.add(x)
q.reverse()
print(len(q))
print(' '.join([str(x) for x in q]))


p = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
k = p[1]
d = [a[0]]
for e in a[1:]:
	if e not in d:
		d.insert(0, e)
	if len(d) > k:
		del d[-1]
print(len(d))
print(' '.join(list(map(str, d))))


(n, k) = map(int, input().split())
a = []
d = list(map(int, input().split()))
for i in range(n):
	if d[i] not in a:
		if len(a) < k:
			a = [d[i]] + a
		else:
			a.remove(a[-1])
			a = [d[i]] + a
print(len(a))
for i in a:
	print(i, end=' ')


def line():
	return map(int, input().split())

def num():
	return int(input())
from collections import OrderedDict as od
(n, k) = line()
ids = list(line())
screen = od()
for id in ids:
	if id not in screen:
		if len(screen) == k:
			screen.popitem(last=False)
		screen[id] = None
print(len(screen))
print(' '.join(map(str, reversed(screen))))


from collections import deque
(n, k) = map(int, input().split())
q = deque()
s = set()
size = 0
for i in map(int, input().split()):
	if i in s:
		continue
	if size == k:
		s.remove(q.pop())
		size -= 1
	s.add(i)
	q.appendleft(i)
	size += 1
l = list(q)
print(len(l))
print(*l)


(n, k) = (int(i) for i in input().split(' '))
sta = []
for i in input().split(' '):
	ii = int(i)
	if len(sta) < k:
		if ii not in sta:
			sta.append(ii)
	elif ii not in sta:
		sta.pop(0)
		sta.append(ii)
print(len(sta))
while len(sta):
	print(sta.pop(), end=' ')


def main():
	(n, k) = map(int, input().rstrip().split())
	arr = list(map(int, input().rstrip().split()))
	msg = {}
	msglist = []
	currentk = 0
	for i in range(n):
		temp = msg.get(arr[i], 0)
		if temp == 0:
			msglist.insert(0, arr[i])
			msg[arr[i]] = 1
			currentk += 1
			if currentk > k:
				temp = msglist.pop(-1)
				msg[temp] = 0
				currentk -= 1
	print(currentk)
	for i in msglist:
		print(i, end=' ')
main()


(n, k) = input().split(' ')
n = int(n)
k = int(k)
datos = input().split(' ')
screen = []
for i in range(len(datos)):
	datos[i] = int(datos[i])
	if datos[i] not in screen and len(screen) < k:
		screen.insert(0, datos[i])
	elif len(screen) == k and datos[i] not in screen:
		screen.pop()
		screen.insert(0, datos[i])
print(len(screen))
for i in screen:
	print(i, end=' ')
print()


(n, k) = list(map(int, input().split()))
messages = list(map(int, input().split()))
result = []
visited = set()
for x in messages:
	if x not in visited:
		result.append(x)
		visited.add(x)
	if len(result) > k:
		a = result.pop(0)
		visited.remove(a)
result.reverse()
print(len(result))
print(' '.join(map(str, result)))


(n, k) = map(int, input().split())
sc = []
for x in list(map(int, input().split())):
	if x in sc:
		continue
	sc.insert(0, x)
	sc = sc[0:k]
print(len(sc))
print(' '.join(map(str, sc)))


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
(n, k) = mapin()
a = listin()
s = set([])
d = deque([])
for i in a:
	if len(d) < k:
		if i not in s:
			s.add(i)
			d.append(i)
	elif i not in s:
		s.remove(d.popleft())
		d.append(i)
		s.add(i)
print(len(d))
d = list(d)
d.reverse()
print(*d)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
lst = []
for i in a:
	if i not in lst:
		if len(lst) > k:
			break
		if len(lst) == 0:
			lst.append(i)
		elif len(lst) == k:
			lst.insert(0, i)
			lst.pop()
		else:
			lst.insert(0, i)
print(len(lst))
print(*lst)


from collections import deque

def main():
	(N, K, *A) = map(int, open(0).read().split())
	(length, in_q, q) = (0, set(), deque([]))
	for new in A:
		if new in in_q:
			continue
		length += 1
		(in_q.add(new), q.appendleft(new))
		if length > K:
			length -= 1
			removed = q.pop()
			in_q.discard(removed)
	print(length)
	print(' '.join(map(str, q)))
main()


x = input().split()
arr = input().split()
queue = []

def search(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return search(arr, l, mid - 1, x)
		else:
			return search(arr, mid + 1, r, x)
	else:
		return -1
d = {}
for a in range(0, len(arr)):
	arr[a] = int(arr[a])
	if not arr[a] in d:
		d[arr[a]] = False
	if len(queue) < int(x[1]) and arr[a] in d and (not d[arr[a]]):
		queue.append(arr[a])
		d[arr[a]] = True
	elif arr[a] in d and (not d[arr[a]]) and (len(queue) == int(x[1])):
		d[queue[0]] = False
		del queue[0]
		queue.append(arr[a])
		d[arr[a]] = True
queue.reverse()
print(len(queue))
st = ''
for each in queue:
	st += str(each) + ' '
print(st[:-1])


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = deque()
h = set()
for i in a:
	if i in h:
		continue
	if len(d) >= k:
		h.remove(d.pop())
	d.appendleft(i)
	h.add(i)
print(len(d))
print(*d)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = []
s = set()
for i in a:
	if len(d) < k:
		if i not in s:
			s.add(i)
			d.insert(0, i)
	elif len(d) == k:
		if i not in s:
			s.remove(d.pop())
			d.insert(0, i)
			s.add(i)
print(len(d))
print(*d)


(q, w) = map(int, input().split())
e = list(map(int, input().split()))
mn = []
for i in range(q):
	if e[i] not in mn:
		mn.append(e[i])
		if len(mn) > w:
			mn.pop(0)
n = len(mn)
print(n)
print(*mn[n:0:-1], end=' ')
print(mn[0])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
cnt = {}
j = 0
for i in range(len(a)):
	x = a[i]
	if x not in cnt:
		cnt[x] = 0
	if cnt[x] == 0:
		if j <= k - 1:
			b.append(x)
			cnt[x] += 1
			j += 1
		if j == k and cnt[x] == 0:
			cnt[b[0]] -= 1
			del b[0]
			b.append(x)
			cnt[x] += 1
print(len(b))
i = len(b) - 1
while i >= 0:
	print(b[i], end=' ')
	i -= 1
print()


(n, k) = map(int, input().split())
id = list(map(int, input().split()))
d = {}
for i in id:
	d[i] = 0
lis = [0] * k
l = 0
str = 0
end = 0
for i in id:
	if d[i] != 1:
		if l == k:
			t = lis[str]
			lis[str] = i
			str = (str + 1) % k
			end = str - 1
			if str == 0:
				end = n - 1
			d[i] = 1
			d[t] = 0
		else:
			end += 1
			lis[l] = i
			d[i] = 1
			l += 1
print(l)
if str == 0:
	for i in range(l - 1, -1, -1):
		print(lis[i], end=' ')
else:
	for i in range(end, -1, -1):
		print(lis[i], end=' ')
	for i in range(l - 1, str - 1, -1):
		print(lis[i], end=' ')


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	z = []
	for i in range(n):
		if not z.__contains__(a[i]):
			if len(z) == k:
				z.remove(z[0])
			z.append(a[i])
	print(len(z))
	z.reverse()
	print(*z)
try:
	solve()
except:
	pass


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
d = {i: False for i in arr}
cnt = 0
ans = []
for i in range(n):
	if d[arr[i]] == False:
		ans.append(arr[i])
		d[arr[i]] = True
		cnt += 1
	if cnt > k:
		d[ans.pop(0)] = False
		cnt -= 1
print(cnt)
print(*ans[::-1])


R = lambda : map(int, input().split())
(n, k) = R()
a = []
for x in R():
	if x not in a:
		a = [x] + a[:k - 1]
print(len(a))
print(*a)


(n, k) = map(int, input().split())
b = []
a = map(int, input().split())
s = set()
l = 0
for x in a:
	if x in s:
		continue
	if len(b) - l == k:
		s.remove(b[l])
		l += 1
	b.append(x)
	s.add(x)
b = b[l:][::-1]
print(len(b))
print(' '.join(map(str, b)))


(n, k) = input().split(' ')
n = int(n)
k = int(k)
ide = []
for e in input().split(' '):
	f = int(e)
	if f not in ide:
		ide.append(f)
		if len(ide) > k:
			ide.pop(0)
print(len(ide))
i = len(ide) - 1
while i >= 0:
	print(ide[i], end=' ')
	i -= 1
print()


(n, k) = map(int, str(input()).split())
a = list(str(input()).split())
s = []
for i in a:
	if i in s:
		pass
	else:
		s.insert(0, i)
		for j in range(k, len(s)):
			s.pop()
print(len(s))
print(' '.join(s))


def main():
	(n, k) = map(int, input().split())
	tab = list(map(int, input().split()))
	q = []
	seen = {}
	for item in tab:
		if not item in seen or (item in seen and seen[item] != 1):
			if len(q) == k:
				seen[q.pop(-1)] = 0
			q.insert(0, item)
			seen[item] = 1
	print(len(q))
	print(*q)
main()


(N, K) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
ans = min(len(set(A)), K)
print(ans)
B = []
for a in A:
	if a not in B:
		if len(B) == ans:
			B.pop()
			B.insert(0, a)
		else:
			B.insert(0, a)
ans = ' '.join((str(x) for x in B))
print(ans)


(n, k) = [int(x) for x in input().split()]
ids = [int(x) for x in input().split()]
notifications = []
for _id in ids:
	if _id in notifications:
		continue
	notifications.append(_id)
	if len(notifications) > k:
		notifications = notifications[1:]
m = len(notifications)
print(m)
print(' '.join([str(x) for x in notifications[::-1]]))


(n, k) = [int(j) for j in input().split()]
arr = [int(j) for j in input().split()]
b = []
d = dict()
for i in range(len(arr)):
	d[arr[i]] = 0
for i in range(len(arr)):
	if len(b) < k and d[arr[i]] == 0:
		b.append(arr[i])
		d[arr[i]] = 1
	elif d[arr[i]] == 0:
		d[b[0]] = 0
		d[arr[i]] = 1
		b.pop(0)
		b.append(arr[i])
print(len(b))
b.reverse()
print(*b, sep=' ')


(n, k) = list(map(int, input().split(' ')))
pms = list(map(int, input().split(' ')))
display = [0] * k
for i in pms:
	if i not in display:
		display.insert(0, i)
		display.pop()
print(k - display.count(0))
print(' '.join(list(map(str, display[0:k - display.count(0)]))))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
m = 0
for j in range(n):
	if l[j] not in ans:
		if m == k:
			ans.pop(0)
			ans.append(l[j])
		else:
			ans.append(l[j])
			m += 1
print(m)
for j in range(m - 1, -1, -1):
	print(ans[j], end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
screen = []
for i in arr:
	if len(screen) < k and i not in screen:
		screen = [i] + screen
	elif len(screen) >= k and i not in screen:
		screen.pop(k - 1)
		screen = [i] + screen
print(len(screen))
for i in screen:
	print(i, end=' ')


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
y = [] * k
a = len(y)
for i in x:
	if a < k:
		if i not in y:
			y.insert(0, i)
			a = len(y)
	elif i in y:
		continue
	else:
		y.pop()
		y.insert(0, i)
print(len(y))
for i in y:
	print(i, end=' ')


def add(m):
	if m not in mes:
		if len(mes) == k:
			del mes[0]
		mes.append(m)
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
mes = []
for i in range(n):
	add(ids[i])
mes.reverse()
print(len(mes))
for j in mes:
	print(j, end=' ')


(n, k) = [int(x) for x in input().split()]
l = list([int(x) for x in input().split()])
conv = {}
for i in range(n):
	conv[l[i]] = None
	if len(conv) > k:
		conv.pop(list(conv.keys())[0])
a = list(conv.keys())
a.reverse()
print(len(a))
for i in a:
	print(i, end=' ')


specs = input().split()
for i in range(len(specs)):
	specs[i] = int(specs[i])
k = specs[1]
order = input().split()
for i in range(len(order)):
	order[i] = int(order[i])
from collections import deque
queue = deque()
for i in range(len(order)):
	flag = 0
	for j in range(len(queue)):
		if order[i] == queue[j]:
			flag = 1
			break
	if flag == 0:
		if len(queue) == k:
			queue.popleft()
			queue.append(order[i])
		else:
			queue.append(order[i])
print(len(queue))
queue.reverse()
for x in queue:
	print(x, end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = [0] * 200005
d = {}
q = 200004
lns = 0
for t in l:
	if lns < k:
		val = d.get(t, 0)
		if val == 0:
			ans[q] = t
			d[t] = val + 1
			lns += 1
			q -= 1
	elif lns == k:
		val1 = d.get(t, 0)
		if val1 == 0:
			xc = ans[-1]
			vc = d.get(xc, 0)
			ans.pop(-1)
			d[xc] = vc - 1
			ans[q] = t
			q -= 1
			vb = d.get(t, 0)
			d[t] = vb + 1
print(lns)
for i in ans:
	if i > 0:
		print(i, end=' ')


a = list(map(int, input().split()))
c = list(map(int, input().split()))
b = a[1]
import collections

def f(A, k):
	d = set()
	ans = collections.deque([])
	for i in range(len(A)):
		if A[i] not in d:
			ans.appendleft(A[i])
			d.add(A[i])
			if len(ans) > k:
				temp = ans.pop()
				d.remove(temp)
	return [len(d), list(ans)]

def g(A):
	str1 = A[0]
	str2 = ''
	for i in A[1]:
		str2 = str2 + str(i) + ' '
	return [str1, str2]
temp = f(c, b)
temp2 = g(temp)
print(temp2[0])
print(temp2[1])


def main():
	(n, m) = map(int, input().split())
	l = input().split()
	(s, j) = (set(), 0)
	for (i, a) in enumerate(l):
		if a in s:
			l[i] = ''
		else:
			s.add(a)
			if len(s) > m:
				while not l[j]:
					j += 1
				s.remove(l[j])
				j += 1
	l = list(filter(None, l[::-1]))[:m]
	print(len(l))
	print(' '.join(l))
main()


from sys import stdin, stdout
nk = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
order = [0] * nk[1]
for i in arr:
	if i in order:
		continue
	else:
		for j in reversed(range(1, nk[1])):
			order[j] = order[j - 1]
		order[0] = i
count = 0
for j in order:
	if j != 0:
		count += 1
stdout.write(str(count) + '\n')
for j in order:
	if j != 0:
		stdout.write(str(j) + ' ')


(n, k) = map(int, input().split())
karr = list(map(int, input().split()))
arr = []
for i in karr:
	if len(arr) < k and i not in arr:
		arr.insert(0, i)
	elif len(arr) == k and i not in arr:
		arr.pop()
		arr.insert(0, i)
print(len(arr))
print(*arr)


from collections import deque
(message, chat) = map(int, input().split())
id = list(map(int, input().split()))
display = set()
current = deque()
for elem in id:
	if elem in display:
		continue
	if len(current) < chat:
		current.append(elem)
		display.add(elem)
	else:
		display.remove(current[0])
		current.popleft()
		current.append(elem)
		display.add(elem)
length = len(current)
print(length)
for i in range(length - 1, -1, -1):
	print(current[i], end=' ')


from math import *
from sys import *
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
ans.append(a[0])
for i in range(1, n):
	if len(ans) < k:
		if a[i] not in ans:
			ans.append(a[i])
	elif a[i] not in ans:
		ans.pop(0)
		ans.append(a[i])
print(len(ans))
print(*ans[::-1])


from collections import deque
import sys
current = set()
(n, k) = map(int, sys.stdin.readline().split())
arr = list(map(int, input().split()))
size = 0
queue = deque()
for i in arr:
	if i not in current:
		if size < k:
			size += 1
		else:
			current.discard(queue.pop())
		current.add(i)
		queue.appendleft(i)
print(size)
print(*queue)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
arr = []
d = {}
s = set(l)
for i in s:
	d[i] = 0
t = 0
for i in l:
	if d[i] == 1:
		continue
	elif t == k and d[i] == 0:
		z = arr.pop()
		d[z] = 0
		arr.insert(0, i)
		d[i] = 1
	elif t < k and d[i] == 0:
		t = t + 1
		d[i] = 1
		arr.insert(0, i)
print(t)
print(*arr)


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = set()
cur = set()
d = deque()
r = 0
for i in range(n):
	if len(ans) < k and a[i] not in ans:
		d.appendleft(a[i])
		ans.add(a[i])
	elif a[i] not in ans:
		x = d.pop()
		ans.remove(x)
		ans.add(a[i])
		d.appendleft(a[i])
print(len(ans))
for c in d:
	print(c, end=' ')
print()


(n, k) = list(map(int, input().split()))
messages = list(map(int, input().split()))
import collections
a = collections.deque()
current_conv = {}
nb_conv = 0
for message in messages:
	if message in current_conv:
		continue
	elif nb_conv == k:
		conv_to_delete = a.pop()
		del current_conv[conv_to_delete]
		a.appendleft(message)
		current_conv[message] = 1
	else:
		a.appendleft(message)
		nb_conv += 1
		current_conv[message] = 1
print(nb_conv)
print(' '.join([str(a.popleft()) for i in range(nb_conv)]))


from collections import deque
(n, k) = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
(result, used) = (deque(), set())
for elem in lst:
	if elem in used:
		continue
	else:
		if len(result) >= k:
			s = result.pop()
			used.remove(s)
		result.appendleft(elem)
		used.add(elem)
print(len(result))
print(*result)


(n, k) = tuple(map(int, input().split()))
id = list(map(int, input().split()))
l = []
d = {}
i = 0
while i < n:
	if id[i] not in d or d[id[i]] == 0:
		if len(l) < k:
			l.append(id[i])
		else:
			t = l[0]
			l.remove(l[0])
			l.append(id[i])
			d[t] = 0
		d[id[i]] = 1
	i += 1
print(len(l))
for i in reversed(range(len(l))):
	print(l[i], end=' ')
print()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
msg = []
msg_len = 0
for q in arr:
	if q not in msg:
		msg = [q] + msg
		msg_len += 1
		if msg_len > k:
			msg.pop()
			msg_len -= 1
print(msg_len)
for i in range(msg_len):
	print(msg[i], end=' ')


from collections import deque
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = deque()
d = dict()
limit = 0
for i in range(n):
	if l[i] in d.keys():
		if d[l[i]]:
			continue
		else:
			d[l[i]] = 1
			ans.appendleft(l[i])
			limit += 1
			if limit > k:
				x = ans.pop()
				d[x] = 0
				limit -= 1
	else:
		d[l[i]] = 1
		ans.appendleft(l[i])
		limit += 1
		if limit > k:
			x = ans.pop()
			d[x] = 0
			limit -= 1
print(limit)
print(*ans)


from collections import deque
arg = list(map(int, input().split()))
arr = list(map(int, input().split()))
check = set()
q = deque()
for i in arr:
	if i not in check:
		check.add(i)
		q.appendleft(i)
		if len(q) > arg[1]:
			a = q.pop()
			check.discard(a)
print(len(q))
for i in q:
	print(i, end=' ')


(x, y) = map(int, input().split())
l1 = list(map(int, input().split()))
l = []
for i in l1:
	if len(l) < y:
		if len(l) == 0:
			l.append(i)
		elif i not in l:
			l.append(i)
	elif i not in l:
		l.pop(0)
		l.append(i)
l = l[::-1]
print(len(l))
print(*l)


def solve(n, k, ar):
	dp = []
	dp.append(ar[0])
	for i in range(1, n):
		if ar[i] not in dp and len(dp) < k:
			dp.insert(0, ar[i])
		elif ar[i] in dp:
			continue
		elif ar[i] not in dp and len(dp) == k:
			dp.pop()
			dp.insert(0, ar[i])
	print(len(dp))
	print(' '.join(map(str, dp)))
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
solve(n, k, ar)


(n, k) = list(map(int, input().split()))
Id = list(map(int, input().split()))
B = []
for i in range(n):
	if Id[i] not in B:
		if len(B) >= k:
			del B[0]
			B.append(Id[i])
		else:
			B.append(Id[i])
print(len(B))
print(*B[::-1])


import sys
[n, k] = [int(j) for j in sys.stdin.readline().split()]
id_arr = [int(j) for j in sys.stdin.readline().split()]
ans_arr = []
ptr = 0
if n <= k:
	d = {}
	for x in range(n):
		if id_arr[x] not in d:
			ans_arr.append(id_arr[x])
			d[id_arr[x]] = 1
else:
	d = {}
	count = 0
	for x in range(n):
		if id_arr[x] not in d or d[id_arr[x]] == 0:
			if count >= k:
				d[ans_arr[ptr]] = 0
				ptr += 1
				ans_arr.append(id_arr[x])
			else:
				ans_arr.append(id_arr[x])
				count += 1
			d[id_arr[x]] = 1
ans_arr.reverse()
print(len(ans_arr) - ptr)
for w in range(len(ans_arr) - ptr):
	print(ans_arr[w], end=' ')
print()


(n, k) = [int(x) for x in input().split()]
messages = [int(x) for x in input().split()]
curr = {}
array = [0] * (n + 1)
no = 0
p = n
for i in range(n):
	if messages[i] in curr:
		continue
	elif no == k:
		x = array.pop()
		del curr[x]
		array[p] = messages[i]
		p -= 1
		curr[messages[i]] = 1
	else:
		no += 1
		array[p] = messages[i]
		p -= 1
		curr[messages[i]] = 1
print(len(array) - array.count(0))
for i in range(len(array)):
	if array[i] != 0:
		print(array[i], end=' ')


n = input()
(n, k) = n.split()
(n, k) = (int(n), int(k))
a = input()
a = [int(x) for x in a.split()]
has = {}
f = []
for x in a:
	if x in has.keys() and has[x]:
		continue
	elif len(f) == k:
		t = f[-1]
		has[t] = False
		f = [x] + f[:-1]
		has[x] = True
	else:
		has[x] = True
		f = [x] + f
print(len(f))
for x in f:
	print(x, end=' ')


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = deque()
	t = defaultdict(lambda : 0)
	for i in range(n):
		if t[a[i]] == 0:
			ans.appendleft(a[i])
			t[a[i]] += 1
		if len(ans) > k:
			x = ans.pop()
			t[x] -= 1
	print(len(ans))
	print(*ans)
solve()


(n, k) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
maxIndex = 0
d = dict()
for i in l:
	if i not in d or d[i] < maxIndex - k:
		d[i] = maxIndex
		maxIndex += 1
finalItems = []
for i in d:
	if d[i] >= maxIndex - k:
		finalItems.append((d[i], i))
finalItems.sort(reverse=True)
ans = []
for i in finalItems:
	ans.append(str(i[1]))
print(len(ans))
print(' '.join(ans))


(n, k) = input().split()
messages = input().split()
view = []
for message in messages:
	if message not in view:
		if len(view) != 0 and len(view) == int(k):
			view.pop()
		view.insert(0, message)
print(len(view))
for message in view:
	if message == view[-1]:
		print(message)
	else:
		print(message, end=' ')


import collections
(x, k) = map(int, input().split())
li = list(input().split())
s = set()
converstaion = collections.deque([])
for id in li:
	if id not in s:
		converstaion.appendleft(id)
		s.add(id)
		if len(converstaion) > k:
			s.discard(converstaion.pop())
print(len(converstaion))
print(*converstaion)


from collections import defaultdict
(n, k) = map(int, input().split())
id = list(map(int, input().split()))
a = [None for i in range(k)]
d = defaultdict(int)
for i in id:
	if d[i] == 0:
		d[a[-1]] = 0
		a = [i] + a[:-1]
		d[i] = 1
cnt = 0
b = []
for i in a:
	if i != None:
		cnt += 1
		b.append(i)
print(cnt)
for i in b:
	print(i, end=' ')


import math
import bisect
from functools import reduce
from collections import defaultdict

def inn():
	return int(input())

def inl():
	return list(map(int, input().split()))
MOD = 10 ** 9 + 7
INF = inf = 10 ** 18 + 5
(n, k) = inl()
idd = inl()
qu = [0] * k
lq = 0
st = n
en = n
d = {}
keys = set(idd)
for i in keys:
	d[i] = 0
for i in range(n):
	if d[idd[i]] == 0:
		if lq == k:
			en = (en - 1 + k) % k
			d[qu[en]] = 0
			lq -= 1
		d[idd[i]] = 1
		st = (st + k - 1) % k
		qu[st] = idd[i]
		lq += 1
print(lq)
for i in range(lq):
	print(qu[(st + i) % k], end=' ')


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
msgs = []
for a in A:
	if a not in msgs:
		if len(msgs) == k:
			msgs.pop(0)
		msgs.append(a)
print(len(msgs))
print(*msgs[::-1])


(n, k) = input().split()
n = int(n)
k = int(k)
m = input().split()
a = []
for i in range(n):
	if len(a) < k:
		if a.count(m[i]) == 0:
			a.insert(0, m[i])
	elif a.count(m[i]) == 0:
		a.insert(0, m[i])
		a.pop()
print(len(a))
for i in a:
	print(i, end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = [l[0]]
p = 0
for i in l:
	if p == 0 or i not in s:
		if len(s) != k:
			s = [i] + s
		else:
			s.pop()
			s = [i] + s
		p = p + 1
	elif i in s:
		s = s
a = []
b = set()
for i in s:
	if i not in b:
		a.append(i)
		b.add(i)
print(len(a))
for i in a:
	print(i, end=' ')


from collections import deque
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
d = deque()
s = set()
for v in arr:
	if v in s:
		continue
	d.append(v)
	s.add(v)
	if len(d) > k:
		s.remove(d.popleft())
print(len(d))
print(*reversed(d))


from collections import deque as dq
(a, b) = map(int, input().split())
l = list(map(int, input().split()))
v = dq([])
s = set()
for i in l:
	if i in s:
		pass
	else:
		if len(v) == b:
			k = v.pop()
			s.remove(k)
		v.appendleft(i)
		s.add(i)
print(len(v))
print(*v)


from collections import deque

def run():
	size = 0
	arr = deque()
	arr_s = set()
	(n, k) = map(int, input().split())
	i = 0
	read = input().split()
	for i in read:
		num = int(i)
		if num not in arr_s:
			arr_s.add(num)
			if size >= k:
				x = arr.popleft()
				arr_s.remove(x)
				arr.append(num)
			else:
				arr.append(num)
				size += 1
	print('{}\n{}'.format(len(arr), ' '.join((str(i) for i in deque(reversed(arr))))))
run()


import re, math, decimal, bisect, heapq

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
(n, m) = viread()
in_queue = set()
queue = []
for i in input().strip().split():
	if i not in in_queue:
		if len(queue) == m:
			in_queue.remove(queue.pop(0))
		in_queue.add(i)
		queue.append(i)
print(len(queue))
print(' '.join(queue[::-1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
z = []
for i in a:
	if i not in z:
		if len(z) < k:
			z.insert(0, i)
		else:
			z.pop()
			z.insert(0, i)
print(len(z))
for i in z:
	print(i, end=' ')


(n, k) = map(int, input().split())
ids = [int(x) for x in input().split()]
a = {}
for x in ids:
	if x in a:
		continue
	if len(a) == k:
		for key in a.keys():
			del a[key]
			break
	a[x] = 0
print(len(a))
print(*reversed(list(a.keys())))


(num_de_msg, num_de_cvs) = map(int, input().split())
ids_das_msgs = list(map(str, input().split()))
dicionario = {}
posicao_correta = []
for i in ids_das_msgs:
	dicionario[i] = -1
for i in ids_das_msgs:
	if dicionario[i] == -1:
		dicionario[i] = 1
		posicao_correta.append(i)
		if len(posicao_correta) > num_de_cvs:
			dicionario[posicao_correta.pop(0)] = -1
num_final = len(posicao_correta)
ids_final = ''
for i in reversed(posicao_correta):
	ids_final += i + ' '
print(num_final)
print(ids_final)


from collections import OrderedDict
(n, k) = map(int, input().split())
mes = OrderedDict()
buff = list(map(int, input().split()))
for x in buff:
	if x not in mes:
		if len(mes) < k:
			mes[x] = 1
			mes.move_to_end(x, last=False)
		else:
			mes.popitem()
			mes[x] = 1
			mes.move_to_end(x, last=False)
print(len(mes))
print(*list(mes.keys()))


(n, k) = list(map(int, input().split()))
iD = list(map(int, input().split()))
iDs = []
a1 = min(len(set(iD)), k)
print(a1)
for i in range(n):
	if iD[i] not in iDs:
		iDs.insert(0, iD[i])
		if len(iDs) > a1:
			iDs.pop()
for i in iDs:
	print(i, end=' ')


import sys
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
SET = set()
from collections import deque
Q = deque()
for a in A:
	if a in SET:
		continue
	elif len(Q) == k:
		x = Q.pop()
		SET.remove(x)
		Q.appendleft(a)
		SET.add(a)
	else:
		SET.add(a)
		Q.appendleft(a)
print(len(Q))
print(*Q)


import sys
import os
from io import IOBase, BytesIO
import math
import collections
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	(n, k) = map(int, sin().split())
	ids = ain()
	q = collections.deque()
	dic = dict.fromkeys(ids, 0)
	for id in ids:
		if len(q) < k and dic[id] == 0:
			q.appendleft(id)
			dic[id] = 1
		elif dic[id] == 0:
			dic[q.pop()] = 0
			q.appendleft(id)
			dic[id] = 1
	print(len(q))
	print(*q)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = []
for i in range(len(a)):
	if a[i] not in x:
		x.append(a[i])
		if len(x) > k:
			x.remove(x[0])
print(len(x))
if len(x) != 0:
	for i in range(len(x) - 1, -1, -1):
		print(x[i], end='')
		print(' ', end='')
	print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
lst = []
for num in a:
	if num not in lst:
		lst.insert(0, num)
	if len(lst) > k:
		lst.pop()
print(len(lst))
for num in lst:
	print(num, end=' ')


(n, k) = list(map(int, input().split(' ')))
lastSeen = {}
curr = 0
arr = list(map(int, input().split(' ')))
for i in arr:
	if i in lastSeen:
		if curr - lastSeen[i] > k:
			lastSeen[i] = curr
			curr += 1
	else:
		lastSeen[i] = curr
		curr += 1
import operator
sorted_x = sorted(lastSeen.items(), key=operator.itemgetter(1), reverse=True)
ans = list(map(lambda x: str(x[0]), sorted_x))
ans = ans[:k]
print(len(ans))
print(' '.join(ans))


(n, k) = map(int, input().split())
l = []
d = {}
for x in input().split():
	if not d.get(int(x)):
		if len(l) == k:
			del d[l.pop(0)]
			l.append(int(x))
			d[int(x)] = 1
		else:
			l.append(int(x))
			d[int(x)] = 1
print(len(l))
for i in range(len(l) - 1, -1, -1):
	print(l[i], end=' ')


from collections import deque, defaultdict
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
screen = deque()
id_dict = defaultdict(int)
f = len
for item in ids:
	if id_dict[item]:
		continue
	else:
		if f(screen) == k:
			id_dict[screen.popleft()] = 0
		screen.append(item)
		id_dict[item] = 1
print(len(screen))
print(*list(screen)[::-1])


import sys
input = sys.stdin.readline
from collections import *
(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
display = deque()
friends = set()
for id in ids:
	if id not in friends:
		if len(display) == k:
			out = display.pop()
			friends.remove(out)
		display.appendleft(id)
		friends.add(id)
print(len(display))
print(*display)


x = input()
x_ = x.split()
y = input()
y_ = y.split()
y__ = [int(d) for d in y_]
convo_vis = int(x_[1])
k = []
i = 0
for j in range(len(y__)):
	if y__[j] not in k and len(k) < convo_vis:
		k.append(y__[j])
	elif y__[j] not in k and len(k) == convo_vis:
		k.append(y__[j])
		k.remove(k[0])
		continue
	elif y__[j] in k:
		continue
k.reverse()
print(len(k))
print(*k)


(n, k) = map(int, input().split())
convs = list(map(int, input().split()))
x = []
size = 0
window = {}
for conv in convs:
	if conv not in window or not window[conv]:
		window[conv] = True
		if size == k:
			window[x[0]] = False
			del x[0]
		elif size < k:
			size += 1
		x.append(conv)
print(size)
print(*x[::-1])


from collections import deque
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
q = deque(maxlen=k)
for i in arr:
	if i not in q:
		q.append(i)
print(len(q))
for i in range(len(q)):
	print(q[len(q) - i - 1], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
i = 0
d = {}
while i < n:
	try:
		if d[a[i]] == 1:
			i += 1
			continue
	except:
		pass
	if len(b) < k:
		b.append(a[i])
		d[a[i]] = 1
	else:
		d[b[0]] = 0
		del b[0]
		b.append(a[i])
		d[a[i]] = 1
	i += 1
print(len(b))
print(*b[::-1])


import queue
(n, k) = map(int, input().split())
id = list(map(int, input().split()))
d = {}
for i in id:
	d[i] = 0
q = queue.Queue(k)
l = 0
for i in id:
	if d[i] != 1:
		if l == k:
			d[q.get()] = 0
			q.put(i)
			d[i] = 1
		else:
			q.put(i)
			d[i] = 1
			l += 1
print(l)
lis = list(q.queue)
for i in range(l - 1, -1, -1):
	print(lis[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ul = []
for i in l:
	if i not in ul:
		if len(ul) == k:
			ul.pop(0)
		ul.append(i)
print(len(ul))
print(*reversed(ul))


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
aa = []
for i in a:
	if i in aa:
		continue
	if len(aa) >= k:
		aa.pop()
	aa.insert(0, i)
print(len(aa))
print(*aa)


from collections import deque
line = input().split(' ')
n = int(line[0])
k = int(line[1])
all_id_list = input().split(' ')
displayed = deque(maxlen=k)
for (index, _id) in enumerate(all_id_list):
	if _id not in displayed and len(displayed) <= k:
		displayed.appendleft(_id)
	if _id in displayed and len(displayed) <= k:
		pass
	else:
		displayed.pop()
		displayed.appendleft(_id)
print(len(displayed))
for _id in displayed:
	print(_id, end=' ')


(n, k) = list(map(int, input().split()))
L = list(map(int, input().split()))
L1 = []
for i in range(len(L)):
	if L[i] in L1:
		continue
	elif len(L1) < k:
		L1.append(L[i])
	else:
		L1.append(L[i])
		L1 = L1[1:]
print(len(L1))
for i in range(len(L1) - 1, -1, -1):
	print(L1[i], end=' ')


import heapq
(n, k) = map(int, input().split())
a = [int(o) for o in input().split()]
h = []
s = set()
j = 0
for i in range(n):
	if a[i] not in s:
		heapq.heappush(h, [i, a[i]])
		j += 1
		s.add(a[i])
		if j > k:
			j -= 1
			lol = heapq.heappop(h)
			s.remove(lol[1])
st = []
while h:
	st.append(heapq.heappop(h)[1])
st = st[::-1]
print(len(st))
print(*st)


(n, k) = map(int, input().split())
a = map(int, input().split())
lt = dict()
timer = 0
for Id in a:
	if Id not in lt:
		lt[Id] = -k
	cur_time = lt[Id]
	if cur_time <= timer - k:
		timer += 1
		lt[Id] = timer
screen = list(lt.items())
screen.sort(key=lambda t: -t[1])
screen = screen[:min(n, k)]
print(len(screen))
for v in screen:
	print(v[0], end=' ')
print()


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
poruke = []
unutra = set()
for i in ids:
	if i not in unutra:
		poruke.append(i)
		unutra.add(i)
		if len(poruke) > k:
			unutra.remove(poruke[0])
			poruke.pop(0)
poruke.reverse()
print(len(poruke))
print(*poruke)


(n, k) = map(int, input().split())
r = list(map(int, input().split()))
l = []
for i in r:
	if i not in l and len(l) == k:
		l.pop(0)
		l.append(i)
	elif i not in l and len(l) < k:
		l.append(i)
print(len(l))
print(*l[::-1])


(n, k) = map(int, input().split())
id_array = [int(x) for x in input().split()]
now = []
now_cnt = 0
for id in id_array:
	if id in now:
		continue
	now_cnt += 1
	if now_cnt <= k:
		now.append(id)
	else:
		now.pop(0)
		now_cnt -= 1
		now.append(id)
print(now_cnt)
print(' '.join([str(x) for x in now[::-1]]))


from math import *
from itertools import *
from collections import *
from bisect import *
(n, k) = map(int, input().split())
lst = [int(x) for x in input().split()]
st = set()
q = deque([], k)
for i in lst:
	if i in st:
		continue
	else:
		if len(q) == k:
			st.remove(q.popleft())
		q.append(i)
		st.add(i)
print(len(q))
print(*reversed(q), sep=' ')


from collections import deque
(n, k) = list(map(int, input().split()))
seen = set()
msgs = deque()
inputs = list(map(int, input().split()))
for v in inputs:
	s = len(seen)
	seen.add(v)
	if len(seen) > s:
		msgs.append(v)
	if len(msgs) > k:
		o = msgs.popleft()
		seen.remove(o)
print(len(msgs))
for i in reversed(list(msgs)):
	print(i, end=' ', flush=True)


(n, k) = map(int, input().split())
ids = input().split()
hash = set()
stack = []
stack_init = 0
for i in ids:
	if i in hash:
		continue
	hash.add(i)
	stack.append(i)
	if len(stack) - stack_init > k:
		last = stack[stack_init]
		hash.remove(last)
		stack_init += 1
m = len(stack) - stack_init
print(m)
res = []
stack_last_id = len(stack) - 1
for i in range(1, m + 1):
	res.append(stack[-i])
print(' '.join(res))


(n, k) = input().split()
n = int(n)
k = int(k)
msg = input().split()
ha = {}
q = []
for i in msg:
	ha[i] = False
for i in msg:
	if ha[i] == False:
		ha[i] = True
		q.insert(0, i)
		if len(q) == k + 1:
			ha[q.pop(k)] = False
ans = ''
for i in q:
	ans += str(i) + ' '
print(len(q))
print(ans)


ent = input().split(' ')
n = int(ent[0])
k = int(ent[1])
atual = -1
tela = set()
tela2 = []
menssagens = input().split(' ')
for i in range(n):
	atual = int(menssagens[i])
	grupo = set()
	grupo.add(atual)
	if grupo.isdisjoint(tela):
		if len(tela) < k:
			tela.add(atual)
			tela2.append(atual)
		else:
			remover = tela2[0]
			tela2.remove(remover)
			tela.remove(remover)
			tela.add(atual)
			tela2.append(atual)
t = len(tela2)
print(t)
for u in range(t):
	if u != t - 1:
		print(tela2[t - 1 - u], end=' ')
	else:
		print(tela2[t - 1 - u])


from collections import deque
mydeq = deque()
myset = set()
(size, k) = [int(x) for x in input().split()]
for val in [int(x) for x in input().split()]:
	if val not in myset:
		mydeq.appendleft(val)
		myset.add(val)
		if len(mydeq) > k:
			myset.remove(mydeq.pop())
print(len(mydeq))
print(*mydeq)


(n, d) = map(int, input().split())
l = list(map(int, input().split()))
l1 = [0] * n
si = n - 1
ei = n - 1
dt = {}
c = 0
for i in l:
	if i not in dt:
		dt[i] = 1
		l1[si] = i
		si -= 1
		c += 1
		if c > d:
			del dt[l1[ei]]
			ei -= 1
			c -= 1
print(ei - si)
for i in range(si + 1, ei + 1):
	print(l1[i], end=' ')


a = list(map(int, input().split()))
k = a[1]
l = list(map(int, input().split()))
ll = []
for i in l:
	if i not in ll:
		if len(ll) < k:
			ll.append(i)
		else:
			ll.pop(0)
			ll.append(i)
print(len(ll))
ll.reverse()
for i in ll:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = [0] * k
for i in a:
	if i not in l:
		del l[0]
		l.append(i)
m = [i for i in l if i != 0]
print(len(m))
for i in reversed(m):
	print(i, end=' ')


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	scr = []
	for idf in a:
		if idf in scr:
			continue
		else:
			if len(scr) == k:
				del scr[-1]
			scr.reverse()
			scr.append(idf)
			scr.reverse()
	print(len(scr))
	print(' '.join(map(str, scr)))
main()


from collections import deque
(a, b) = map(int, input().split())
li = list(map(int, input().split()))
s = set()
l = deque([])
le = 0
for i in li:
	if i in s:
		pass
	elif le < b:
		le += 1
		s.add(i)
		l.appendleft(i)
	else:
		s.remove(l.pop())
		s.add(i)
		l.appendleft(i)
print(len(l))
print(*list(l))


import sys
import queue
(n, k) = map(int, sys.stdin.readline().split(' '))
q = queue.Queue(k + 1)
seen = set()
q_size = 0
for m in map(int, sys.stdin.readline().split(' ')):
	if m not in seen:
		if q_size < k:
			q.put(m)
			q_size += 1
			seen.add(m)
		else:
			v = q.get()
			seen.remove(v)
			q.put(m)
			seen.add(m)
result = []
while not q.empty():
	result.append(q.get())
print(len(result))
print(' '.join(map(str, result[::-1])))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = []
b = []
for i in range(k):
	b.append(0)
for i in range(n):
	if a[i] not in b:
		b.pop()
		b.insert(0, a[i])
j = 0
for i in range(len(b)):
	if b[i] != 0:
		j += 1
print(j)
for i in range(len(b)):
	if b[i] != 0:
		print(b[i], end=' ')


(n, k) = map(int, input().split())
numbers = [*map(int, input().split())]
(ans, l) = ([0] * k, 0)
for i in numbers:
	if l < k and i not in ans:
		ans[k - l - 1] = i
		l += 1
	elif i in ans:
		continue
	else:
		ans = [i] + ans[:-1]
print(min(len(set(numbers)), k))
print(*[x for x in ans if x])


x = [int(i) for i in input().split()]
(n, k) = (x[0], x[1])
li = [int(i) for i in input().split()]
h = set()
ans = []
for i in li:
	if i not in h:
		if len(h) < k:
			h.add(i)
			ans.insert(0, i)
		else:
			ans.insert(0, i)
			ans.pop()
			h = set(ans)
print(len(ans))
print(*ans, end=' ')


from collections import deque
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
q = deque()
s = set()
for i in range(n):
	if l[i] not in s:
		if len(q) < k:
			q.append(l[i])
			s.add(l[i])
		else:
			x = q.popleft()
			s.remove(x)
			q.append(l[i])
			s.add(l[i])
print(len(q))
ans = []
while len(q) > 0:
	ans.append(q.popleft())
ans.reverse()
print(*ans)


(n, k) = map(int, input().split())
lis = []
arr = list(map(int, input().split()))
for j in range(n):
	if arr[j] not in lis:
		lis.insert(0, arr[j])
		lis = lis[:k]
print(len(lis))
x = ' '.join([str(i) for i in lis])
print(x)


import queue
[n, k] = map(int, input().split(' '))
x = input().split(' ')
screen = queue.Queue(maxsize=k)
onScreen = []
for i in x:
	if not screen.full():
		if onScreen.count(i) == 0:
			screen.put(i)
			onScreen.append(i)
	elif onScreen.count(i) == 0:
		temp = screen.get()
		onScreen.remove(temp)
		screen.put(i)
		onScreen.append(i)
count = 0
stack = queue.LifoQueue(maxsize=k)
while not screen.empty():
	stack.put(screen.get())
	count += 1
print(count)
while not stack.empty():
	print(stack.get(), end=' ')


(n, k) = map(int, input().split())
queue = list(map(int, input().split()))
ans = []
was = set()
for id in queue:
	if id not in was:
		if len(was) == k:
			was.remove(ans[-k])
		was.add(id)
		ans.append(id)
print(min(len(was), k))
for i in range(len(was)):
	print(ans[len(ans) - 1 - i], end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
a = []
s = set()
for i in arr:
	if i not in s:
		s.add(i)
		a.append(i)
	if len(a) > k:
		s.discard(a[0])
		del a[0]
print(len(a))
for i in range(len(a) - 1, -1, -1):
	print(a[i], end=' ')


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = []
for i in range(n):
	if a[i] not in b:
		if len(b) < k:
			b.insert(0, a[i])
		else:
			b.pop()
			b.insert(0, a[i])
print(len(b))
print(*b)


(n, k) = input().split()
n = int(n)
k = int(k)
l = []
a = [int(i) for i in input().split()]
for i in a:
	if i in l:
		pass
	if i not in l and len(l) != k:
		l.insert(0, i)
	if i not in l and len(l) == k:
		l.insert(0, i)
		l.pop(-1)
print(len(l))
print(*l)


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = []
for i in range(len(l1)):
	if len(l2) == k and l1[i] not in l2:
		l2.pop(0)
		l2.append(l1[i])
	elif l1[i] not in l2:
		l2.append(l1[i])
print(len(l2))
for i in reversed(l2):
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for item in a:
	if item not in ans:
		if len(ans) == k:
			ans.pop()
		ans.insert(0, item)
print(len(ans))
print(*ans)


def main():
	(n, k) = input().split()
	k = int(k)
	messages = input().split()
	screen = []
	for i in messages:
		if i not in screen:
			if len(screen) == k:
				screen.pop()
			screen.insert(0, i)
	print(len(screen))
	print(' '.join(screen))
main()


(n, k) = list(map(int, input().split(' ')))
messages = list(input().split(' '))
received = {}
screen = []
t = 0

def isReceived(i):
	return i in received and received[i] != 0

def updateScreen(i):
	global t
	if isReceived(i):
		return
	if screen != [] and len(screen) == k:
		received[screen[-1]] = 0
		screen.pop()
	received[i] = 1
	screen.insert(0, i)
for m in messages:
	updateScreen(m)
print(len(screen))
print(' '.join(screen))


(n, k) = list(map(int, input().split()))
Massage = []
id_all = list(map(int, input().split()))
A = set()
for i in range(n):
	id = id_all[i]
	if id not in A:
		Massage.append(id)
		A.add(id)
		if len(A) > k:
			A.remove(Massage[-k - 1])
if len(Massage) > k:
	print(k)
	print(*Massage[-1:-(k + 1):-1])
else:
	print(len(Massage))
	print(*Massage[::-1])


(n, k) = map(int, input().split())
calls = list(map(int, input().split()))
rec = []
for i in calls:
	if i not in rec:
		rec += [i]
		if len(rec) > k:
			rec.pop(0)
print(len(rec))
for i in rec[::-1]:
	print(i, end=' ')


from collections import *
(n, k) = map(int, input().split(' '))
a = [int(x) for x in input().strip().split(' ')]
l = deque()
c = 0
ch = Counter()
for i in range(n):
	if ch[a[i]] == 0:
		if c < k:
			l.appendleft(a[i])
			c += 1
			ch[a[i]] = 1
		else:
			ch[l.pop()] = 0
			l.appendleft(a[i])
			ch[a[i]] = 1
print(len(l))
print(*l)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
	tmp = len(b)
	tmp = tmp - k
	if tmp < 0:
		tmp = 0
	if a[i] not in b[tmp:]:
		b.append(a[i])
tim = min(k, len(b))
print(tim)
b.reverse()
for j in range(min(k, len(b))):
	print(b[j], end=' ')


import collections
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
de = collections.deque()
for i in range(n):
	if len(de) < k:
		if arr[i] not in de:
			de.appendleft(arr[i])
	elif len(de) == k:
		if arr[i] not in de:
			de.appendleft(arr[i])
			de.pop()
print(len(de))
print(*de)


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
seen = set()
ans = []
for i in range(n):
	if ids[i] in seen:
		continue
	else:
		if len(ans) < min(n, k):
			ans = [ids[i]] + ans
		else:
			temp = ans.pop(-1)
			seen.remove(temp)
			ans = [ids[i]] + ans
		seen.add(ids[i])
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [a[0]]
for i in range(1, n):
	if b.count(a[i]) == 0:
		if len(b) == k:
			b.pop()
		b.insert(0, a[i])
print(len(b))
print(*b)


import collections as cl
q = cl.deque()
s = set()
(n, k) = map(int, input().split())
for id_ in map(int, input().split()):
	if id_ not in s:
		s.add(id_)
		q.appendleft(id_)
		if len(q) > k:
			s.remove(q.pop())
print(len(q))
print(*list(q))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))[:n]
out = []
for ele in a:
	if ele not in out:
		if len(out) < k:
			out.insert(0, ele)
		else:
			out.insert(0, ele)
			out.pop()
print(len(out))
print(*out)


(n, k) = list(map(int, input().split()))
running_list = []
membership_set = set()
input_list = list(input().split())
for text in input_list:
	if text in membership_set:
		continue
	if len(running_list) < k:
		running_list.append(text)
		membership_set.add(text)
	else:
		membership_set.discard(running_list[0])
		del running_list[0]
		running_list.append(text)
		membership_set.add(text)
		continue
print(len(running_list))
print(' '.join(running_list[::-1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
c = []
for i in range(0, len(a)):
	if a[i] in ans:
		pass
	else:
		if len(ans) == k:
			ans.pop()
		c.append(a[i])
		ans = c + ans
		c.pop()
print(len(ans))
print(*ans)


[n, k] = input().split()
n = int(n)
k = int(k)
lis = []
mes = input().split()
for i in range(n):
	if mes[i] not in lis:
		if len(lis) < k:
			lis.append(0)
		for a in reversed(range(1, len(lis))):
			lis[a] = lis[a - 1]
		lis[0] = mes[i]
print(len(lis))
print(' '.join(lis))


class Queue:

	def __init__(self):
		self.queue = []

	def enqueue(self, obj):
		if obj not in self.queue:
			self.queue.insert(0, obj)
			return True
		return False

	def dequeue(self):
		if self.size() > 0:
			return self.queue.pop()
		return False

	def size(self):
		return len(self.queue)

	def output(self):
		return q.queue
(n, k) = map(int, input().split())
m = list(map(int, input().split()))
q = Queue()
for ele in m:
	q.enqueue(ele)
	if q.size() > k:
		q.dequeue()
print(q.size())
print(' '.join(map(str, q.output())))


from collections import deque
(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
q = deque()
d1 = {}
for i in range(n):
	if l1[i] not in d1:
		if len(q) < k:
			d1[l1[i]] = 1
			q.append(l1[i])
		else:
			del d1[q.popleft()]
			q.append(l1[i])
			d1[l1[i]] = 1
print(len(q))
result = []
for item in q:
	result.append(item)
result = result[::-1]
print(*result, sep=' ')


def B1():
	(amOfMessages, convConstr) = map(int, input().split())
	ids = input().split()
	messagesShown = []
	index = 0
	while index < len(ids):
		if ids[index] not in messagesShown:
			messagesShown.insert(0, ids[index])
		if len(messagesShown) > convConstr:
			del messagesShown[-1]
		index += 1
	answer = str(len(messagesShown)) + '\n'
	index = 0
	while index < len(messagesShown):
		answer = answer + messagesShown[index] + ' '
		index += 1
	print(answer)
B1()


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
m = []
for i in l:
	if len(m) < k and i not in m:
		m.insert(0, i)
	elif i not in m:
		j = m.pop()
		m.insert(0, i)
	else:
		continue
print(len(m))
print(*m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
answer = []
for i in a:
	if i not in answer:
		if len(answer) is k:
			del answer[0]
		answer.append(i)
print(len(answer))
print(*reversed(answer))


from collections import deque
I = lambda : map(int, input().split())
(_, k) = I()
S = deque()
for x in I():
	if x not in S:
		S.appendleft(x)
		if len(S) > k:
			S.pop()
print(len(S))
print(*S)


from sys import stdin
input = lambda : map(int, stdin.readline().split())
(n, k) = input()
(d, v, x) = ({}, [], 1)
for i in input():
	if d.get(i, 0) < x:
		d[i] = x + k
		v += (i,)
		x += 1
v = v[::-1][:k]
print(len(v))
print(*v)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
s = set()
l = []
c = 0
for i in a:
	if i in s:
		continue
	if len(s) == k:
		z = l[c - k]
		s.remove(z)
	l.append(i)
	c = c + 1
	s.add(i)
print(len(s))
y = min(len(s), len(l))
p = len(l)
p -= 1
while y:
	print(l[p], end=' ')
	p -= 1
	y -= 1


(n, k) = map(int, input().split())
arr = list(map(int, input().strip().split()))[:n]
from collections import defaultdict
store = defaultdict(int)
ans = []
for num in arr:
	if store[num] != 1:
		if len(ans) == k:
			s = ans.pop(0)
			store[s] = 0
			ans.append(num)
			store[num] = 1
		else:
			ans.append(num)
			store[num] = 1
print(len(ans))
for i in range(len(ans) - 1, -1, -1):
	print(ans[i], end=' ')


(n, k) = tuple(map(int, input().split()))
ids = list(map(int, input().split()))
S = []
for id in ids:
	if id not in S:
		S = [id] + S
		S = S[:k]
print(len(S))
print(' '.join([str(s) for s in S]))


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = deque()
l = 0
s = set()
for _ in range(n):
	if a[_] in s:
		continue
	if l < k:
		d.appendleft(str(a[_]))
		s.add(a[_])
		l += 1
		continue
	d.appendleft(str(a[_]))
	s.add(a[_])
	s.remove(int(d[-1]))
	d.pop()
	l += 1
print(len(s))
print(*list(d), sep=' ')


(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
in_list = set()
con = []
for x in d:
	if x in in_list:
		continue
	if len(con) == k:
		top = con[0]
		in_list.remove(top)
		con.pop(0)
	con.append(x)
	in_list.add(x)
print(len(con))
print(*con[::-1])


(n, k) = map(int, input().split())
inp = list(map(int, input().split()))
listt = []
for i in inp:
	if len(listt) < k:
		if i not in listt:
			listt = [i] + listt
	if len(listt) == k:
		if i not in listt:
			listt = [i] + listt
			listt = listt[:-1]
print(len(listt))
print(*listt)


I = lambda : map(int, input().split())
(n, k) = I()
l = list(I())
result = []
d = {}
for i in l:
	if len(result) < k and i not in d:
		result.append(i)
		d[i] = 1
	elif i in d:
		continue
	else:
		result.append(i)
		d[i] = 1
		del d[result.pop(0)]
print(len(result))
print(*result[::-1])


from collections import OrderedDict
import sys
(n, k) = map(int, sys.stdin.readline().split())
ids = list(map(int, sys.stdin.readline().split()))
shown = OrderedDict()
for friend in ids:
	if friend in shown:
		continue
	if len(shown) < k:
		shown[friend] = ''
	else:
		shown.popitem(last=False)
		shown[friend] = ''
print(len(shown))
print(*reversed(shown), sep=' ')


nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
ids = list(map(int, input().split()))
screen = []
for cur_id in ids:
	found = False
	for a in range(max(0, len(screen) - k), len(screen)):
		if screen[a] == cur_id:
			found = True
			break
	if not found:
		screen.append(cur_id)
if len(screen) <= k:
	print(len(screen))
	print(' '.join(map(str, screen[::-1])))
else:
	print(k)
	print(' '.join(map(str, screen[-k:][::-1])))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
for i in l:
	if i not in ans:
		if len(ans) < k:
			ans.insert(0, i)
		else:
			ans.pop()
			ans.insert(0, i)
print(len(ans))
for i in ans:
	print(i, end=' ')


from collections import deque
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
p = []
q = deque(p)
d = {}
for i in range(len(l)):
	key = l[i]
	if key not in d or d[key] == 0:
		q.appendleft(l[i])
		d[key] = 1
		if len(q) > k:
			x = q.pop()
			d[x] = 0
print(len(q))
for i in q:
	print(i, end=' ')


R = lambda : list(map(int, input().split()))
(n, m) = R()
l = R()
k = []
for i in range(n):
	if l[i] not in k:
		k.insert(0, l[i])
		if len(k) > m:
			k.pop()
print(len(k))
print(*k)


(n, k) = map(int, input().split())
_id = list(map(int, input().split()))
out = []
for i in range(n):
	if _id[i] not in set(out):
		out.insert(0, _id[i])
		if len(out) > k:
			out.pop()
print(len(out))
for i in out:
	print(i, end=' ')


from collections import OrderedDict
(n, k) = map(int, input().split())
d = list(map(int, input().split()))
last = OrderedDict()
for di in d:
	if len(last) == k:
		if last.get(di):
			continue
		last.popitem(False)
		last[di] = True
		last.move_to_end(di, True)
		continue
	last[di] = True
print(len(last))
print(*list(last.keys())[::-1])


import array
(n, k) = map(int, input().split())
ids = map(int, input().split())
size = 0
L = [None] * (k + 1)
for id in ids:
	if id not in L:
		for i in range(size, 0, -1):
			L[i] = L[i - 1]
		if size < k:
			size += 1
		L[size] = None
		L[0] = id
l = [x for x in L[:k] if x is not None]
print(len(l))
for i in l:
	print(i, end=' ')


(n, k) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = []
for i in range(n):
	if a[i] in b:
		continue
	elif len(b) < k:
		b.insert(0, a[i])
	else:
		b.pop(-1)
		b.insert(0, a[i])
print(len(b))
print(*b)


from collections import deque
se = set([])
s = deque([])
(n, k) = map(int, input().split())
li = list(map(int, input().split()))
cnt = 0
for i in li:
	if i in se:
		continue
	if cnt < k:
		s.append(i)
		se.add(i)
		cnt += 1
	else:
		s.append(i)
		se.add(i)
		se.discard(s[0])
		s.popleft()
print(len(s))
print(*list(s)[::-1])


(n, k) = map(int, input().rstrip().split())
ids = list(map(int, input().rstrip().split()))
arr = []
for i in range(k):
	arr.append(0)
temp = True
for i in range(n):
	if ids[i] in arr:
		temp == False
		continue
	if temp == True:
		arr.insert(0, ids[i])
		arr.pop()
for i in range(len(arr) - 1, -1, -1):
	if arr[i] == 0:
		arr.pop(i)
	else:
		break
print(len(arr))
for i in arr:
	print(i, end=' ')


from collections import deque
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
stack = deque()
st = set()
for i in arr:
	if i not in st:
		stack.appendleft(i)
		st.add(i)
		if len(stack) > k:
			j = stack.pop()
			st.remove(j)
print(len(stack))
print(*stack)


[n, k] = list(map(int, input('').split(' ')))
messages = list(map(int, input('').split(' ')))
conv = []
for m in messages:
	if m in conv:
		pass
	elif len(conv) == k:
		conv = conv[1:]
		conv.append(m)
	else:
		conv.append(m)
conv.reverse()
print(len(conv))
for i in conv:
	print(i, end=' ')


q = [int(i) for i in input().split()]
n = q[0]
k = q[1]
a = [int(i) for i in input().split()]
m = []
for i in range(n):
	if a[i] not in m:
		if len(m) == 0:
			m.append(a[i])
		else:
			m.insert(0, a[i])
		if len(m) > k:
			m.pop()
print(len(m))
for i in range(len(m)):
	print(m[i], end=' ')


x = input().split()
arr = input().split()
queue = []
for a in range(0, len(arr)):
	arr[a] = int(arr[a])
	if len(queue) < int(x[1]) and (not arr[a] in queue):
		queue.append(arr[a])
	elif not arr[a] in queue and len(queue) == int(x[1]):
		del queue[0]
		queue.append(arr[a])
queue.reverse()
print(len(queue))
st = ''
for each in queue:
	st += str(each) + ' '
print(st[:-1])


from collections import deque
(n, k) = [int(p) for p in input().split()]
arr = [int(p) for p in input().split()]
curr = set()
stack = deque()
for i in range(len(arr)):
	if arr[i] not in curr:
		stack.appendleft(arr[i])
		curr.add(arr[i])
	if len(stack) > k:
		ele = stack.pop()
		curr.remove(ele)
print(len(stack))
print(*stack)


import sys
from math import *
from collections import *

def inp():
	return map(int, input().split())
(n, k) = inp()
a = inp()
res = deque()
for i in a:
	if i not in res:
		res.appendleft(i)
		if len(res) > k:
			res.pop()
if len(res) > k:
	print(k)
	for i in range(k):
		print(res[i], end=' ')
else:
	print(len(res))
	for i in res:
		print(i, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
que = []
for i in arr:
	if i not in que:
		que.append(i)
		if len(que) > k:
			que.pop(0)
print(len(que))
print(*que[::-1])


(n, k) = map(int, input().split())
ids = [int(x) for x in input().split()]
tela = []
for id in ids:
	if not id in tela:
		tela.insert(0, id)
	if len(tela) > k:
		tela.pop()
print(len(tela))
print(*tela)


from collections import deque
X = list(map(int, input().split()))
Messages = list(map(int, input().split()))
Answer = deque()
for i in range(X[0]):
	if Messages[i] not in Answer:
		if len(Answer) < X[1]:
			Answer.appendleft(Messages[i])
		else:
			del Answer[-1]
			Answer.appendleft(Messages[i])
print(len(Answer))
print(*Answer)


first = input().split(' ')
messages = int(first[0])
screen_size = int(first[1])
message_list = list(map(int, input().split(' ')))
screen = []
for message in message_list:
	if message not in screen:
		if len(screen) < screen_size:
			screen.append(message)
		else:
			screen.pop(0)
			screen.append(message)
screen = list(map(str, screen))
print(len(screen))
print(' '.join(screen[::-1]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
r = []
for i in range(n):
	if len(r) < k and False == (l[i] in r):
		r.insert(0, l[i])
	elif len(r) == k and False == (l[i] in r):
		r.pop()
		r.insert(0, l[i])
print(len(r))
print(*r, sep=' ')


from sys import stdin as si, stdout as so
from collections import deque
length = len
output = deque()
insert = output.appendleft
pop = output.pop
d = {}
(a, b) = map(int, si.readline().split())
arr = list(map(int, si.readline().split()))
for i in arr:
	if d.setdefault(i, 0) == 0:
		insert(i)
		d[i] = 1
		if length(output) > b:
			x = pop()
			d[x] = 0
print(length(output))
print(*list(output))


def fct(listes, a):
	c = 0
	for i in range(len(listes)):
		if listes[i] == a:
			c += 1
	if c == 0:
		return 0
	else:
		return 1

def fe(liste, k):
	A = []
	if k >= len(liste):
		T = []
		for s in range(len(liste)):
			if fct(T, liste[s]) == 0:
				T.append(liste[s])
		print(len(T))
		T.reverse()
		return T
	else:
		i = 0
		while len(A) < k and i <= len(liste) - 1:
			if fct(A, liste[i]) == 0:
				A.append(liste[i])
				i += 1
			else:
				i += 1
		for j in range(i, len(liste)):
			if fct(A, liste[j]) == 0:
				A.remove(A[0])
				A.append(liste[j])
		A.reverse()
		print(len(A))
	return A
(n, k) = map(int, input().split())
liste = list(map(int, input().split()))
l = fe(liste, k)
for i in l:
	print(i, end=' ')


from collections import deque

def main():
	(n, k) = map(int, input().split())
	vals = list(map(int, input().split()))
	d = deque()
	s = set()
	for i in vals:
		if not i in s:
			if len(d) == k:
				s.remove(d.pop())
			d.appendleft(i)
			s.add(i)
	print(len(d))
	print(*list(d))
main()


(n, k) = map(int, input().split())
ids = map(int, input().split())

def print_list(l):
	for item in l[:-1]:
		print(item, end=' ')
	print(l[-1])
l = []
for item in ids:
	if item not in l:
		if len(l) == k:
			l.pop()
		l.insert(0, item)
else:
	print(len(l))
	print_list(l)


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = deque([])
for i in a:
	if i not in ans and len(ans) == k:
		ans.pop()
		ans.appendleft(i)
	elif i not in ans:
		ans.appendleft(i)
print(len(ans))
for i in ans:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for l in range(len(a)):
	flag = 0
	for j in range(len(b)):
		if b[j] == a[l]:
			flag = 1
	if flag:
		pass
	elif len(b) >= k:
		del b[0]
		b.append(a[l])
	else:
		b.append(a[l])
print(len(b))
l1 = b[::-1]
for i in l1:
	print(i, end=' ')


entrada = input().split()
n = int(entrada[0])
k = int(entrada[1])
fila = [-1 for i in range(k)]
ids = list(map(int, input().split()))
ultimodisponivel = 0
for j in range(n):
	flag = False
	for i in range(len(fila)):
		if ids[j] == fila[i]:
			flag = True
			break
	if not flag:
		if ultimodisponivel == k:
			del fila[0]
			fila.append(-1)
			ultimodisponivel -= 1
		fila[ultimodisponivel] = ids[j]
		ultimodisponivel += 1
print(ultimodisponivel)
string = ''
for i in range(ultimodisponivel):
	if i == ultimodisponivel - 1:
		string += str(fila[ultimodisponivel - i - 1])
		break
	else:
		string += str(fila[ultimodisponivel - i - 1]) + ' '
print(string)


from collections import deque
(a, b) = list(map(int, input().split()))
array = list(map(int, input().split()))
hashmap = {}
arr = deque()
current = 0
x = 0
while 6 == 6:
	if x == a:
		break
	if array[x] in hashmap:
		pass
	elif current < b:
		hashmap[array[x]] = 5
		arr.appendleft(array[x])
		current += 1
	else:
		if hashmap != {}:
			hashmap.pop(arr[-1])
		arr.pop()
		arr.appendleft(array[x])
		hashmap[array[x]] = 5
	x += 1
print(len(arr))
print(*list(arr))


import queue
(n, k) = map(int, input().split())
h = {}
L = queue.Queue(maxsize=k)
numbers = input().split()
numbers = list(map(int, numbers))
for i in numbers:
	if i in h and h[i] == True:
		continue
	elif L.full():
		if not L.empty():
			a = L.get()
			h[a] = False
		L.put(i)
		h[i] = True
	else:
		L.put(i)
		h[i] = True
ans = []
counter = 0
while not L.empty():
	ans.append(L.get())
	counter += 1
print(counter)
for i in reversed(ans):
	print(i, end=' ')


(n, k) = list(map(int, input().split()))
Massage = []
id_all = list(map(int, input().split()))
for i in range(n):
	id = id_all[i]
	if id not in Massage:
		if len(Massage) < k:
			Massage.insert(0, id)
		else:
			for j in range(len(Massage) - 1):
				Massage[len(Massage) - j - 1] = Massage[len(Massage) - j - 2]
			Massage[0] = id
print(len(Massage))
print(*Massage)


from collections import deque
(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
current = set([])
queue = deque([])
for i in ids:
	if i in current:
		pass
	elif len(current) == k:
		last = queue.popleft()
		current.remove(last)
		current.add(i)
		queue.append(i)
	else:
		current.add(i)
		queue.append(i)
queue.reverse()
final_ids = [str(i) for i in queue]
print(len(final_ids))
print(' '.join(final_ids))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
output = []
for i in range(n):
	if A[i] in output[:k]:
		continue
	else:
		output.insert(0, A[i])
print(min(n, k, len(output)))
print(*output[:min(n, k, len(output))])


from collections import deque

def funcao(lista, k):
	fila = deque()
	conj = set()
	for e in lista:
		if e not in conj:
			conj.add(e)
			fila.appendleft(e)
		if len(fila) > k:
			conj.remove(fila.pop())
	return fila
k = int(input().split()[1])
lista = input().split()
res = funcao(lista, k)
print(len(res))
print(' '.join(res))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ll = []
for i in range(n):
	if l[i] not in ll:
		if len(ll) == k:
			ll.pop(0)
		ll.append(l[i])
print(len(ll))
ll = ll[::-1]
print(*ll)


ar = []
for x in input().split(' '):
	ar.append(int(x))
n = ar[0]
k = ar[1]
ar2 = []
for x in input().split(' '):
	ar2.append(int(x))
curr = []
for x in ar2:
	if x in curr:
		continue
	if len(curr) == k:
		curr.insert(0, x)
		curr = curr[:-1]
	else:
		curr.insert(0, x)
print(len(curr))
print(*curr)


from collections import defaultdict as dc
import sys
import math
mod = 10 ** 9 + 7

def inp():
	p = sys.stdin.readline()
	return p

def prf(a, n, k):
	q = dc(int)
	p = []
	i = 0
	while len(p) <= k or i < n:
		if q[a[i]] == 0:
			p.append(a[i])
			q[a[i]] = 1
			if len(p) == k:
				break
		i += 1
		if i >= n:
			break
	if i >= n:
		return p[::-1]
	for j in range(i + 1, n):
		if q[a[j]] == 0:
			l = p[0]
			p = p[1:] + [a[j]]
			q[a[j]] = 1
			q[l] = 0
	return p[::-1]
(n, m) = list(map(int, inp().split()))
a = list(map(int, inp().split()))
z = prf(a, n, m)
print(len(z))
print(*z)


(n, k) = [int(x) for x in input().split()]
ar = [int(x) for x in input().split()]
x = []
for i in range(len(ar)):
	if ar[i] not in x:
		if len(x) == k:
			x.pop()
		x.insert(0, ar[i])
	else:
		continue
print(len(x))
for i in x:
	print(i, end=' ')


(n, k) = [int(x) for x in input().split()]
numbers = [int(x) for x in input().split()]
checkMap = {}
outputArray = []
for num in numbers:
	if num in checkMap:
		next
	else:
		if len(outputArray) == k:
			key = outputArray[k - 1]
			del checkMap[key]
			outputArray = [num] + outputArray[:-1]
		else:
			outputArray = [num] + outputArray
		checkMap[num] = True
print(len(outputArray))
for num in outputArray:
	print(num, end=' ')
print()


(n, k) = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
count = 0
f = [0] * k
for i in p:
	if i not in f:
		f.insert(0, i)
		f.pop()
print(len(f) - f.count(0))
for i in f:
	if i != 0:
		print(i, end=' ')


a = list(map(int, input().split()))
l = list(map(int, input().split()))
k = a[-1]
ans = []
for i in l:
	if i in ans:
		continue
	elif len(ans) < k:
		ans.insert(0, i)
	else:
		t = ans.pop(-1)
		ans.insert(0, i)
print(len(ans))
for i in range(len(ans)):
	print(ans[i], end=' ')
print(' ')


(n, k) = input().split()
n = int(n)
k = int(k)
a = [int(n) for n in input().split()]
b = []
max = max(a)
for i in range(n):
	if len(b) < k and b.count(a[i]) == 0:
		b.insert(0, a[i])
	elif len(b) >= k and b.count(a[i]) == 0:
		b.insert(0, a[i])
		b.pop()
print(len(b))
print(*b, sep=' ')


import time
import collections
LOCAL = False
start_time = None
if LOCAL:
	start_time = time.time()
(n, k) = list(map(lambda x: int(x), input().split(' ')))
poses = list(map(lambda x: int(x), input().split(' ')))
q = collections.deque(maxlen=k)
for i in poses:
	if i not in q:
		q.appendleft(i)
print(len(q))
print(' '.join([str(i) for i in q]))
if LOCAL:
	print('--- %s seconds ---' % (time.time() - start_time))


import sys
(n, k) = map(int, sys.stdin.readline().split())
mes = list(map(int, sys.stdin.readline().split()))
con = []
_id = dict()
for i in range(len(mes)):
	if mes[i] not in _id:
		_id[mes[i]] = 1
		con = [mes[i]] + con
		if len(con) > k:
			del _id[con.pop()]
print(len(con))
for j in range(len(con)):
	print(con[j], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = list(set(l))
z = []
d = {}
for i in s:
	d[i] = 0
a = 0
for i in l:
	if a == k and d[i] != 1:
		d[z[0]] = 0
		a -= 1
		z.pop(0)
	if d[i] == 0:
		z.append(i)
		d[i] += 1
		a += 1
z.reverse()
print(a)
print(*z)


(n, k) = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
res = list()
for id in d:
	if id in res:
		continue
	if len(res) < k:
		res.append(id)
	else:
		res = res[1:k]
		res.append(id)
res.reverse()
print(len(res))
for i in res:
	print(i, end=' ')


for a0 in range(1):
	(a, b) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	new = []
	for i in l:
		if i not in new:
			if len(new) >= b:
				new.pop()
			new = [i] + new
	print(len(new))
	print(*new)


import math
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
qu = []
d = {}
for i in l:
	if i in qu:
		pass
	elif len(qu) == k:
		qu.insert(0, i)
		t = qu.pop()
	else:
		qu.insert(0, i)
print(len(qu))
print(*qu)


(n, k) = tuple(map(int, input().split()))
msg = list(map(int, input().split()))
sc = list()
for x in msg:
	if x in sc:
		continue
	if len(sc) >= k:
		del sc[-1]
	sc.insert(0, x)
print(len(sc))
print(' '.join(map(str, sc)))


from collections import deque
(n, k) = input().split()
n = int(n)
k = int(k)
m = set()
q = deque()
arr = [int(i) for i in input().split()]
for i in range(len(arr)):
	if str(arr[i]) not in m:
		if len(q) >= k:
			m.remove(q.pop())
		q.appendleft(str(arr[i]))
		m.add(str(arr[i]))
print(len(q))
print(*q)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
iterator = 1
output = []
for i in arr:
	if i not in output:
		output.append(i)
	length = len(output)
	if length > k:
		output = output[iterator:]
print(len(output))
print(*output[::-1])


(n, k) = [int(i) for i in input().split()]
pid = [int(i) for i in input().split()]
st = set()
q = [0] * k
ind = -1
for i in range(n):
	if pid[i] not in st:
		ind += 1
		ind %= k
		if len(st) == k:
			st.remove(q[ind])
		q[ind] = pid[i]
		st.add(pid[i])
print(len(st))
ans = []
for i in range(len(st)):
	ans.append(q[ind - i])
print(*ans)


def convopicker(convos, n, k):
	convolist = list()
	for i in range(n):
		if convos[i] in convolist:
			pass
		elif len(convolist) == k:
			convolist.pop()
			convolist.insert(0, convos[i])
		else:
			convolist.insert(0, convos[i])
	print(len(convolist))
	for i in convolist:
		print(i, end=' ')
(n, k) = [int(x) for x in input().split()]
convos = [int(x) for x in input().split()]
convopicker(convos, n, k)


(n, k) = [int(x) for x in input().split()]
arr = []
for x in input().split():
	if int(x) not in arr:
		if len(arr) == k:
			arr.pop()
			arr.insert(0, int(x))
		else:
			arr.insert(0, int(x))
print(len(arr))
for x in arr:
	print(x, end=' ')


(n, k) = [int(x) for x in input().split()]
id = [int(x) for x in input().split()]
liss = []
for i in range(n):
	if id[i] not in liss and len(liss) < k:
		liss.append(id[i])
	elif id[i] not in liss and len(liss) == k:
		liss.remove(liss[0])
		liss.append(id[i])
print(len(liss))
for i in range(len(liss)):
	print(liss[len(liss) - i - 1], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
r = []
r.append(l[0])
for i in range(1, len(l)):
	if l[i] not in r:
		if len(r) < k:
			r.insert(0, l[i])
		else:
			r.remove(r[-1])
			r.insert(0, l[i])
print(len(r))
print(*r)


from sys import stdin
from collections import defaultdict
import math
(n, k) = list(map(int, stdin.readline().rstrip().split()))
id = list(map(int, stdin.readline().rstrip().split()))
c_id = defaultdict(lambda : 0)
curr = []
c_len = 0
for i in range(n):
	if c_id[id[i]] != 0:
		continue
	elif c_len < k:
		c_len += 1
		curr.append(id[i])
		c_id[id[i]] = 1
	else:
		c_id[curr[0]] = 0
		curr.pop(0)
		curr.append(id[i])
		c_id[id[i]] = 1
print(c_len)
print(' '.join(map(str, curr[::-1])))


(n, k) = map(int, input().strip().split())
d = {}
s = []
now = 0
pos = 0
for i in list(map(int, input().split())):
	is_new = False
	if i not in d:
		d[i] = True
		is_new = True
	if is_new or d[i] == False:
		d[i] = True
		s.append(i)
		if now < k:
			now += 1
		else:
			d[s[pos]] = False
			pos += 1
print(now)
print(' '.join(map(str, s[::-1][0:k])))


(n, k) = map(int, input().split())
messages = list(map(str, input().split()))
show = []
for elem in messages:
	if len(show) < k and elem not in show:
		show.insert(0, elem)
	elif elem not in show:
		del show[k - 1]
		show.insert(0, elem)
print(len(show))
s = ' '.join(show)
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = []
for num in a:
	if num not in q:
		q.append(num)
	if len(q) > k:
		q.pop(0)
print(len(q))
for i in range(len(q) - 1, -1, -1):
	print(q[i], end=' ')
print()


from collections import deque

def solution(arr, k: int) -> None:
	d = deque()
	s = set()
	for v in arr:
		if v not in s:
			s.add(v)
			if len(d) == k:
				s.discard(d.pop())
			d.appendleft(v)
	print(len(d))
	print(*d)

def main():
	(_, k) = map(int, input().split())
	arr = map(int, input().split())
	solution(arr, k)
main()


from queue import Queue

def pageFaults(pages, n, capacity):
	s = set()
	indexes = Queue()
	page_faults = 0
	for i in range(n):
		if len(s) < capacity:
			if pages[i] not in s:
				s.add(pages[i])
				page_faults += 1
				indexes.put(pages[i])
		elif pages[i] not in s:
			val = indexes.queue[0]
			indexes.get()
			s.remove(val)
			s.add(pages[i])
			indexes.put(pages[i])
			page_faults += 1
	return list(indexes.queue)
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l2 = pageFaults(l, n, m)
print(len(l2))
for i in l2[::-1]:
	print(i, end=' ')
print()


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
x = []
for i in range(len(l)):
	if l[i] in x:
		continue
	elif len(x) == b:
		x.remove(x[0])
		x.append(l[i])
	else:
		x.append(l[i])
x.reverse()
print(len(x))
print(*x)


import sys
import math
import collections
import bisect
import string

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, k) = get_ints()
	arr = get_list()
	phone = collections.deque()
	screen = set()
	for i in arr:
		if i in screen:
			continue
		elif len(phone) >= k:
			last = phone.pop()
			screen.remove(last)
			screen.add(i)
			phone.appendleft(i)
		else:
			phone.appendleft(i)
			screen.add(i)
	print(len(phone))
	print(*phone)


from collections import deque
screen = deque()
items = set()
(n, k) = list(map(int, input().split()))
msgs = list(map(int, input().split()))

def add(i):
	if i not in items:
		if len(screen) == k:
			items.remove(screen.pop())
		screen.appendleft(i)
		items.add(i)
for m in msgs:
	add(m)
print(len(screen))
print(' '.join((str(i) for i in screen)))


(n, k) = list(map(int, input().split()))
n = int(n)
k = int(k)
l1 = []
l = list(map(int, input().split()))
for i in range(len(l)):
	if l[i] not in l1:
		if len(l1) == k:
			del l1[0]
			l1.append(l[i])
		else:
			l1.append(l[i])
print(len(l1))
for i in range(len(l1) - 1, -1, -1):
	print(l1[i], end=' ')


import queue
(n, k) = input().split()
n = int(n)
k = int(k)
list1 = [int(x) for x in input().split()]
L = queue.Queue(maxsize=k)
for i in list1:
	list_ans = list(L.queue)
	list_ans = list_ans[::-1]
	if i not in list_ans and L.full():
		ele = L.get()
		L.put(i)
	elif i not in list_ans:
		L.put(i)
	else:
		continue
list_ans = list(L.queue)
list_ans = list_ans[::-1]
print(len(list_ans))
for i in list_ans:
	print(i, end=' ')
print()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cnt = 1
d = dict()
stack = []
j = 0
ls = 0
for i in range(n):
	if l[i] not in d:
		if ls == k:
			del d[stack[j]]
			j += 1
			stack.append(l[i])
			d[l[i]] = 1
		else:
			stack.append(l[i])
			ls += 1
			d[l[i]] = 1
stack = stack[::-1]
print(min(len(set(l)), k))
print(*stack[0:min(len(set(l)), k)])


import sys
from collections import deque
I = sys.stdin.readline
(n, k) = map(int, I().split())
id_ = list(map(int, I().split()))
sc = deque()
for i in range(n):
	if len(sc) < k:
		if id_[i] not in sc:
			sc.appendleft(id_[i])
	elif id_[i] not in sc:
		sc.pop()
		sc.appendleft(id_[i])
print(len(sc))
print(*list(sc))


from collections import deque
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
s = deque()
for i in range(len(a)):
	f = a[i] in s
	if len(s) == k and (not f):
		z = s.pop()
	if not f:
		s.appendleft(a[i])
print(len(s))
print(*s)


(n, k) = input().split()
liste = list(map(int, input().split()))
liste2 = []
for i in liste:
	if i not in liste2:
		liste2.insert(0, i)
		if len(liste2) > int(k):
			liste2.pop()
print(len(liste2))
print(*liste2)


(mcount, ccount) = [int(x) for x in input().split(' ')]
messages = [int(x) for x in input().split(' ')]
displayed = []
for i in messages:
	if not i in displayed:
		if ccount > 0:
			displayed.append(i)
			ccount -= 1
		else:
			displayed.pop(0)
			displayed.append(i)
reslen = len(displayed)
print(reslen)
res = ''
for i in range(reslen - 1, -1, -1):
	res += str(displayed[i]) + ' '
print(res)


from collections import deque
(n, k) = [int(p) for p in input().split()]
arr = [int(p) for p in input().split()]
final = deque()
s = set()
for i in range(len(arr)):
	if len(final) < k:
		if arr[i] not in s:
			final.appendleft(arr[i])
			s.add(arr[i])
	else:
		if arr[i] in s:
			continue
		e = final.pop()
		s.remove(e)
		final.appendleft(arr[i])
		s.add(arr[i])
print(len(final))
print(*final)


from collections import deque
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = deque()
B.append(A[0])
for i in range(1, n):
	if A[i] not in B:
		if len(B) == k:
			B.popleft()
		B.append(A[i])
	else:
		pass
print(len(B))
print(*list(B)[::-1])


def sovle():
	(n, k) = map(int, input().split())
	ss = [int(i) for i in input().split()]
	ans = []
	for i in range(0, len(ss)):
		if ss[i] in ans:
			continue
		if len(ans) == k:
			ans.pop()
			ans = ss[i:i + 1] + ans[:]
			continue
		ans = ss[i:i + 1] + ans[:]
	print(len(ans))
	print(*ans)
sovle()


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
from collections import deque
q = deque()
(n, s) = map(int, input().split())
for i in map(int, input().split()):
	if i in q:
		continue
	q.appendleft(i)
	if len(q) > s:
		q.pop()
print(str(len(q)) + '\n')
for i in q:
	print(str(i) + ' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque
d = set({})
queue = deque([])
for i in l:
	if i in d:
		continue
	else:
		d.add(i)
		queue.append(i)
	if len(d) > k:
		t = queue[0]
		queue.popleft()
		d.remove(t)
print(len(d))
for i in range(1, len(queue) + 1):
	print(queue[-i], end=' ')


from collections import deque
(n, k) = map(int, input().split())
l1 = deque([])
s = set(l1)
inp = list(map(int, input().split()))
for i in range(n):
	element = inp[i]
	if element in s:
		pass
	else:
		if len(l1) == k:
			s.remove(l1.pop())
		l1.appendleft(inp[i])
		s.add(element)
print(len(l1))
for j in l1:
	print(j, end=' ')


a = input('').split(' ')
n = int(a[0])
k = int(a[1])
a = list(map(int, input('').split(' ')))
d = {}
l = []
s = -1
import collections
l = collections.deque([])
for i in range(n):
	if a[i] in d:
		continue
	elif len(l) < k:
		l.appendleft(a[i])
		d[a[i]] = True
	else:
		cu = l.pop()
		del d[cu]
		d[a[i]] = True
		l.appendleft(a[i])
print(len(l))
for k in l:
	print(k, end=' ')


from collections import Counter
from collections import defaultdict
(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
d = defaultdict(lambda : 0)
c = 0
a = list()
for i in l:
	if d[i] == 0:
		if c < k:
			d[i] = d[i] + 1
			a.append(i)
		else:
			d[i] = d[i] + 1
			g = a[0]
			a = a[1:]
			d[g] = d[g] - 1
			a.append(i)
			c = c - 1
		c = c + 1
print(c)
print(*a[::-1])


import sys
from collections import deque

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
(N, K) = MAP()
A = LIST()
que = deque()
S = set()
for a in A:
	if len(que) < K:
		if a not in S:
			que.appendleft(a)
			S.add(a)
	elif a not in S:
		b = que.pop()
		S.remove(b)
		que.appendleft(a)
		S.add(a)
print(len(que))
print(*que)


(n, k) = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
nowlist = []
nowset = set()
for i in arr:
	if i in nowset:
		continue
	if len(nowlist) == k:
		nowset.remove(nowlist.pop())
	nowlist = [i] + nowlist
	nowset.add(i)
print(len(nowlist))
print(*nowlist)


from collections import defaultdict as df
import heapq
import bisect
import math
from itertools import combinations, permutations
from collections import deque
(n, k) = list(map(int, input().split()))
a = list(map(int, input().rstrip().split()))
ans = []
for i in a:
	if i in ans:
		pass
	elif len(ans) >= k:
		ans.pop()
		ans.insert(0, i)
	else:
		ans.insert(0, i)
print(len(ans))
print(*ans)


import collections
(n, k) = map(int, input().split())
A = [*map(int, input().split())]
order = collections.deque()
hashset = set()
for a in A:
	if a in hashset:
		pass
	else:
		order.appendleft(a)
		hashset.add(a)
		if len(order) > k:
			b = order.pop()
			hashset.remove(b)
print(len(order))
print(' '.join(map(str, order)))


(n, k) = [int(i) for i in input().split()]
ids = [int(i) for i in input().split()]
msgs = list()
m = 0
for i in ids:
	if not msgs:
		msgs = [i]
		m += 1
		continue
	if i not in msgs:
		if m < k:
			msgs.append(i)
			m += 1
		else:
			msgs = msgs[1:]
			msgs.append(i)
print(m)
print(' '.join([str(i) for i in msgs[::-1]]))


def main():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	arr = [int(i) for i in input().split()]
	s = []
	for i in range(n):
		if len(s) < k:
			if str(arr[i]) not in s:
				s.insert(0, str(arr[i]))
			else:
				continue
		elif str(arr[i]) not in s:
			s = s[:len(s) - 1]
			s.insert(0, str(arr[i]))
		else:
			continue
	print(len(s))
	for i in range(len(s)):
		print(s[i], end=' ')
main()


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
f = 0
l = []
for i in a:
	if f < y:
		if i not in l:
			f += 1
			l.insert(0, i)
	elif i not in l:
		l.insert(0, i)
		l.pop()
print(len(l))
print(*l)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ln = []
if n <= k:
	for i in range(n):
		if l[i] not in ln:
			ln.insert(0, l[i])
else:
	for i in range(n):
		if len(ln) < k:
			if l[i] not in ln:
				ln.insert(0, l[i])
		elif l[i] not in ln:
			del ln[-1]
			ln.insert(0, l[i])
print(len(ln))
for j in range(len(ln)):
	print(ln[j], end=' ')


import collections
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = collections.deque()
used = {}
for i in a:
	used[i] = False
cnt = 0
for i in a:
	if not used[i]:
		used[i] = True
		d.appendleft(i)
		cnt += 1
	if cnt > k:
		lst = d.pop()
		used[lst] = False
		cnt -= 1
print(cnt)
for i in d:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = []
for i in range(n):
	if a[i] in b:
		continue
	if len(b) == k:
		b.remove(b[len(b) - 1])
		b.insert(0, a[i])
	else:
		b.insert(0, a[i])
print(len(b))
for i in range(len(b)):
	print(b[i], end=' ')


def Queue(ID, c, l, n, k):
	if c >= n:
		print(len(l))
		print(*l)
	elif ID[c] not in l:
		if len(l) >= k:
			l.insert(0, ID[c])
			l.pop()
		else:
			l.insert(0, ID[c])
		c += 1
		Queue(ID, c, l, n, k)
	else:
		c += 1
		Queue(ID, c, l, n, k)
(n, k) = map(int, input().split())
ID = list(map(int, input().split()))
l = []
c = 0
Queue(ID, c, l, n, k)


(n, k) = input().split()
n = int(n)
k = int(k)
lis = list(map(int, input().split()))
dic = set()
j = 0
lis1 = []
for i in lis:
	if i not in dic:
		dic.add(i)
		lis1.append(i)
		if len(lis1) > k:
			dic.discard(lis1[0])
			del lis1[0]
print(len(lis1))
for i in range(len(lis1)):
	print(lis1[len(lis1) - 1 - i], end=' ')


import collections
(n, k1) = map(int, input().split())
k = list(map(int, input().split()))
q = collections.deque()
h = set()
for i in range(len(k)):
	if k[i] not in h:
		q.appendleft(k[i])
		h.add(k[i])
	if len(q) > k1:
		h.discard(q[len(q) - 1])
		q.pop()
print(len(q))
print(*q)


fir = input().split(' ')
(n, k) = (int(fir[0]), int(fir[1]))
liste = list(map(int, input().split(' ')))
kam = []
tan = 0
for i in liste:
	if len(kam) < k and i not in kam:
		tan += 1
		kam = [i] + kam
	elif i in kam:
		continue
	else:
		tan += 1
		kam = [i] + kam
		del kam[-1]
print(min(tan, k))
print(' '.join(map(str, kam)))


from collections import deque
(n, k) = map(int, input().split())
friends = list(map(int, input().split()))
d = deque()
q = set()
for ID in friends:
	if ID in q:
		continue
	if len(d) >= k:
		q.remove(d.pop())
	d.appendleft(ID)
	q.add(ID)
print(len(d))
print(*d)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
screen = []
st = set()
for i in range(n):
	if len(screen) < k and a[i] not in st:
		screen.insert(0, a[i])
		st.add(a[i])
	elif len(screen) == k and a[i] not in st:
		num = screen.pop()
		st.remove(num)
		screen.insert(0, a[i])
		st.add(a[i])
print(len(screen))
print(*screen)


(n, max1) = map(int, input().split())
lis = list(map(int, input().split()))
forlist = []
for i in lis:
	if i in forlist:
		continue
	if len(forlist) == max1:
		forlist.pop(0)
	forlist.append(i)
print(len(forlist))
for i in range(len(forlist) - 1, -1, -1):
	print(forlist[i], end=' ')


(n, k) = map(int, input().split())
convs = list(map(int, input().split()))
window = []
for i in convs:
	if len(window) >= k:
		if i not in window:
			del window[0]
			window.append(i)
	elif i not in window:
		window.append(i)
print(len(window))
print(*window[::-1])


ln = [int(i) for i in input().split(' ')]
n = ln[0]
k = ln[1]
ln = [int(i) for i in input().split(' ')]
ns = []
i = 0
oi = 0
for i in range(0, n):
	if ln[i] not in ns:
		if len(ns) < k:
			ns = [ln[i]] + ns
		else:
			ns = [ln[i]] + ns[:-1]
print(len(ns))
print(' '.join([str(i) for i in ns]))


(n, k) = [int(x) for x in input().split()]
s = list(map(int, input().split()))
l = []
while len(s) != 0:
	x = s.pop(0)
	if x in l:
		continue
	elif len(l) < k:
		l.insert(0, x)
	else:
		a = l.pop()
		l.insert(0, x)
print(len(l))
for i in range(len(l)):
	print(l[i], end=' ')


l1 = []
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n):
	if l[i] not in l1:
		l1.insert(0, l[i])
		if len(l1) > m:
			l1.pop()
print(len(l1))
for i in range(len(l1)):
	print(l1[i], end=' ')


(a, b) = input().split()
a = int(a)
b = int(b)
l = [int(x) for x in input().split()]
k = []
for i in l:
	if i in k:
		continue
	elif len(k) == b:
		k.remove(k[0])
		k.append(i)
	else:
		k.append(i)
if len(k) < b:
	print(len(k))
	for i in range(1, len(k) + 1):
		print(k[-i], end=' ')
else:
	print(b)
	for i in range(1, b + 1):
		print(k[-i], end=' ')


import sys, math, queue, collections
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
last = collections.deque()
listed = dict()
for ai in a:
	if ai not in listed:
		listed[ai] = False
	if not listed[ai]:
		if len(last) == k:
			listed[last.popleft()] = False
		last.append(ai)
		listed[ai] = True
last = list(reversed(last))
print(len(last))
print(*last)


from sys import stdin, stdout
from collections import deque
(n, k) = map(int, stdin.readline().split())
lis = deque()
sett = set()
arr = list(map(int, stdin.readline().split()))
for j in arr:
	if j not in sett:
		lis.appendleft(j)
		sett.add(j)
		if len(lis) > k:
			sett.discard(lis[-1])
			del lis[-1]
print(len(lis))
print(*lis)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = []
for i in arr:
	if len(ans) == k:
		if i in ans:
			pass
		else:
			del ans[-1]
			ans.insert(0, i)
	elif i not in ans:
		ans.insert(0, i)
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
check = []
for i in range(len(a)):
	if len(check) >= k and a[i] not in check:
		check.pop()
	if a[i] in check:
		continue
	else:
		check.insert(0, a[i])
print(len(check))
for i in check:
	print(i, end=' ')


(n, k) = map(int, input().split())
ID = [int(s) for s in input().split()]
a = []
for nom in ID:
	if not nom in a:
		if len(a) == k:
			a.pop()
		b = [nom]
		b.extend(a)
		a = b
print(len(a))
print(' '.join([str(i) for i in a]))


ids = []
(n, k) = input().split()
n = int(n)
k = int(k)
a = input().split()
for i in a:
	if i not in ids:
		ids.insert(0, i)
	if len(ids) > k:
		ids.pop()
print(len(ids))
print(' '.join(ids))


(n, k) = [int(j) for j in input().split()]
arr = [int(j) for j in input().split()]
b = []
for i in range(len(arr)):
	if len(b) < k and arr[i] not in b:
		b.append(arr[i])
	elif arr[i] not in b:
		b.pop(0)
		b.append(arr[i])
print(len(b))
b.reverse()
print(*b, sep=' ')


import queue
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
qu = queue.Queue()
s = set()
for i in a:
	if i not in s:
		if qu.qsize() < k:
			qu.put(i)
			s.add(i)
		elif qu.qsize() == k:
			s.remove(qu.get())
			qu.put(i)
			s.add(i)
qs = qu.qsize()
ls = [0 for i in range(qs)]
for i in range(qs):
	ls[i] = qu.get()
print(len(ls))
for i in range(-1, -qs - 1, -1):
	print(ls[i], end=' ')


from collections import deque
(n_messages, max_dialogs) = map(int, input().split())
on_screen = set()
order = deque()
messages = map(int, input().split())
for mes in messages:
	if len(on_screen) < max_dialogs and mes not in on_screen:
		on_screen.add(mes)
		order.appendleft(mes)
	elif mes not in on_screen:
		on_screen.remove(order.pop())
		on_screen.add(mes)
		order.appendleft(mes)
print(len(order))
print(*order)


(n, k) = list(map(int, input().split()))
incoming_msg = list(map(int, input().split()))
screen = []
for friend in incoming_msg:
	if friend in screen:
		continue
	elif len(screen) < k:
		screen = [friend] + screen
	else:
		screen.pop()
		screen = [friend] + screen
print(len(screen))
print(' '.join(map(str, screen)))


from collections import defaultdict as dd
from collections import deque
(n, k) = map(int, input().split())
d = dd(int)
l = list(map(int, input().split()))
ll = deque([])
for i in range(n):
	if d[l[i]] == 0:
		if len(ll) == k:
			d[ll.pop()] -= 1
		ll.appendleft(l[i])
		d[l[i]] += 1
print(len(ll))
print(*ll)


(n, k) = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
l1 = []
for i in range(n):
	if l[i] not in l1:
		if len(l1) == k:
			del l1[k - 1]
			l1 = [l[i]] + l1
		else:
			l1 = [l[i]] + l1
print(len(l1))
print(*l1)


(n, k) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
x = [0 for i in range(n)]
ans = []
c = 0
for i in range(n):
	if c < k:
		if l[i] not in ans:
			ans = [l[i]] + ans
			c = c + 1
	elif l[i] not in ans:
		ans = [l[i]] + ans
		ans.pop()
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
a = []
for id in ids:
	if id in a:
		continue
	if len(a) < k:
		a.append(id)
	else:
		a.pop(0)
		a.append(id)
print(len(a))
print(*a[::-1])


(n, k) = map(int, input().strip().split())
ids = map(int, input().strip().split())
convs = []
for i in ids:
	if i in convs:
		continue
	elif len(convs) == k:
		convs.pop()
	convs.insert(0, i)
print(len(convs))
print(' '.join(map(str, convs)))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
s = set()
l = []
for i in a:
	if i in s:
		continue
	if len(s) == k:
		z = l.pop(0)
		s.remove(z)
	l.append(i)
	s.add(i)
print(len(s))
for i in range(len(l) - 1, -1, -1):
	print(l[i], end=' ')


import sys
import math

def read_two_lines():
	(num_messages, k) = [int(x) for x in input().split()]
	message_ids = [int(x) for x in input().split()]
	queue = []
	for m in message_ids:
		if m in queue:
			continue
		else:
			queue_len = len(queue)
			if queue_len == k:
				queue.pop()
			queue.insert(0, m)
	print(len(queue))
	print(' '.join([str(x) for x in queue]))
	return queue
read_two_lines()


from collections import deque
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
d = deque()
s = set()
for id in ids:
	if id not in s:
		s.add(id)
		if len(d) == k:
			s.remove(d.popleft())
			d.append(id)
		else:
			d.append(id)
d.reverse()
print(len(d))
print(' '.join(map(str, d)))


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = []
for i in arr:
	if len(ans) < k and i not in ans:
		ans = [i] + ans
	elif len(ans) == k and i not in ans:
		ans = [i] + ans[:k - 1]
print(len(ans))
print(*ans)


import collections
arr = collections.deque([])
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
s = set(l)
for i in s:
	d[i] = 0
t = 0
for i in l:
	if d[i] == 1:
		continue
	elif t == k and d[i] == 0:
		z = arr.pop()
		d[z] = 0
		arr.appendleft(i)
		d[i] = 1
	elif t < k and d[i] == 0:
		t = t + 1
		d[i] = 1
		arr.appendleft(i)
print(t)
print(*arr)


(x, y) = [int(x) for x in input('').split()]
L = list(map(int, input('').split()))
l = []
for i in L:
	if len(l) < y:
		if i not in l:
			l.insert(0, i)
	elif len(l) == y:
		if i not in l:
			l.insert(0, i)
			l.pop()
print(len(l))
for i in l:
	print(i, end=' ')


a = [int(x) for x in input().strip().split(' ')]
b = [int(x) for x in input().strip().split(' ')]
(n, k) = (a[0], a[1])
l = []
for i in range(n):
	if len(l) < k and b[i] not in l:
		l.insert(0, b[i])
	elif b[i] not in l:
		l.pop()
		l.insert(0, b[i])
print(len(l))
for i in range(len(l)):
	print(l[i], end=' ')


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
from collections import deque
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
d = deque()
s = set()
for i in a:
	if i not in s:
		if len(d) == k:
			s.remove(d.popleft())
		s.add(i)
		d.append(i)
print(len(d))
print(*reversed(d))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
q = []
a = 0
d = dict()
for i in range(n):
	d.setdefault(l[i], 0)
	if a < k and d[l[i]] == 0:
		d[l[i]] = 1
		q.append(l[i])
		a += 1
	elif a == k and d[l[i]] == 0:
		d[q[0]] = 0
		q.pop(0)
		q.append(l[i])
		d.setdefault(l[i], 1)
		d[l[i]] = 1
print(a)
q.reverse()
print(*q)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
x = 0
for i in a:
	if i not in b:
		b.append(i)
		x += 1
		if x > k:
			del b[0]
			x = k
f = min(n, k)
g = f
if len(b) <= f:
	g = len(b)
h = len(b)
fl = 0
hug = 0
if h > g:
	hug = h - 1 - g
print(g)
for j in range(h - 1, -1, -1):
	print(b[j], end=' ')
	fl += 1
	if fl == g:
		break


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
lookup = set()
q = []
for i in a:
	if i not in lookup:
		if len(q) < k:
			lookup.add(i)
			q.append(i)
		else:
			lookup.remove(q[0])
			q.pop(0)
			q.append(i)
			lookup.add(i)
print(len(q))
for i in q[::-1]:
	print(i, end=' ')
print()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
a = []
for i in arr:
	if len(a) == 0:
		a.append(i)
	elif i not in a:
		if len(a) < k:
			a.insert(0, i)
		elif len(a) == k:
			a = [i] + a[:k - 1]
print(len(a))
print(*a)


(n, k) = [int(i) for i in input().split()]
msg = [int(i) for i in input().split()]
fila = []
for i in msg:
	if i in fila:
		continue
	if len(fila) >= k:
		fila.pop()
	fila = [i] + fila
print(len(fila))
print(*fila)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
queue = []
for i in a:
	if i not in queue:
		if len(queue) == k:
			queue.pop()
			queue.insert(0, i)
		else:
			queue.insert(0, i)
print(len(queue))
print(*queue)


from collections import deque
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
s = deque()
d = dict()
for i in range(len(a)):
	if a[i] not in d:
		f = False
	else:
		f = d[a[i]] == 1
	if len(s) == k and (not f):
		z = s.pop()
		d[z] = 0
	if not f:
		d[a[i]] = 1
		s.appendleft(a[i])
print(len(s))
print(*s)


from collections import defaultdict
(a, b) = map(int, input().split())
arr = list(map(int, input().split()))
d = {}
output = []
for i in arr:
	try:
		if d[i] == 0:
			output.insert(0, i)
			if len(output) > b:
				x = output.pop()
				d[x] = 0
			d[i] = 1
	except KeyError:
		output.insert(0, i)
		if len(output) > b:
			x = output.pop()
			d[x] = 0
		d[i] = 1
print(len(output))
print(*output)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = []
if k >= len(set(a)):
	for i in a:
		if i in l:
			pass
		else:
			l = [i] + l
else:
	i = 0
	while i < n:
		if a[i] in l:
			pass
		else:
			l = [a[i]] + l
		i += 1
		l = l[:k]
print(len(l))
print(*l)


(n, k) = map(int, input().split())
id = list(map(int, input().split()))
arr = []
for i in id:
	if len(arr) < k and i not in arr:
		arr.insert(0, i)
	if len(arr) == k and i not in arr:
		arr.pop()
		arr.insert(0, i)
print(len(arr))
print(' '.join(map(str, arr)))


from sys import stdin
from collections import deque
input = stdin.readline
(n, k) = map(int, input().split())
(s, v, l) = (set(), deque(), 0)
for i in map(int, input().split()):
	f = i in s
	if f:
		continue
	elif not f and l == k:
		s.remove(v.pop())
		v.appendleft(i)
		s.add(i)
	else:
		s.add(i)
		v.appendleft(i)
		l += 1
print(len(v))
print(*v)


(n, k) = map(int, input().split())
cnt = 0
a = []
h = list(map(int, input().split()))
for i in range(n):
	n1 = h[i]
	if n1 not in a:
		if cnt < k:
			a.append(n1)
			cnt += 1
		else:
			a = a[1:] + [n1]
a.reverse()
print(len(a))
print(*a)


(n, k) = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
a = []
for i in range(n):
	if not v[i] in a:
		if len(a) == k:
			a = a[1:] + [v[i]]
		else:
			a.append(v[i])
print(len(a))
i = len(a) - 1
while i >= 0:
	if i == 0:
		print(a[i])
	else:
		print(a[i], end=' ')
	i -= 1


from collections import defaultdict as dc
from collections import deque as dq
import sys
import math
mod = 10 ** 9 + 7

def inp():
	p = sys.stdin.readline()
	return p
(n, k) = list(map(int, inp().split()))
a = list(map(int, inp().split()))
q = dc(int)
p = dq([])
i = 0
while len(p) <= k or i < n:
	if q[a[i]] == 0:
		p.appendleft(a[i])
		q[a[i]] = 1
		if len(p) == k:
			break
	i += 1
	if i >= n:
		break
if i >= n:
	print(len(p))
	print(*p)
else:
	for j in range(i + 1, n):
		if q[a[j]] == 0:
			z = p.pop()
			p.appendleft(a[j])
			q[a[j]] = 1
			q[z] = 0
	print(len(p))
	print(*p)


(n, k) = map(int, input().split())
d = dict()
l = list(map(int, input().split()))
q = [0 for i in range(k)]
ct = 0
top = k - 1
for i in range(n):
	if ct == k:
		if l[i] not in d or d[l[i]] == 0:
			d[q[top]] = 0
			q[top] = l[i]
			top -= 1
			if top == -1:
				top = k - 1
			d[l[i]] = 1
	elif l[i] not in d or d[l[i]] == 0:
		q[k - 1 - ct] = l[i]
		ct += 1
		d[l[i]] = 1
print(ct)
for i in range(k):
	ind = (top + 1) % k
	if q[ind] != 0:
		print(q[ind], end=' ')
	top = (top + 1) % k
print()


from collections import defaultdict, deque
from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	(N, K) = map(int, input().split())
	ID = map(int, input().split())
	id = deque([], K)
	flag = defaultdict(int)
	for i in ID:
		if not flag[i]:
			if len(id) == K:
				flag[id[-1]] = 0
			id.appendleft(i)
			flag[i] = 1
	print(len(id))
	print(*id)
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
(ans, res) = (0, 0)
for i in range(n):
	if a[i] not in b:
		b.insert(0, a[i])
		b = b[:k]
print(len(b))
print(*b)


(n, k) = [int(x) for x in input().split()]
cl = [int(x) for x in input().split()]
queue = []
for i in cl:
	if i not in queue:
		queue = [i] + queue
		queue = queue[:k]
print(len(queue))
print(*queue)


a = []
c = []
(n, k) = list(map(int, input().strip().split()))
a[0:n] = list(map(int, input().strip().split()))
for i in range(n):
	if len(c) < k:
		if a[i] not in c:
			c.insert(0, a[i])
	elif a[i] not in c:
		c.pop(k - 1)
		c.insert(0, a[i])
print(len(c))
for i in c:
	print(i, end=' ')


(n, k) = [int(x) for x in input().split()]
a = [int(j) for j in input().split()]
s = set()
q = []
for x in a:
	if x in s:
		continue
	else:
		q.append(x)
		s.add(x)
		if len(q) > k:
			t = q.pop(0)
			s.remove(t)
print(len(q))
q.reverse()
for x in q:
	print(x, end=' ')


import collections
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = []
s = set(a)
d = collections.Counter(s)
for i in d:
	d[i] -= 1
if k >= n or len(set(a)) <= k:
	for i in range(0, n):
		if d[a[i]] == 0:
			ans.append(a[i])
		d[a[i]] += 1
	print(len(ans))
	ans = ans[::-1]
	print(*ans)
else:
	i = 0
	while len(ans) != k:
		if d[a[i]] == 0:
			ans.append(a[i])
		d[a[i]] += 1
		i += 1
	for j in range(i, n):
		if d[a[j]] == 0:
			d[ans[0]] = 0
			ans.pop(0)
			ans.append(a[j])
		d[a[j]] += 1
	print(len(ans))
	ans = ans[::-1]
	print(*ans)


from sys import stdin, stdout, setrecursionlimit
from collections import deque

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		(n, k) = [int(x) for x in R().split()]
		ID = [int(x) for x in R().split()]
		conversation = deque()
		check = {}
		for j in range(n):
			if ID[j] not in check:
				check[ID[j]] = True
				conversation.appendleft(ID[j])
				if len(conversation) > k:
					del check[conversation.pop()]
		ans.append(str(len(conversation)))
		ans.append('\n')
		while len(conversation):
			ans.append(str(conversation.popleft()))
			ans.append(' ')
		W(''.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
c = set()
for i in a:
	if i not in c:
		b.append(i)
		c.add(i)
		if len(b) > k:
			c.remove(b[0])
			del b[0]
b.reverse()
print(len(b))
print(*b)


from sys import stdin
input = stdin.readline
from collections import deque
(n, k) = map(int, input().split())
arr = map(int, input().split())
dd = deque()
ss = set()
for v in arr:
	if v not in ss:
		if len(dd) >= k:
			ss.remove(dd.pop())
		ss.add(v)
		dd.appendleft(v)
print(len(dd))
print(' '.join((str(v) for v in dd)))


a = list(map(int, input().split()))
b = []
for i in map(int, input().split()):
	x = len(b)
	if x == 0:
		b.append(i)
	elif x < a[1]:
		if i not in b:
			b.insert(0, i)
	elif x == a[1]:
		if i not in b:
			b.pop()
			b.insert(0, i)
print(len(b))
print(*b, sep=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = []
for i in range(len(l)):
	if len(m) < k:
		if l[i] not in m:
			m.append(l[i])
	elif l[i] not in m[len(m) - k:]:
		m.append(l[i])
m = m[::-1]
print(min(len(m), k))
if len(m) < k:
	print(' '.join(map(str, m)))
else:
	print(' '.join(map(str, m[:k])))


(n, k) = map(int, input().split())
id = list(map(int, input().split()))
li = []
for i in range(n):
	l = len(li)
	if id[i] not in li:
		li.append(id[i])
		if l >= k:
			li.remove(li[0])
print(len(li))
li.reverse()
print(*li)


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
ms = []
added = []
mss = set()
for i in range(n):
	if m[i] not in mss:
		if len(mss) == k:
			mss.remove(added[-k])
		mss.add(m[i])
		added.append(m[i])
a = added[-k:]
a.reverse()
print(len(a))
print(*a)


from collections import defaultdict as dc
import sys
import math
input = sys.stdin.readline
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
p = [0] * n
x = dc(int)
j = 0
for i in range(n):
	if x[l[i]] == 0:
		x[l[i]] = 1
		p[j] = l[i]
		if j - k >= 0:
			x[p[j - k]] = 0
		j += 1
x = p[max(j - k, 0):j]
print(len(x))
x = x[::-1]
print(*x)


(m, k) = [int(a) for a in input().split()]
msgs = list(map(int, input().split()))
ls = min(m, k)
stack = []
for i in range(m):
	if msgs[i] not in stack:
		if len(stack) == ls:
			stack.pop(0)
		stack.append(msgs[i])
print(len(stack))
print(*stack[-1::-1])


(n, k) = map(int, input().split())
ID = list(map(int, input().split()))
(res, length) = ([], 0)
d = {x: 0 for (i, x) in enumerate(set(ID))}
app = res.append
for (i, x) in enumerate(ID):
	if d[x] == 0:
		if length == k:
			y = res.pop(0)
			d[y] -= 1
		else:
			length += 1
		app(x)
		d[x] += 1
print(length)
res.reverse()
print(*res)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(n, k) = li()
a = li()
b = deque([])
s = set({})
for i in a:
	if i not in s:
		if len(b) == k:
			s.discard(b.popleft())
			b.append(i)
			s.add(i)
		else:
			b.append(i)
			s.add(i)
b = list(b)
print(len(b))
b.reverse()
print(*b)


queue = []
(n, m_len) = map(int, input().split())

def add(num):
	global queue
	if not num in queue:
		if len(queue) == m_len:
			queue.pop()
		queue = [num] + queue
a = list(map(int, input().split()))
for i in a:
	add(i)
print(len(queue))
print(' '.join((str(i) for i in queue)))


from collections import deque
(n, k) = map(int, input().split())
li = list(map(int, input().split()))
ans = deque([])
for i in range(len(li)):
	if li[i] not in ans and len(ans) < k:
		ans.appendleft(li[i])
	elif len(ans) == k and li[i] not in ans:
		ans.pop()
		ans.appendleft(li[i])
j = min(k, len(ans))
print(j)
for i in range(j):
	print(ans[i], end=' ')


a = list(map(int, input().split()))
k = a[1]
l = list(map(int, input().split()))
ll = []
ind = 0
lenn = 0
d = {}
for i in l:
	d[i] = 0
for i in l:
	if d[i] == 0:
		if lenn < k:
			ll.append(i)
			d[i] = 1
			lenn += 1
		else:
			d[ll[ind]] = 0
			ind += 1
			ll.append(i)
			d[i] = 1
			lenn += 1
print(len(ll) - ind)
for i in range(1, lenn - ind + 1):
	print(ll[-i], end=' ')


arr = input()
ns = list(map(int, arr.split(' ')))
arr = input()
ids = list(map(int, arr.split(' ')))
n = ns[0]
k = ns[1]
res = [None] * n
for i in range(0, len(ids)):
	if ids[i] not in res[0:k]:
		res.insert(0, ids[i])
finalRes = []
for i in range(len(res[:k])):
	if res[i] == None:
		break
	else:
		finalRes.append(res[i])
print(len(finalRes))
for i in range(len(finalRes)):
	print(finalRes[i], end=' ')


(n, k) = (int(i) for i in input().split())
a = list(map(int, input().split()))
ans = []
s = set()
for i in a:
	if i in s:
		continue
	elif len(ans) < k:
		ans.insert(0, i)
		s.add(i)
	else:
		s.remove(ans[k - 1])
		del ans[k - 1]
		ans.insert(0, i)
		s.add(i)
print(len(ans))
print(*ans)


(n, k) = list(map(int, input().split()))
incomingTexts = list(input().split())
running_list = []
for text in incomingTexts:
	if text in running_list:
		continue
	if len(running_list) < k:
		running_list.insert(0, text)
		continue
	if len(running_list) == k:
		del running_list[-1]
		running_list.insert(0, text)
		continue
print(len(running_list))
print(' '.join(running_list))


from collections import Counter

def countmy(arr):
	return len(Counter(arr).keys())

def is_in_list(arr, x):
	flag = False
	for m in range(len(arr)):
		if x == arr[m]:
			flag = True
	return flag
(n, k) = input().split()
n = int(n)
k = int(k)
arr = list(map(int, input().split()))
u = countmy(arr)
L = []
for index in arr:
	if len(L) == min(u, k) and is_in_list(L, index) is False:
		L.pop(min(u, k) - 1)
	if len(L) < min(u, k) and is_in_list(L, index) is False:
		L.insert(0, index)
print(min(u, k))
print(*L)


import sys
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
display = [0] * k
for id in ids:
	if id not in display:
		display.append(id)
		display.pop(0)
while 0 in display:
	display.remove(0)
display.reverse()
print(len(display))
print(*display)


(n, k) = map(int, input().split())
w = []
x = set()
l = list(map(int, input().split()))
for i in range(n):
	if l[i] in x:
		continue
	else:
		if len(w) >= k:
			x.discard(w[k - 1])
			w.remove(w[k - 1])
		w.insert(0, l[i])
		x.add(l[i])
print(len(w))
print(*w)


from sys import stdin

def main():
	inp = stdin.readline
	(n, k) = map(int, inp().split())
	d = list(map(int, inp().split()))
	m = []
	b = set()
	for i in d:
		if i not in b:
			m.append(i)
			if len(m) > k:
				b.remove(m[-(k + 1)])
			b.add(i)
	f = min(len(m), k)
	print(f)
	for i in range(1, f + 1):
		print(m[-i], end=' ')
	print()
main()


from collections import deque

def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	queue = deque()
	for i in range(n):
		if arr[i] not in queue:
			if len(queue) < k:
				queue.appendleft(arr[i])
			else:
				queue.pop()
				queue.appendleft(arr[i])
	print(len(queue))
	for i in range(len(queue)):
		print(queue[i], end=' ')
main()


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
(n, k) = inpl()
a = inpl()
se = set()
q = deque([])
ln = 0
for x in a:
	if x in se:
		continue
	if ln < k:
		q.appendleft(x)
		se.add(x)
		ln += 1
	else:
		p = q.pop()
		se.discard(p)
		q.appendleft(x)
		se.add(x)
print(len(q))
print(*list(q))


(n, k) = map(int, input().split())
arr = [int(k) for k in input().split()]
lis = []
dic = {}
for i in range(n):
	if arr[i] not in dic:
		dic[arr[i]] = 1
		lis.append(arr[i])
		if len(lis) > k:
			del dic[lis[0]]
			lis.pop(0)
print(len(lis))
print(*lis[::-1])


(n, k) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
log = []
for query in arr:
	if query in log:
		continue
	log.insert(0, query)
	if len(log) > k:
		log.pop(-1)
print(len(log))
print(' '.join(list((str(l) for l in log))))


import sys
input = sys.stdin.readline
import collections

def main():
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	msgs = input().split()
	q = collections.deque()
	s = set()
	for msg in msgs:
		if msg not in s:
			q.append(msg)
			s.add(msg)
			if len(q) > k:
				s.remove(q.popleft())
	print(len(q))
	while q:
		print(q.pop(), end=' ')
main()


from collections import *
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
deq = deque()
ll = defaultdict(int)
for i in range(n):
	if len(deq) == k:
		if ll[l[i]] == 0:
			val = deq.pop()
			ll[val] = 0
			deq.appendleft(l[i])
			ll[l[i]] = 1
	elif ll[l[i]] == 0:
		deq.appendleft(l[i])
		ll[l[i]] = 1
print(len(deq))
print(*deq)


(n, k) = [int(i) for i in input().split()]
id = [int(i) for i in input().split()]
que = []
for i in range(n):
	if id[i] in que:
		continue
	else:
		if len(que) == k:
			que.remove(que[-1])
		que = [id[i]] + que
print(len(que))
for i in range(len(que)):
	print(que[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
arr = []
for i in range(n):
	if i == 0:
		arr.append(l[i])
	elif l[i] not in arr:
		arr = [l[i]] + arr
		if len(arr) > k:
			del arr[-1]
print(len(arr))
print(*arr)


(n, k) = map(int, input().split())
ids = [i for i in input().split()]
in_q = set()
Q = []
for idi in ids:
	if idi not in in_q:
		if len(Q) == k:
			last = Q.pop(0)
			in_q.discard(last)
		in_q.add(idi)
		Q.append(idi)
print(len(Q))
print(*reversed(Q))


from collections import deque
(n, k) = map(int, input().split())
A = map(int, input().split())
D = deque()
s = set()
for a in A:
	if a in s:
		continue
	if len(D) < k:
		s.add(a)
		D.appendleft(a)
	else:
		s.remove(D.pop())
		D.appendleft(a)
		s.add(a)
print(len(D))
print(' '.join(map(str, D)))


def nof(n, k, convs):
	L = list()
	for conv in convs:
		if conv not in L:
			L.insert(0, conv)
		L = L[:k].copy()
	return (len(L), ' '.join(L))
(n, k) = input().split()
convs = input().split()
(m, n) = nof(n, int(k), convs)
print(m)
print(n)


from collections import deque
(n, k) = map(int, input().split())
d = list(map(int, input().split()))
p = dict()
t = deque([])
for i in range(n):
	if not d[i] in p:
		p[d[i]] = 0
		t.appendleft(d[i])
	if len(t) > k:
		p.pop(t[-1])
		t.pop()
w = list(t)
print(len(w))
for x in w:
	print(x, end=' ')


(n, k) = list(map(int, input().split(' ')))
N = list(map(int, input().split(' ')))
curr = []
A = ''
while N:
	cid = N.pop(0)
	if cid in curr:
		continue
	if len(curr) == k:
		curr.pop()
	curr.insert(0, cid)
print(len(curr))
for i in curr:
	A += str(i) + ' '
print(A[:-1])


from collections import deque
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
sc = deque([])
s = set()
l = 0
for a in arr:
	if a not in s:
		sc.insert(0, a)
		s.add(a)
		l += 1
		if l > k:
			p = sc.pop()
			l = k
			s.remove(p)
print(l)
print(*sc)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
j = 0
for i in range(n):
	if a[i] not in b:
		b.insert(0, a[i])
		j = j + 1
		if j > k:
			b.pop(j - 1)
			j = j - 1
unique_list = []
for x in b:
	if x not in unique_list:
		unique_list.append(x)
s = min(len(unique_list), k)
print(s)
for i in range(s):
	print(b[i], end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = []
size = 0
dic = {}
for i in range(n):
	try:
		dic[arr[i]] = dic[arr[i]] & dic[arr[i]]
	except:
		dic[arr[i]] = False
	if dic[arr[i]] == False:
		ans.append(arr[i])
		dic[arr[i]] = True
		size += 1
	if size > k:
		dic[ans[0]] = False
		del ans[0]
		size -= 1
print(len(ans))
print(*ans[::-1])


(n, k) = map(int, input().split())
sp = list(map(int, input().split()))
s = []
while len(sp) != 0:
	x = sp[0]
	if x not in s:
		if len(s) == k:
			del s[0]
		s.append(x)
	del sp[0]
s.reverse()
print(len(s))
print(*s)


def __main__():
	(n, k) = map(int, input().split())
	idx = map(int, input().split())
	m = min(n, k)
	lst = []
	for num in idx:
		if num not in lst:
			lst.append(num)
		if len(lst) > m:
			lst.pop(0)
	print(min(len(lst), m))
	for i in range(len(lst) - 1, -1, -1):
		print(lst[i], end=' ')
__main__()


(x, y) = map(int, input().split())
l = list(map(int, input().split()))
k = []
for num in l:
	if num not in k and len(k) < y:
		k.append(num)
	elif num not in k and len(k) == y:
		k.pop(0)
		k.append(num)
print(len(k))
for x in k[::-1]:
	print(x, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
import queue
s = set()
q = queue.Queue()
count = 0
for x in a:
	if x not in s:
		if count < k:
			q.put(x)
			s.add(x)
			count += 1
		else:
			s.remove(q.get())
			q.put(x)
			s.add(x)
ans = list()
for _ in range(count):
	ans.append(q.get())
print(count)
print(' '.join(map(str, ans[::-1])))


(n, k) = [int(i) for i in input().split()]
iD = list(map(int, input().split()))
res = [None for i in range(k)]

def check(a):
	for i in res:
		if i == a:
			return True
	return False
for i in range(n):
	if check(iD[i]):
		continue
	else:
		res = [iD[i]] + res[:k - 1]
res2 = 0
for i in range(k):
	if res[i] == None:
		break
	res2 += 1
print(res2)
for i in range(k):
	if res[i] == None:
		break
	print(res[i], end=' ')


(n, k) = [int(i) for i in input().split()]
dat = [int(i) for i in input().split()]
d = [0] * 1000000
s = 500000
e = 500000 - 1
st = set()
for f in dat:
	if f in st:
		pass
	else:
		if len(st) == k:
			st.remove(d[e])
			e -= 1
		st.add(f)
		s -= 1
		d[s] = f
print(e - s + 1)
for dd in range(s, e + 1):
	print(d[dd], end=' ')
print()


(n, k) = input().split()
n = int(n)
k = int(k)
idd = list(map(int, input().split()))
m = 0
screen = []
for i in idd:
	if len(screen) == k and i not in screen:
		screen.pop(len(screen) - 1)
	if i not in screen:
		screen.insert(0, i)
print(len(screen))
for i in screen:
	print(i, end=' ')


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
onsc = set()
c = 0
chat = []
for i in a:
	if i in onsc:
		continue
	else:
		chat.append(i)
		c += 1
		onsc.add(i)
		if c > k:
			c == k
			onsc.remove(chat.pop(0))
print(len(chat))
for i in chat[::-1]:
	print(i, end=' ')
print()


from collections import deque
(a, b) = map(int, input().split())
l = list(map(int, input().split()))
c = set()
d = deque()
for x in l:
	if x not in c:
		if len(d) >= b:
			c.remove(d.pop())
		d.appendleft(x)
		c.add(x)
print(len(d))
k = list(d)
for x in k:
	print(x, end=' ')


import sys
(n, k) = list(map(int, input().split()))
msgs = list(map(int, input().split()))
screen = []
for i in msgs:
	if i not in screen:
		screen.insert(0, i)
		if len(screen) > k:
			screen.pop()
print(len(screen))
for i in screen:
	sys.stdout.write(str(i) + ' ')


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
ak = []
for i in arr:
	if len(ak) < k:
		if str(i) not in ak:
			ak.insert(0, str(i))
	elif str(i) not in ak:
		ak.pop()
		ak.insert(0, str(i))
print(len(ak))
print(' '.join(ak))


from collections import deque
nos = list(map(int, input().rstrip().split()))
n = nos[0]
k = nos[1]
ele = list(map(int, input().rstrip().split()))
dis = deque([])
for i in ele:
	if len(dis) < k:
		if i in dis:
			pass
		else:
			dis.append(i)
	elif i in dis:
		pass
	else:
		dis.popleft()
		dis.append(i)
print(len(dis))
for i in range(len(dis)):
	print(dis.pop(), end=' ')


(c, l) = map(int, input().split())
arr = [int(x) for x in input().split()]
q = list()
s = set()
k = 0
for i in arr:
	if i not in s:
		if len(s) == l:
			s -= {q[k]}
			k += 1
		s.add(i)
		q.append(i)
print(len(q) - k)
print(*reversed(q[k:]))


from collections import deque
(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
d = dict()
for i in lis:
	d[i] = 0
dq = deque()
for i in lis:
	if d[i] == 1:
		continue
	if len(dq) < k:
		d[i] = 1
		dq.appendleft(i)
	else:
		d[dq.pop()] = 0
		d[i] = 1
		dq.appendleft(i)
print(len(dq))
print(*dq)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
q = []
mini = min(n, k)
for i in range(n):
	if l[i] in q:
		continue
	elif l[i] not in q:
		if len(q) < k:
			q.insert(0, l[i])
		else:
			q.pop()
			q.insert(0, l[i])
if len(q) > mini:
	q.pop()
print(len(q))
print(*q)


s1 = input()
s1 = s1.strip()
n = int(s1[:s1.index(' ')])
k = int(s1[s1.index(' ') + 1:])
l = [int(n) for n in input().split()]
calls = []
for i in range(n):
	if len(calls) < k:
		if (l[i] in calls) == False:
			calls.insert(0, l[i])
	elif len(calls) == k:
		if (l[i] in calls) == False:
			calls.insert(0, l[i])
			calls.remove(calls[k])
st = ''
for j in calls:
	st += str(j) + ' '
m1 = st.split()
print(len(m1))
print(st)


def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]
from collections import *
(n, k) = inp()
id = arr_inp()
(mem, arr, l) = (defaultdict(lambda : 0), deque(), 0)
for i in range(n):
	if mem[id[i]] == 0:
		if l >= k:
			mem[arr.pop()] = 0
		arr.appendleft(id[i])
		mem[id[i]] = 1
		l += 1
print(len(arr))
print(*arr)


(n, k) = map(int, input().strip().split())
m = []
for a in list(map(int, input().strip().split())):
	if a in m:
		pass
	else:
		m.insert(0, a)
		m = m[:k]
print(len(m))
print(' '.join(map(str, m)))


(n, k) = map(int, input().split())
ids = input().split()
queue = []
for i in ids:
	if len(queue) < k and i not in queue:
		queue.insert(0, i)
	elif len(queue) >= k and i not in queue:
		del queue[-1]
		queue.insert(0, i)
print(len(queue))
print(' '.join(queue))


import collections
(n, k) = [int(i) for i in input().split()]
iD = list(map(int, input().split()))
de = collections.deque([])
s = set(iD)
dic = {}
for i in s:
	dic[i] = 0
for i in range(n):
	if dic[iD[i]] == 1:
		continue
	dic[iD[i]] = 1
	de.appendleft(iD[i])
	if len(de) > k:
		dic[de[-1]] = 0
		de.pop()
print(len(de))
print(*de)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
z = []
a = 0
for i in l:
	if i not in z and a == k:
		z.pop(0)
		a -= 1
	if i not in z:
		z.append(i)
		a += 1
z.reverse()
print(len(z))
print(*z)


from collections import *
from math import *

def I():
	return map(int, input().strip().split())
(n, k) = I()
arr = list(I())
pivot = deque()
mp = defaultdict(bool)
for i in arr:
	if mp[i]:
		continue
	else:
		pivot.appendleft(i)
		mp[i] = True
		if len(pivot) > k:
			mp[pivot[len(pivot) - 1]] = False
			pivot.pop()
print(len(pivot))
print(*pivot)


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
d = {}
m = []
for i in range(n):
	if ids[i] in d and d[ids[i]] == True:
		continue
	if len(m) == k:
		d[m[0]] = False
		m.pop(0)
	d[ids[i]] = True
	m.append(ids[i])
print(len(m))
print(' '.join(map(str, m[::-1])))


from collections import deque
from collections import defaultdict
import sys
Input = sys.stdin.readline
(n, k) = map(int, Input().split())
a = list(map(int, Input().split()))
answer = {}
counter = 0
final = deque()
for i in a:
	if i not in answer or answer[i] == 0:
		answer[i] = 1
		final.appendleft(i)
		if len(final) > k:
			answer[final[-1]] = 0
			final.pop()
print(len(final))
print(*final)


(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
a = list(map(int, input().strip().split(' ')))
cnt = 0
d = dict()
ans = []
st = 0
for i in a:
	if cnt < k and i not in d.keys():
		ans.append(i)
		cnt += 1
		d[i] = 1
	elif cnt == k and i not in d.keys():
		d.pop(ans[st], None)
		st += 1
		ans.append(i)
		d[i] = 1
print(cnt)
for i in range(len(ans) - 1, st - 1, -1):
	print(ans[i], end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
queue = []
for i in arr:
	if i not in queue:
		if len(queue) < k:
			queue.insert(0, i)
		else:
			queue.pop()
			queue.insert(0, i)
print(len(queue))
for i in list(queue):
	print(i, end=' ')
print()


(n, k) = map(int, input().split())
messages = list(map(int, input().split()))
result = []
for message in messages:
	l = len(result)
	if message not in result and l < k:
		result.insert(0, message)
	elif message not in result:
		result.pop(l - 1)
		result.insert(0, message)
print(len(result))
for r in result:
	print(r, end=' ')


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
b = []
i = 0
while i < x:
	if a[i] not in b:
		if len(b) < y:
			b.append(a[i])
		else:
			b.pop(0)
			b.append(a[i])
	i += 1
print(len(b))
print(*b[::-1])


entrada = input().split()
mensagens = int(entrada[0])
display = int(entrada[1])
mensagens_l = input().split()
saida = []
for k in mensagens_l:
	if len(saida) < display and k not in saida:
		saida.append(k)
	elif k not in saida:
		saida.append(k)
		saida.remove(saida[0])
print(len(saida))
saidaf = ''
for k in range(len(saida) - 1, 0, -1):
	saidaf += saida[k] + ' '
saidaf += saida[0]
print(saidaf)


(n, k) = map(int, input().split())
ls = []
a = list(map(int, input().split()))
for x in a:
	if x in ls:
		continue
	elif len(ls) < k:
		ls.insert(0, x)
	else:
		ls.pop()
		ls.insert(0, x)
print(len(ls))
ls = list(map(str, ls))
print(' '.join(ls))


info = [int(k) for k in input().split()]
(n, k) = (info[0], info[1])
dialogs = []
for request in input().split():
	req = int(request)
	if req not in dialogs:
		if len(dialogs) < k:
			dialogs.append(req)
		else:
			del dialogs[0]
			dialogs.append(req)
print(len(dialogs))
s = ''
for i in range(len(dialogs)):
	s += str(dialogs[len(dialogs) - 1 - i]) + ' '
print(s)


(n, k) = map(int, input().split())
process = map(int, input().split())
l = []
s = set()
for e in process:
	if e not in s:
		l.append(e)
		s.add(e)
		if len(l) == k + 1:
			s.remove(l[0])
			l = l[1:]
print(len(l))
print(' '.join(map(str, l[::-1])))


import sys
from collections import deque
I = sys.stdin.readline
(n, k) = map(int, I().split())
id_ = list(map(int, I().split()))
sc = deque()
d = dict()
for i in range(n):
	d[id_[i]] = 0
for i in range(n):
	d[id_[i]] += 1
	if len(sc) < k:
		if d[id_[i]] == 1:
			sc.appendleft(id_[i])
			d[id_[i]] += 1
	elif d[id_[i]] == 1:
		d[sc[-1]] = 0
		sc.pop()
		sc.appendleft(id_[i])
		d[id_[i]] += 1
print(len(sc))
print(*list(sc))


def qw(a):
	c = 0
	for i in range(len(a) - 1):
		if a[i] != a[i + 1]:
			c = c + 1
	return c
t = 1
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	q = []
	for j in range(len(a)):
		if a[j] not in q:
			q.append(a[j])
			if len(q) > k:
				q.pop(0)
print(len(q))
q.reverse()
print(*q)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = set()
ans1 = []
size = 0
for i in range(n):
	if arr[i] not in ans:
		ans.add(arr[i])
		size += 1
		ans1.append(arr[i])
	if size > k:
		ans.discard(ans1[0])
		del ans1[0]
		size -= 1
print(len(ans1))
print(*ans1[::-1])


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = []
l22 = set()
tt = 0
for i in range(n):
	if len(l2) < k and l1[i] not in l22:
		l2.append(l1[i])
		l22.add(l1[i])
	elif len(l2) >= k and l1[i] not in l22:
		l2.append(l1[i])
		l22.add(l1[i])
		l22.remove(l2[tt])
		tt = tt + 1
l2.reverse()
if len(l2) > k:
	print(k)
	print(*l2[0:k])
else:
	print(len(l2))
	print(*l2)


(n, k) = list(map(int, input().split(' ')))
id_arr = list(map(int, input().split(' ')))
phone = []
for id in id_arr:
	if not id in phone:
		phone = [id] + phone
		if len(phone) > k:
			del phone[-1]
print(len(phone))
for message in phone:
	print(message, end=' ')


(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
sort1 = []
for i in range(n):
	if len(sort1) <= k and list1[i] not in sort1:
		sort1.insert(0, list1[i])
		if len(sort1) > k:
			sort1.pop(len(sort1) - 1)
print(len(sort1))
for item in sort1:
	print(item, end=' ')


import math
from collections import deque
(n, k) = [int(x) for x in input().split()]
dq = deque(maxlen=k)
m = -1
for x in input().split():
	x = int(x)
	if not x in dq:
		dq.appendleft(x)
	m = max(x, m)
print(len(dq))
print(*dq)


(n, k) = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
d = []
for i in a:
	if len(d) < k:
		if i not in d:
			d.append(i)
			for j in range(len(d) - 1, 0, -1):
				d[j] = d[j - 1]
			d[0] = i
	elif len(d) == k:
		if i not in d:
			d.pop()
			d.append(i)
			for j in range(len(d) - 1, 0, -1):
				d[j] = d[j - 1]
			d[0] = i
print(len(d))
for i in d:
	print(i, end=' ')


(n, k) = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
msg = []
i = 0
while i < len(l):
	if l[i] not in msg:
		msg.append(l[i])
		if len(msg) > k:
			msg.pop(0)
	i = i + 1
msg = msg[::-1]
print(len(msg))
for i in msg:
	print(i, end=' ')


(n, k) = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
q = []
for i in range(n):
	if lst[i] in q:
		c = 1
	elif len(q) < k:
		q.insert(0, lst[i])
	else:
		del q[k - 1]
		q.insert(0, lst[i])
print(len(q))
for i in range(len(q)):
	print(q[i], end=' ')


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
a = []
for i in c:
	if i not in a and len(a) < k:
		a.append(i)
	elif i not in a:
		a.remove(a[0])
		a.append(i)
print(len(a))
a.reverse()
for j in a:
	print(j, end=' ')


(n, k) = input().split()
n = int(n)
k = int(k)
ar = list(map(int, input().split()))
k_ = 0
a = []
for i in ar:
	if k_ < k:
		if i not in a:
			a.insert(0, i)
			k_ += 1
	elif i not in a:
		del a[k - 1]
		a.insert(0, i)
print(k_)
for i_ in a:
	print(i_, end=' ')


(n, k) = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
out = [-1] * k
for i in range(n):
	if a[i] not in out:
		out = out[-1:] + out[:-1]
		out[0] = a[i]
if -1 in out:
	out = out[:out.index(-1)]
print(len(out))
for j in range(len(out)):
	print(out[j], end=' ')


(n, k) = map(int, input().split())
ids = [int(i) for i in input().split()]
show = []
for id in ids:
	if not id in show:
		show.insert(0, id)
		if len(show) > k:
			del show[k]
print(len(show))
for i in show:
	print(i, end=' ')


(n, k) = map(int, input().split())
q = []
isv = set()
id = list(map(int, input().split()))
for v in id:
	if v not in isv:
		isv.add(v)
		if len(q) == k:
			x = q.pop(0)
			isv.remove(x)
		q.append(v)
print(len(q))
for i in range(len(q) - 1, -1, -1):
	print(q[i], end=' ')


mes = input().split()
ID = input().split()
n = int(mes[0])
k = int(mes[1])
screen = []
for i in ID:
	i = int(i)
	if len(screen) < k and i not in screen:
		screen.insert(0, i)
		continue
	if len(screen) == k and i in screen:
		continue
	if len(screen) == k and i not in screen:
		del screen[-1]
		screen.insert(0, i)
		continue
print(len(screen))
answer = ''
for i in screen:
	answer += str(i)
	answer += ' '
print(answer)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = set()
s = []
for i in l:
	if len(a) < k:
		if i not in a:
			a.add(i)
			s.insert(0, i)
		elif i in a:
			pass
	elif len(a) == k:
		if i not in a:
			temp = s.pop()
			a.remove(temp)
			a.add(i)
			s.insert(0, i)
		if i in a:
			pass
print(len(s))
ans = str(s[0])
ok = 1
for i in s:
	if ok == 1:
		ok = 0
		continue
	ans += ' ' + str(i)
print(ans)


(n, k) = list(map(int, input().split()))
id = list(map(int, input().split()))
out = []
for i in id:
	if i not in out:
		if len(out) == k:
			out.remove(out[-1])
		out.insert(0, i)
print(len(out))
for x in out:
	print(x, end=' ')


import sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
import math
import copy
(N, K) = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
freq = {}
stack = deque()
elements = 0
for i in range(N):
	if arr[i] not in freq:
		if elements < K:
			elements += 1
			freq[arr[i]] = 1
			stack.append(arr[i])
		else:
			freq[arr[i]] = 1
			stack.append(arr[i])
			tmp = stack.popleft()
			freq[tmp] = 0
	elif freq[arr[i]] == 0 and elements == K:
		tmp = stack.popleft()
		freq[tmp] = 0
		stack.append(arr[i])
		freq[arr[i]] = 1
print(elements)
stack = list(stack)
print(*stack[::-1])


(n, k) = map(int, input().split())
lis = [int(x) for x in input().split()]
res = []
for i in lis:
	if i not in res:
		if len(res) < k:
			res = [i] + res
		else:
			res = [i] + res[:len(res) - 1]
print(len(res))
print(*res)


n = int(input().split()[1])
conv = []
msg = map(int, input().split())
for i in msg:
	if len(conv) < n and i not in conv:
		conv = [i] + conv
		continue
	if i in conv:
		continue
	conv = [i] + conv[0:n - 1]
print(len(conv))
r = ''
for i in conv:
	r += str(i) + ' '
print(r[0:len(r) - 1])


from collections import OrderedDict
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
dic = OrderedDict()
s = set()
for i in range(n):
	if arr[i] not in s:
		if len(dic) < k:
			dic[i] = arr[i]
			s.add(arr[i])
		else:
			x = dic.popitem(last=False)
			s.remove(x[1])
			dic[i] = arr[i]
			s.add(arr[i])
print(len(dic))
ans = []
for (i, j) in dic.items():
	ans.append(j)
print(*ans[::-1])


n = list(map(int, input().split()))
h = list(map(int, input().split()))
a = []
i = 0
while i < len(h):
	if h[i] not in a:
		if len(a) < n[1]:
			a.insert(0, h[i])
		else:
			a.pop()
			a.insert(0, h[i])
	i += 1
print(len(a))
i = 0
while i < len(a):
	print(a[i], end=' ')
	i += 1


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = []
d = {}
for i in range(n):
	if len(a) < k:
		if d.get(l[i], 0):
			pass
		else:
			a.append(l[i])
			d[l[i]] = 1
	elif d.get(l[i], 0):
		pass
	else:
		c = a.pop(0)
		a.append(l[i])
		d[c] = 0
		d[l[i]] = 1
print(len(a))
print(*a[::-1])


from collections import deque
(n, k) = map(int, input().split())
myset = set()
mydq = deque()
for i in map(int, input().split()):
	if i in myset:
		continue
	mydq.appendleft(i)
	myset.add(i)
	if len(mydq) > k:
		myset.discard(mydq.pop())
print(len(mydq))
print(*mydq)


(n, k) = map(int, input().split())
idi = input().split()
display = []
for i in idi:
	if i not in display:
		if len(display) < k:
			display.append(i)
		else:
			del display[0]
			display.append(i)
display.reverse()
print(len(display))
for i in display:
	print(i, end=' ')


(n, k) = input().split(' ')
n = int(n)
k = int(k)
messageIDs = input().split(' ')
messageIDs = [int(i) for i in messageIDs]
conversations = []
for i in messageIDs:
	if i not in conversations:
		conversations.insert(0, i)
	if len(conversations) > k:
		conversations.pop()
print(len(conversations))
for i in conversations:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cur = []
for i in range(n):
	if len(cur) < k and a[i] not in cur:
		cur.insert(0, a[i])
	elif a[i] not in cur:
		cur.insert(0, a[i])
		del cur[-1]
print(len(cur))
for i in cur:
	print(i, end=' ')


from math import *

def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]

def print_arr(arr):
	print(*arr, sep=' ')
(n, k) = inp()
id = arr_inp()
arr = []
for i in range(n):
	if id[i] not in arr:
		if len(arr) >= k:
			arr.pop(k - 1)
		arr.insert(0, id[i])
print(len(arr))
print_arr(arr)


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
l = []
for i in range(n):
	if lis[i] not in l:
		l.insert(0, lis[i])
		if len(l) > k:
			l.remove(l[k])
print(len(l))
for x in l:
	print(x, end=' ')


(x, y) = map(int, input().split())
l = list(map(int, input().split()))
l1 = []
for i in l:
	if i in l1:
		continue
	if len(l1) <= y - 1:
		l1.insert(0, i)
	else:
		l1.pop()
		l1.insert(0, i)
print(len(l1))
for i in l1:
	print(i, end=' ')


(n, k) = map(int, input().split())
c = 0
ids = list(map(int, input().split()))
messages = [-1 for i in range(k)]
for id in ids:
	if id not in messages:
		del messages[-1]
		messages = list(reversed(messages))
		messages.append(id)
		messages = list(reversed(messages))
for i in range(len(messages)):
	if messages[i] != -1:
		c += 1
print(c)
for i in range(c):
	print(messages[i], '', end='')


from collections import deque
(amount, can_show) = [int(i) for i in input().split()]
deq = deque()
for sms in input().split():
	sms = int(sms)
	if sms not in deq:
		deq.appendleft(sms)
	if len(deq) > can_show:
		deq.pop()
print(len(deq))
for sms in deq:
	print(sms, end=' ')


def affichage(L):
	for i in range(len(L)):
		L[i] = str(L[i])
	return ' '.join(L)
ch = input()
L = [int(i) for i in ch.split()]
n = L[0]
k = L[1]
ch = input()
L = [int(i) for i in ch.split()]
L2 = []
for i in L:
	if i not in L2:
		L2 = [i] + L2
		if len(L2) > k:
			L2.remove(L2[k])
print(len(L2))
print(affichage(L2))


(n, k) = input().split()
n = int(n)
k = int(k)
list_of_id = input().split()
for i in range(n):
	list_of_id[i] = int(list_of_id[i])
screen = []
for i in range(n):
	if list_of_id[i] in screen:
		continue
	if len(screen) != k:
		screen.insert(0, list_of_id[i])
	else:
		screen.pop()
		screen.insert(0, list_of_id[i])
print(len(screen))
for i in screen:
	print(i, end=' ')


(n, m) = map(int, input().split())
q = []
d = {}
a = list(map(int, input().split()))
for i in a:
	if i not in d:
		d[i] = 1
		if len(q) < m:
			q.append(i)
		else:
			z = q.pop(0)
			del d[z]
			q.append(i)
print(len(q))
print(*q[::-1])


DIM = 200001
deq = [0] * DIM
(n, k) = input().split()
n = int(n)
k = int(k)
sir = input().split()
screen = {}
st = 1
dr = 0
for i in range(n):
	cur_el = int(sir[i])
	if dr <= k - 1:
		if cur_el not in screen:
			screen[cur_el] = 1
			dr += 1
			deq[dr] = cur_el
	elif cur_el not in screen:
		screen.pop(deq[st], None)
		st += 1
		screen[cur_el] = 1
		dr += 1
		deq[dr] = cur_el
print(dr - st + 1)
i = dr
while i >= st:
	print(deq[i], end=' ')
	i -= 1


def friends(k, ids):
	q = []
	for i in ids:
		if i in q:
			continue
		if len(q) == k:
			q.pop()
		q = [i] + q
	print(len(q))
	for i in q:
		print(i, '', end='')
	print()
(n, k) = list(map(int, input().rstrip().split()))
x = list(map(int, input().rstrip().split()))
friends(k, x)


import collections
(a, b) = map(int, input().split())
ar = list(map(int, input().split()))
s = set()
ar1 = collections.deque([])
for i in ar:
	if i not in s:
		s.add(i)
		ar1.appendleft(i)
		if len(s) > b:
			s.remove(ar1[-1])
			ar1.pop()
print(len(s))
print(*ar1)


(n, w) = map(int, input().split())
li = list(map(int, input().split()))
que = []
for i in li:
	if i in que:
		continue
	if len(que) < w:
		que = [i] + que
	elif w == 1:
		que = [i]
	else:
		que = que[:-1]
		que = [i] + que
print(len(que))
print(' '.join((str(i) for i in que)))


(n, k) = map(int, input().split())
A = map(int, input().split())
v = []
for a in A:
	if a in v:
		continue
	v = v[:k - 1]
	v.insert(0, a)
	v = v[-k:]
print(len(v))
print(*v)


(c, l) = map(int, input().split())
arr = [int(x) for x in input().split()]
q = list()
for i in arr:
	if i not in q:
		if len(q) == l:
			q.pop()
		q.insert(0, i)
print(len(q))
for i in q:
	print(i, end=' ')


p = input().rstrip().split(' ')
q = input().rstrip().split(' ')
l = []
for i in range(0, len(q)):
	if len(l) < int(p[1]):
		if int(q[i]) not in l:
			l.insert(0, int(q[i]))
		else:
			continue
	elif int(q[i]) not in l:
		del l[len(l) - 1]
		l.insert(0, int(q[i]))
if len(l) <= min(int(p[0]), int(p[1])):
	print(len(l))
	print(*l)
else:
	print(min(int(p[0]), int(p[1])))
	A = l[0:min(int(p[0]), int(p[1]))]
	print(*A)


from collections import deque
q = deque()
(n, k) = map(int, input().split())
l = 0
s = set()
for i in map(int, input().split()):
	if i not in s:
		if l == k:
			s.discard(q.popleft())
		else:
			l += 1
		q.append(i)
		s.add(i)
print(l)
print(*list(q)[::-1])


from collections import OrderedDict
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = OrderedDict()
arr = [-1] * 4001
start = -1
end = -1
for i in a:
	if i in d:
		pass
	else:
		d[i] = 1
		if start == end and start == -1:
			start += 1
			end += 1
			arr[start] = i
		elif end - start + 1 < k:
			end += 1
			arr[end] = i
		else:
			del d[arr[start]]
			start += 1
			end += 1
			arr[end] = i
print(end - start + 1)
for i in range(end, start - 1, -1):
	print(arr[i], end=' ')


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

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

def getStr():
	return input().strip()
(n, k) = getVars()
a = getList()
b = []
for i in range(n):
	if a[i] not in b:
		b.append(a[i])
		if len(b) > k:
			b.pop(0)
b.reverse()
print(len(b))
print(*b)


a = list(map(int, input().split()))
n = a[0]
k = a[1]
ids = list(map(int, input().split()))
displayed = []
for i in range(n):
	if ids[i] not in displayed:
		displayed.insert(0, ids[i])
		if len(displayed) > k:
			displayed.pop()
print(len(displayed))
print(' '.join(map(str, displayed)))


from collections import deque
(N, P) = map(int, input().split())
nl = map(int, input().split())
Q = deque([])
for n in nl:
	if len(Q) == P:
		if n not in Q:
			Q.appendleft(n)
			Q.pop()
	elif n not in Q:
		Q.appendleft(n)
tmp = [str(i) for i in Q]
print(len(Q))
print(' '.join(tmp))


from collections import deque

def run():
	size = 0
	arr = deque()
	arr_s = set()
	(n, k) = map(int, input().split())
	i = 0
	read = input().split()
	for i in read:
		if i not in arr_s:
			arr_s.add(i)
			if size >= k:
				x = arr.pop()
				arr_s.remove(x)
				arr.appendleft(i)
			else:
				arr.appendleft(i)
				size += 1
	print('{}\n{}'.format(size, ' '.join((i for i in arr))))
run()


from collections import deque
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
q = deque()
used = set()
for id in ids:
	if id not in used:
		if len(q) == k:
			used.remove(q.pop())
		q.appendleft(id)
		used.add(id)
print(len(q))
print(*q)


(n, k) = map(int, input().split())
l = []
d = {}
m = list(map(int, input().split()))
for i in m:
	if len(l) < min(n, k):
		try:
			present = d[i]
			continue
		except KeyError:
			l.insert(0, i)
			d[i] = 1
		continue
	try:
		present = d[i]
	except KeyError:
		d[i] = 1
		d.pop(l.pop(), None)
		l.insert(0, i)
print(len(l))
print(*l)


(a, b) = list(map(int, input().split()))
c = []
st = input().split()
for i in st:
	if len(c) == 0:
		c.append(i)
	elif len(c) < b and len(c) > 0 and (i not in c):
		c.insert(0, i)
	elif len(c) == b and i not in c:
		c.insert(0, i)
		del c[-1]
print(len(c))
print(*c)


(n, k) = map(int, input().split())
d = {}
ls = []
for x in list(map(int, input().split())):
	if d.get(x) == None:
		d[x] = 0
		ls.append(x)
		if len(ls) > k:
			d[ls[0]] = None
			del ls[0]
print(len(ls))
ls.reverse()
print(' '.join(map(str, ls)))


class Node:

	def __init__(self, nodeValue, nodePrevious=None, nodeNext=None):
		self.value = nodeValue
		self.previous = nodePrevious
		self.next = nodeNext

	def __srt__(self):
		return str(self.value)

class DoubleLinkedList:

	def __init__(self):
		self.head = None
		self.tail = None

	def addFirst(self, nodeValue):
		node = Node(nodeValue)
		if self.head != None:
			oldHead = self.head
			oldHead.previous = node
			node.next = self.head
		self.head = node
		if self.tail == None:
			self.tail = node

	def cutLast(self):
		if self.head == self.tail:
			tail = self.tail
			self.head = None
			self.tail = None
			return tail.value
		previousTail = self.tail
		newTail = previousTail.previous
		newTail.next = None
		self.tail = newTail
		return previousTail.value

	def showList(self):
		if not self.head:
			return 'Empty'
		else:
			node = self.head
			r = []
			while node != None:
				r.append(str(node.value))
				node = node.next
			return ' '.join(r)

def solve(n, k, ids):
	d = {}
	l = DoubleLinkedList()
	for v in ids:
		if v not in d:
			if len(d) == k:
				del d[l.cutLast()]
			l.addFirst(v)
			d[v] = 1
	print(len(d))
	print(l.showList())
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
solve(n, k, ids)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = list(set(l))
m = {i: n + 100 for i in s}
common_add = 0
for i in l:
	if m[i] + common_add > k:
		m[i] = -common_add
		common_add += 1
aas = [0] * (k + 1)
for i in s:
	if m[i] + common_add <= k:
		aas[m[i] + common_add] = i
print(min(len(s), k))
print(*aas[1:min(len(s), k) + 1])


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
ans = []
i = 0
j = 0
nums = set()
for ii in range(n):
	if j - i < k:
		if ls[ii] not in nums:
			j += 1
			nums.add(ls[ii])
			ans.append(ls[ii])
	elif ls[ii] not in nums:
		i += 1
		j += 1
		nums.remove(ans[i - 1])
		nums.add(ls[ii])
		ans.append(ls[ii])
print(j - i)
print(' '.join(map(str, ans[i:j][::-1])))


(n, k) = map(int, input().split())
conv = list(map(int, input().split()))
display = [0] * k
for c in conv:
	if c in display:
		continue
	else:
		display = display[:-1]
		display = [c] + display
for z in display:
	if z == 0:
		k -= 1
print(k)
print(*display[:k])


import sys, bisect
from collections import deque

def main():

	def input():
		return sys.stdin.readline()[:-1]
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	u = set()
	l = deque()
	for e in a:
		if len(l) == k:
			if e not in u:
				l.appendleft(e)
				t = l.pop()
				u.remove(t)
				u.add(e)
			else:
				pass
		elif e not in u:
			l.appendleft(e)
			u.add(e)
		else:
			pass
	print(len(l))
	print(*l, sep=' ')
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = []
c = []
for i in range(n):
	if a[i] not in c:
		if len(c) == k:
			c.insert(0, a[i])
			c.remove(c[k])
		else:
			c.insert(0, a[i])
print(len(c))
print(' '.join(map(str, c)))


ip = input().split()
n = int(ip[0], 10)
k = int(ip[1], 10)
l = [int(x) for x in input().split()]
q = []
cnt = 0
for i in range(len(l)):
	if cnt < k:
		if l[i] not in q:
			cnt += 1
			q.insert(0, l[i])
	elif l[i] not in q:
		del q[len(q) - 1]
		q.insert(0, l[i])
print(len(q))
for i in range(len(q)):
	print(q[i], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = dict()
q = []
c = 0
for i in range(n):
	if q == []:
		q.append(a[i])
		c += 1
		s[a[i]] = 1
	elif s.get(a[i]):
		pass
	elif c >= k:
		x = q[-1]
		q = [a[i]] + q[:-1]
		s[a[i]] = 1
		del s[x]
	else:
		q = [a[i]] + q[:]
		s[a[i]] = 1
		c += 1
print(len(q))
print(*q)


import sys
input = sys.stdin.readline
from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = [a[0]]
q = deque(q)
d = {a[0]: 1}
for i in range(1, n):
	if a[i] not in d:
		if len(q) == k:
			del d[q.popleft()]
			q.append(a[i])
			d[a[i]] = 1
		else:
			q.append(a[i])
			d[a[i]] = 1
print(len(q))
q = list(q)
print(*q[::-1])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
noti = []
noc = set()
for i in range(n):
	noc.add(l[i])
	if l[i] not in noti and len(noti) < k:
		noti.insert(0, l[i])
	if l[i] not in noti and len(noti) >= k:
		noti.pop()
		noti.insert(0, l[i])
	if l[i] in noti:
		continue
if len(noc) < min(n, k):
	print(len(noc))
else:
	print(min(n, k))
for i in range(len(noti)):
	print(noti[i], end=' ')


(n, k) = [int(i) for i in input().split()]
convos = [int(i) for i in input().split()]
screen = []
for friend in convos:
	if len(screen) + 1 <= k:
		if friend not in screen:
			screen.insert(0, friend)
	elif friend not in screen:
		del screen[-1]
		screen.insert(0, friend)
print(len(screen), ' '.join(map(str, screen)), sep='\n')


BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
from collections import deque
(n, k) = list(map(int, input().split()))
order = list(map(int, input().split()))
got = deque()
cur = set()
for i in order:
	if i in cur:
		continue
	else:
		cur.add(i)
		got.appendleft(i)
		if len(got) > k:
			cur.remove(got.pop())
print(len(cur))
print(' '.join(list(map(str, got))))


(n, k) = map(int, input().split())
l = []
t2 = list(map(int, input().split()))
for i in range(n):
	t = t2[i]
	if t not in l:
		if len(l) < k:
			l.insert(0, t)
		else:
			l.pop()
			l.insert(0, t)
print(len(l))
for i in l:
	print(i, end=' ')


from collections import deque
(numberOfmsg, numberOfMaxDialogs) = map(int, input().split())
numberOfMaxOnScreen = set()
numberInOrder = deque()
msg = map(int, input().split())
for mes in msg:
	if len(numberOfMaxOnScreen) < numberOfMaxDialogs and mes not in numberOfMaxOnScreen:
		numberOfMaxOnScreen.add(mes)
		numberInOrder.appendleft(mes)
	elif mes not in numberOfMaxOnScreen:
		numberOfMaxOnScreen.remove(numberInOrder.pop())
		numberOfMaxOnScreen.add(mes)
		numberInOrder.appendleft(mes)
print(len(numberInOrder))
print(*numberInOrder)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = list(set(a))
lst = []
for i in range(n):
	if a[i] not in lst:
		lst.append(a[i])
		if len(lst) > k:
			lst.pop(0)
	if len(lst) == len(s):
		break
lst.reverse()
print(len(lst))
for i in lst:
	print(i, end=' ')


from collections import defaultdict, deque
(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
count = 0
Dict = defaultdict(int)
ans = deque([])
for i in lst:
	if Dict[i] == 1:
		continue
	elif count == k:
		temp = ans.pop()
		Dict[temp] = 0
		ans.appendleft(i)
		Dict[i] = 1
	else:
		ans.appendleft(i)
		count += 1
		Dict[i] = 1
print(count)
print(*ans)


class CircularLinkedList:

	class _Node:
		__slots__ = ('_data', '_next')

		def __init__(self, value, next):
			self._data = value
			self._next = next

	def __init__(self):
		self._head = None
		self._tail = None
		self._size = 0

	def getheadData(self):
		return self._head._data

	def getsize(self):
		return self._size

	def is_empty(self):
		return self._size == 0

	def add_first(self, value):
		new_node = self._Node(value, None)
		if self.is_empty():
			new_node._next = new_node
			self._head = new_node
			self._tail = new_node
		else:
			new_node._next = self._head
			self._tail._next = new_node
		self._head = new_node
		self._size += 1

	def add_last(self, value):
		new_node = self._Node(value, None)
		if self.is_empty():
			new_node._next = new_node
			self._head = new_node
			self._tail = new_node
		else:
			new_node._next = self._head
			self._tail._next = new_node
		self._tail = new_node
		self._size += 1

	def add_particular(self, value, position):
		new_node = self._Node(value, None)
		i = 1
		temp = self._head
		while i < position - 1:
			temp = temp._next
			i += 1
		new_node._next = temp._next
		temp._next = new_node
		self._size += 1

	def remove_first(self):
		if self.is_empty():
			print('The  list is empty')
		oh = self._head
		self._tail._next = oh._next
		self._head = oh._next
		self._size -= 1
		if self.is_empty():
			self._tail = None
		return oh._data

	def remove_last(self):
		if self.is_empty():
			print('The list is empty')
		temp = self._head
		i = 1
		while i < self._size - 1:
			temp = temp._next
			i += 1
		value = temp._next._data
		self._tail = temp
		self._tail._next = self._head
		self._size -= 1
		return value

	def print_list(self):
		temp = self._head
		i = 0
		ans = list()
		while i < self._size:
			ans.append(temp._data)
			temp = temp._next
			i += 1
		return ans
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = set()
new = CircularLinkedList()
for i in l:
	if i in s:
		continue
	s.add(i)
	if new.getsize() < k:
		new.add_last(i)
	else:
		new.add_last(i)
		s.discard(new.getheadData())
		new.remove_first()
print(len(s))
p = new.print_list()
p = p[::-1]
for i in p:
	print(i, end=' ')


from collections import deque
I = lambda : map(int, input().split())
(_, k) = I()
q = deque()
X = set()
for x in I():
	if x not in X:
		q.appendleft(x)
		X.add(x)
		if len(q) > k:
			X.remove(q.pop())
print(len(q))
print(*q)


(n, k) = input().split()
n = int(n)
k = int(k)
L = list(map(int, input().split()))
ans = []
for i in range(n):
	if L[i] not in ans:
		ans.append(L[i])
		if len(ans) > k:
			del ans[0]
print(len(ans))
print(*ans[::-1])


(n, k) = [int(i) for i in input().split()]
screen = []
messages = [int(i) for i in input().split()]
for ID in messages:
	if ID not in screen[0:k]:
		screen.insert(0, ID)
print(k if len(screen) > k else len(screen))
print(' '.join([str(i) for i in screen[0:k]]))


import math
(m, n) = map(int, input().split())
a = list(map(int, input().split()))
ss = []
for i in range(m):
	if a[i] not in ss:
		ss.insert(0, a[i])
		if len(ss) > n:
			ss.pop()
print(len(ss))
for i in ss:
	int(i)
	print(i, end=' ')


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
m = [0] * k
for x in l:
	if x in m[:k]:
		continue
	m.insert(0, x)
nn = len(m)
idx = 0
for x in range(nn):
	if m[x] == 0:
		idx = x
		break
if idx >= k:
	print(k)
	for x in m[:k]:
		print(x, end=' ')
else:
	print(idx)
	for x in m[:idx]:
		print(x, end=' ')


import sys
a = tuple(map(int, input().split()))
k = a[1]
liste = tuple(sys.stdin.readline().split())
liste2 = []
for i in liste:
	if i not in liste2:
		liste2.insert(0, i)
		if len(liste2) > k:
			liste2.pop()
print(len(liste2))
print(*liste2)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
res = []
for item in arr:
	if count == 0 or item not in res:
		if k > len(res):
			res.insert(0, item)
			count += 1
		elif item not in res:
			res.pop()
			res.insert(0, item)
print(count)
print(*res)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import *
import queue
(n, k) = I()
l = I()
s = set()
q = []
for i in l:
	if i in s:
		continue
	if len(s) < k:
		s.add(i)
	else:
		a = q.pop(0)
		s.remove(a)
		s.add(i)
	q.append(i)
ans = []
print(len(q))
print(*q[::-1])


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
seen = set()
ans = []
for i in ids:
	if i in seen:
		continue
	else:
		seen.add(i)
		if len(ans) >= min(n, k):
			temp = ans.pop(0)
			seen.remove(temp)
		ans.append(i)
print(len(ans))
while len(ans):
	print(ans.pop(), end=' ')


from collections import deque
(p, k) = map(int, input().split())
nums = list(map(int, input().split()))
state = deque(maxlen=k)
l = 0
for num in nums:
	if num not in state:
		state.appendleft(num)
		if l < k:
			l += 1
ans = ''
for _ in range(l):
	ans += str(state.popleft())
	ans += ' '
laa = l if l < k else k
print(laa)
print(ans[:-1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
res = []
for i in a:
	if i not in res and len(res) < k:
		res.insert(0, i)
	elif i not in res and len(res) == k:
		res.insert(0, i)
		res = res[:len(res) - 1]
print(len(res))
for i in res:
	print(i, end=' ')


(n, s) = map(int, input().rstrip().split())
mydict = {}
mylist = []
for i in map(int, input().rstrip().split()):
	if i not in mydict:
		mydict[i] = 0
		if len(mylist) >= s:
			mydict.pop(mylist.pop())
			mylist = [i] + mylist
		else:
			mylist = [i] + mylist
print(len(mylist))
for i in mylist:
	print(i, '', end='')


from collections import deque
(N, K) = map(int, input().split())
X = list(map(int, input().split()))
is_queue = set()
queue = deque([])
for x in X:
	if x in is_queue:
		continue
	elif len(queue) == K:
		y = queue.pop()
		is_queue.remove(y)
	queue.appendleft(x)
	is_queue.add(x)
print(len(queue))
print(*queue)


x = input()
xx = x.split()
n = int(xx[0])
k = int(xx[1])
s = []
x = input()
xx = x.split()
for i in xx:
	if int(i) not in s:
		s.reverse()
		s.append(int(i))
		s.reverse()
		if len(s) > k:
			del s[k]
print(len(s))
for i in s:
	print(i, end=' ')


(n, limit) = map(int, input().split())
sn = list(map(int, input().split()))
result = []
for i in range(len(sn)):
	if not sn[i] in result:
		result.insert(0, sn[i])
	if len(result) > limit:
		result.pop()
print(len(result))
for i in range(len(result)):
	print(result[i], end=' ')


z = list(map(int, input().split()))
y = list(map(int, input().split()))
arr = []
for i in range(z[0]):
	if y[i] not in arr:
		arr.append(y[i])
	else:
		for j in range(1, z[1] + 1):
			if y[i] == arr[-j]:
				break
			elif j == z[1]:
				arr.append(y[i])
arr.reverse()
temp = []
for i in arr:
	if i not in temp:
		temp.append(i)
inter = len(temp)
kevin = min(z[1], inter)
print(kevin)
for i in range(kevin):
	if i == len(arr) - 1:
		print(arr[i])
	else:
		print(arr[i], end=' ')


a = str(input())
texts = int(a.split()[0])
capacity = int(a.split()[1])
b = input().split()
text_numbers = []
output = []
for i in b:
	text_numbers.append(int(i))
for i in text_numbers:
	if i in output:
		continue
	elif i not in output and len(output) == capacity:
		del output[capacity - 1]
		output.insert(0, i)
	else:
		output.insert(0, i)
print(len(output))
for i in output:
	print(i, end=' ')


from collections import deque
import sys
(n, k) = list(map(int, sys.stdin.readline().rstrip().split()))
qry = list(map(int, sys.stdin.readline().rstrip().split()))
msg = deque()
ids = dict()
for q in qry:
	try:
		t = ids[q]
	except KeyError:
		ids[q] = 1
		msg.appendleft(q)
		if len(msg) > k:
			d = msg.pop()
			del ids[d]
print(len(msg))
for itm in msg:
	print(itm, end=' ')
print()


from sys import stdin, stdout
from collections import deque

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def pp(A):
	for i in A:
		print(i)

def solve():
	(n, k) = ip()
	K = ip()
	A = deque()
	st = set()
	for i in K:
		if i in st:
			continue
		elif len(A) < k and i not in st:
			A.appendleft(i)
			st.add(i)
		else:
			e = A.pop()
			st.remove(e)
			A.appendleft(i)
			st.add(i)
	print(len(A))
	for i in A:
		print(str(i) + ' ', end='')
solve()


from collections import deque
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
lf = deque()
lf_set = set(lf)
for i in range(n):
	if l[i] not in lf_set:
		lf.appendleft(l[i])
		lf_set.add(l[i])
	if len(lf) > k:
		lf_set.remove(lf.pop())
print(len(lf))
print(*lf, sep=' ')


(n, k) = map(int, input().split())
messages_order = list(map(int, input().split()))
(contats, displayed) = (set(), [])
for i in range(n):
	if messages_order[i] not in contats:
		displayed.append(messages_order[i])
		contats.add(messages_order[i])
		if len(displayed) > k:
			contats.remove(displayed[0])
			displayed.pop(0)
print(len(displayed))
print(*displayed[::-1])


from collections import deque
(n, k) = map(int, input().split())
l = 0
ids = list(map(int, input().split()))
q = deque()
val = set()
for i in ids:
	if not i in val:
		l += 1
		val.add(i)
		q.appendleft(i)
		if len(q) > k:
			l -= 1
			t = q.pop()
			val.discard(t)
print(l)
print(*q)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = []
map = {}
size = 0
for i in range(n):
	if map.get(a[i]) == 1:
		continue
	if size < k:
		q.append(a[i])
		map[a[i]] = 1
		size += 1
	else:
		map[q.pop(0)] = 0
		map[a[i]] = 1
		q.append(a[i])
q = q[::-1]
print(len(q))
s = ''
for i in range(len(q)):
	s = s + str(q[i]) + ' '
print(s)


sysIn = list(map(int, input().split()))
n = sysIn[0]
k = sysIn[1]
ids = list(map(int, input().split()))
messages = []
for id in ids:
	if not id in messages:
		if len(messages) == k and messages:
			messages.pop(len(messages) - 1)
		messages.insert(0, id)
print(len(messages))
strMessage = ' '.join(map(str, messages))
print(strMessage)


import sys
input = sys.stdin.readline
from collections import defaultdict, deque
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
flag = defaultdict(int)
q = deque([])
for id_i in ids:
	if flag[id_i] == 0:
		q.appendleft(id_i)
		flag[id_i] = 1
		if len(q) > k:
			remove_id = q.pop()
			flag[remove_id] = 0
print(len(q))
print(*q)


from collections import *
(n, k) = map(int, input().split())
(*a,) = map(int, input().split())
d = deque()
for i in a:
	if i not in d:
		d.appendleft(i)
		if len(d) > k:
			d.pop()
print(len(d))
print(*d)


(number_mes, appear_on_screen) = list(map(int, input().split()))
friends_ord = input().split()
screen = []
screen_set = set()
for friend in friends_ord:
	if friend in screen_set:
		continue
	elif len(screen) >= appear_on_screen:
		screen_set.discard(screen.pop(0))
		screen.append(friend)
		screen_set.add(friend)
	else:
		screen.append(friend)
		screen_set.add(friend)
print(len(screen))
print(' '.join(reversed(screen)))


(a, b) = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
f = [0] * b
count = 0
for i in p:
	if i not in f:
		f.insert(0, i)
		f.pop()
print(len(f) - f.count(0))
for i in f:
	if i != 0:
		print(i, end=' ')


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
res = []
table = set()
for id in ids:
	if len(res) < k:
		if id not in table:
			table.add(id)
			res.append(id)
	elif id not in table:
		table.remove(res[0])
		table.add(id)
		res.append(id)
		res.pop(0)
print(len(res))
res.reverse()
print(*res)


from collections import deque
(n, k) = map(int, input().strip().split())
m = deque()
s = set()
c = 0
for a in list(map(int, input().strip().split())):
	if a in s:
		continue
	c += 1
	m.appendleft(a)
	s.add(a)
	if c > k:
		s.remove(m.pop())
		c -= 1
print(len(m))
print(' '.join(map(str, m)))


x = input().split()
ids = input().split()
n = int(x[0])
k = int(x[1])
max_count = k
count = 0
screen = []
set_screen = set()
for i in ids:
	x = i
	if x in set_screen:
		continue
	else:
		screen.insert(0, x)
		set_screen.add(x)
		count += 1
		if count > max_count:
			p = screen.pop(-1)
			set_screen.remove(p)
			count -= 1
print(len(screen))
print(' '.join(screen))


def main():
	(n, k) = map(int, input().split())
	tab = list(map(int, input().split()))
	q = [0] * (n + 1)
	seen = {}
	l = n
	r = n
	size = 0
	for item in tab:
		if not item in seen or (item in seen and seen[item] != 1):
			if size >= k:
				seen[q[r]] = 0
				q[r] = 0
				r -= 1
				size -= 1
			q[l] = item
			l -= 1
			size += 1
			seen[item] = 1
	print(size)
	print(*q[l + 1:r + 1])
main()


from collections import deque
(n, k) = list(map(int, input().split()))
lst = list(map(int, input().split()))
q = deque()
s = set()
for i in range(n):
	if lst[i] not in s:
		if len(q) == k:
			s.remove(q.popleft())
			q.append(lst[i])
			s.add(lst[i])
		else:
			q.append(lst[i])
			s.add(lst[i])
res = []
num = len(q)
print(num)
q.reverse()
print(*q)


from collections import deque
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = 0
q = deque()
for i in range(len(a)):
	for j in range(len(q)):
		if q[j] == a[i]:
			f = 1
			break
	if f == 1:
		f = 0
		continue
	if len(q) == k:
		q.pop()
	q.appendleft(a[i])
print(len(q))
for i in range(len(q)):
	print(q[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
nl = []
for i in range(n):
	if l[i] not in nl:
		if len(nl) < k:
			nl.append(l[i])
		else:
			del nl[0]
			nl.append(l[i])
print(len(nl))
print(*reversed(nl))


def mi():
	return map(int, input().split())
(n, k) = mi()
a = list(mi())
ls = set()
stack = []
for i in range(n):
	if a[i] in ls:
		continue
	if len(ls) < k:
		stack.insert(0, a[i])
		ls.add(a[i])
	else:
		ls.remove(stack[-1])
		del stack[-1]
		stack.insert(0, a[i])
		ls.add(a[i])
print(len(stack))
for i in range(len(stack)):
	if stack[i]:
		print(stack[i], end=' ')
print()


(n, m) = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
lst2 = []
for i in lst:
	if i in lst2:
		pass
	else:
		lst2 = [i] + lst2
	if len(lst2) > m:
		lst2.pop(-1)
print(len(lst2))
for i in lst2:
	print(i, end=' ')


(n, k) = [int(i) for i in input().split()]
idd = [int(i) for i in input().split()]
d = []
a = set()
for i in idd:
	if len(d) < k and i not in a:
		d.append(i)
		a.add(i)
	elif i not in a:
		a.remove(d[0])
		a.add(i)
		del d[0]
		d.append(i)
print(len(d))
for i in d[::-1]:
	print(i, end=' ')


(n, k) = [x for x in map(int, input().split())]
A = [x for x in map(int, input().split())]
res = []
for i in A:
	if len(res) < k:
		if i not in res:
			res.insert(0, i)
	elif i not in res:
		res.insert(0, i)
		del res[-1]
print(len(res))
for i in res:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0] * k
for i in a:
	if i not in b:
		b = [i] + b[:-1]
b = b[:len(b) - b.count(0)]
print(len(b))
for i in b:
	print(i, end=' ')


import sys, collections
(n, k) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
mes = collections.deque()
for i in range(n):
	if arr[i] in mes:
		continue
	elif len(mes) < k:
		mes.appendleft(arr[i])
	else:
		mes.pop()
		mes.appendleft(arr[i])
print(len(mes))
print(' '.join(map(str, mes)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
o = []
for i in range(n):
	if l[i] in o:
		continue
	o.append(l[i])
	if len(o) > k:
		o.pop(0)
print(len(o))
o = o[::-1]
print(*o)


entrada1 = list(map(int, input().split()))
k = entrada1[1]
entrada2 = list(map(int, input().split()))
lista = []
for ids in entrada2:
	if len(lista) < k and ids not in lista:
		lista.append(ids)
	if len(lista) == k and ids not in lista:
		del lista[0]
		lista.append(ids)
lista.reverse()
print(len(lista))
cont = 0
for nums in lista:
	if cont < len(lista) - 1:
		print(nums, end=' ')
	else:
		print(nums)
	cont += 1


import math
import collections
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
qu = collections.deque([])
d = {}
for i in l:
	if d.get(i, 0) != 0:
		pass
	elif len(qu) == k:
		qu.appendleft(i)
		t = qu.pop()
		d[t] -= 1
		d[i] = 1
	else:
		qu.appendleft(i)
		d[i] = 1
print(len(qu))
print(*qu)


(n, k) = map(int, input().split())
a = input().split()
b = []
m = min(n, k)
for i in a:
	if len(b) <= m:
		if i not in b:
			b.append(i)
	if len(b) > m:
		del b[0]
print(len(b))
for i in range(1, len(b) + 1):
	print(b[-i], end=' ')


from _collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = deque()
c = set()
(ans, res) = (0, 0)
for i in a:
	if i not in c:
		b.appendleft(i)
		c.add(i)
		if len(b) > k:
			c.discard(b[-1])
			del b[-1]
print(len(b))
print(*b)


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
from collections import deque
(n, k) = map(int, input().split())
quee = deque()
a = list(map(int, input().split()))
s = set()
for i in range(n):
	if a[i] in s:
		continue
	if len(s) == k:
		x = quee.pop()
		s.remove(x)
	s.add(a[i])
	quee.appendleft(a[i])
print(len(s))
for i in quee:
	print(i, end=' ')
print()


import math
(n, k) = map(int, input().split())
listr = list(map(int, input().split()))
A = []
for i in listr:
	if i not in A:
		if len(A) == 0:
			A.append(i)
		elif len(A) < k:
			A.insert(0, i)
		elif len(A) == k:
			A.pop()
			A.insert(0, i)
print(len(A))
print(*A, end=' ')
print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
import queue
s = set()
q = queue.Queue(k)
for x in a:
	if x not in s:
		try:
			q.put(x, block=False)
			s.add(x)
		except queue.Full:
			s.remove(q.get(block=False))
			q.put(x, block=False)
			s.add(x)
ans = list()
while not q.empty():
	ans.append(q.get(block=False))
print(len(ans))
print(' '.join(map(str, ans[::-1])))


import math

def test(val, msgs):
	show = []
	for i in msgs:
		if i not in show:
			if len(show) < val:
				show.insert(0, i)
			else:
				show.pop(-1)
				show.insert(0, i)
	print(len(show))
	for i in show:
		print(f'{i} ', end='')
w = int(input('').split(' ')[1])
lst = input('').split(' ')
lst = [int(i) for i in lst]
test(w, lst)


from collections import deque
(n, k) = map(int, input().split())
d = list(map(int, input().split()))
p = dict()
t = deque([])
for i in range(n):
	if not d[i] in p or p[d[i]] == 0:
		p[d[i]] = 1
		if len(t) == k:
			p[t[-1]] = 0
			t.pop()
		t.appendleft(d[i])
res = list(t)
print(len(res))
for elem in res:
	print(elem, end=' ')


(n, k) = map(int, input().split())
seq = list(map(int, input().split()))
l = [0] * k
j = 1
for i in range(n):
	if seq[i] not in l:
		if 0 in l:
			l[k - j] = seq[i]
			j += 1
		else:
			d = l.pop(-1)
			l.insert(0, seq[i])
b = list(filter(0 .__ne__, l))
print(len(b))
print(' '.join((str(x) for x in b)))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
msg_text = set()
msg_conv = []
for x in a:
	if x not in msg_text:
		if len(msg_conv) == k:
			_ = msg_conv.pop(0)
		msg_conv.append(x)
		msg_text = set(msg_conv)
f = set()
ans = []
for x in msg_conv:
	if x not in f:
		f.add(x)
		ans.append(x)
print(len(ans))
print(' '.join(list(map(str, reversed(ans)))))


import collections

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, k) = mi()
d = li()
b = collections.deque([])
s = set(d)
l1 = list(s)
di = {}
for i in range(len(l1)):
	di[l1[i]] = 0
for i in range(n):
	if len(b) < k and di[d[i]] != 1:
		b.appendleft(d[i])
		di[d[i]] = 1
	elif di[d[i]] != 1:
		di[b[-1]] = 0
		b.pop()
		b.appendleft(d[i])
		di[d[i]] = 1
l = list(b)
print(len(l))
for i in l:
	print(i, end=' ')


[n, k] = map(int, input().split())
a = list(map(int, input().split()))
answ = []
for i in range(n):
	curr = a[i]
	inScreen = False
	pos = -1
	for j in range(len(answ)):
		if answ[j] == a[i]:
			inScreen = True
			pos = j
	if not inScreen:
		if len(answ) == k:
			answ.pop(0)
		answ.append(a[i])
print(len(answ))
print(' '.join([str(x) for x in answ[::-1]]))


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
(n, k) = mi()
a = li()
v = set()
p = deque([])
x = 0
for i in range(n):
	if a[i] not in v:
		p.append(a[i])
		v.add(a[i])
		x += 1
		if x > k:
			z = p.popleft()
			v.discard(z)
			x -= 1
p = list(p)
print(x)
print(*p[::-1])


records1 = list(map(int, input().split()))
records = records1[0]
size = records1[1]
li = list(map(int, input().split()))
li2 = []
for i in range(0, len(li)):
	if li[i] in li2:
		continue
	elif len(li2) >= size:
		li2.pop(0)
		li2.append(li[i])
	else:
		li2.append(li[i])
print(len(li2))
li3 = li2[::-1]
for i in li3:
	print(i, end=' ')


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(n, k) = Read.list_int()
	ids = Read.list()
	a = []
	len_a = 0
	for i in ids:
		c = True
		for j in range(len_a - k, len_a):
			if j >= 0 and a[j] == i:
				c = False
		if c:
			a.append(i)
			len_a += 1
	count = 0
	res = ''
	for i in range(len_a - 1, max(0, len_a - k) - 1, -1):
		res += a[i] + ' '
		count += 1
	print(count)
	print(res)
query_count = 1
for j in range(query_count):
	solve()


from collections import deque
lis = deque()
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
dic = {}
for i in arr:
	dic[i] = 0
for i in arr:
	if dic[i] == 0:
		if len(lis) == k:
			f = lis.popleft()
			dic[f] = 0
		lis.append(i)
		dic[i] = 1
result = list(lis)
print(len(result))
print(*result[::-1])


import sys
input = sys.stdin.readline
from collections import deque
t = 1
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	hm = dict()
	queue = deque(maxlen=k)
	for i in range(n):
		if hm.get(a[i], 0) == 0:
			if len(queue) == k:
				hm[a[queue.popleft()]] = 0
			hm[a[i]] = 1
			queue.append(i)
	queue.reverse()
	print(len(queue))
	for i in queue:
		print(a[i], end=' ')
	print()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
t = []
for i in l:
	if i in t:
		pass
	else:
		t.insert(0, i)
		if len(t) > k:
			t.pop(-1)
print(len(t))
for i in t:
	print(i, end=' ')


from collections import deque
(n, k) = map(int, input().split())
data = list(map(int, input().split()))
m = set()
q = deque()
for i in data:
	if i not in m:
		if len(q) >= k:
			m.remove(q.pop())
		q.appendleft(i)
		m.add(i)
print(len(q))
print(*q)


from collections import deque
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
messages = deque([])
check = set()
for i in range(n):
	if len(messages) < k:
		if arr[i] not in check:
			messages.append(arr[i])
			check.add(arr[i])
	elif arr[i] not in check:
		elem = messages.popleft()
		check.remove(elem)
		messages.append(arr[i])
		check.add(arr[i])
print(len(messages))
for i in range(len(messages) - 1, -1, -1):
	print(messages[i], end=' ')


from collections import deque
(n, k) = map(int, input().split())
messages = list(map(int, input().split()))
contained = set()
fila = deque()
for i in range(n):
	num = messages[i]
	if num not in contained:
		contained.add(num)
		if len(fila) < k:
			fila.append(num)
		else:
			contained.remove(fila.popleft())
			fila.append(num)
	else:
		pass
print(len(fila))
while len(fila) > 1:
	print(fila.pop(), end=' ')
print(fila.pop())


from collections import deque
q = deque()
(n, k) = map(int, input().split())
id_ = list(map(int, input().split()))
for item in id_:
	if item not in q:
		q.appendleft(item)
		if len(q) > k:
			q.pop()
print(len(q))
print(*q)


from collections import deque
(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
dq = deque()
sc = set()
for el in arr:
	if el in sc:
		continue
	if len(dq) == k:
		sc.remove(dq.pop())
	sc.add(el)
	dq.appendleft(el)
print(len(dq))
for el in dq:
	print(el, end=' ')
print()


(n, k) = map(int, input().split())
d = list(map(int, input().split()))
res = []
for _ in d:
	if _ not in res:
		res.insert(0, _)
	if _ in res[k:]:
		res.remove(_)
		res.insert(0, _)
m = list(res[0:k])
print(len(m))
print(' '.join((str(i) for i in m)))


ip = input().split()
n = int(ip[0])
k = int(ip[1])
msgs = list(map(int, input().split()))
conv = []
for i in msgs:
	if not i in conv:
		conv.insert(0, i)
		if len(conv) > k:
			del conv[-1]
print(len(conv))
for i in conv:
	print(i, end=' ')


from collections import defaultdict
(n, k) = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
tmp = defaultdict(lambda : -1)
run = 1
for num in arr:
	if tmp[num] in range(max(run - k, 1), run):
		continue
	tmp[num] = run
	run += 1
rev = {}
for (key, val) in tmp.items():
	rev[val] = key
run -= 1
tot = min(run, k)
print(tot)
ans = []
for _ in range(tot):
	ans.append(rev[run])
	run -= 1
print(*ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		(n, k) = ria()
		a = ria()
		d = {}
		curcon = deque([])
		for i in range(n):
			z = a[i]
			if z not in d:
				if len(curcon) == k:
					del d[curcon[-1]]
					curcon.pop()
				curcon.appendleft(z)
				d[z] = 1
		wi(len(list(curcon)))
		wia(list(curcon))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import collections
(n, k) = map(int, input().split(' '))
frs = input().split(' ')
shown = collections.deque()
j = 1
for i in range(len(frs)):
	if frs[i] not in list(shown)[:k]:
		shown.appendleft(frs[i])
	pass
print(len(list(shown)[:k]))
print(' '.join(list(shown)[:k]))
pass


nk = [int(c) for c in input().split()]
idi = input().split()
out = []
i = 0
while i < nk[0]:
	if out.count(idi[i]) == 0 and len(out) != nk[1]:
		out.insert(0, idi[i])
	elif out.count(idi[i]) == 0 and len(out) == nk[1]:
		out.pop(-1)
		out.insert(0, idi[i])
	i = i + 1
print(len(out))
print(' '.join(out))


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
check = deque()
my_set = set()
for i in range(len(a)):
	if a[i] in my_set:
		continue
	if len(check) >= k:
		my_set.discard(check.pop())
	my_set.add(a[i])
	check.appendleft(a[i])
print(len(check))
print(*check)


(n, k) = [int(i) for i in input().split()]
screen = []
messages = [int(i) for i in input().split()]
for i in range(n):
	if messages[i] not in screen:
		screen.insert(0, messages[i])
		if len(screen) > k:
			screen = screen[:-1]
print(len(screen))
str1 = ' '.join((str(e) for e in screen))
print(str1)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
ans = []
len_ans = 0
for i in lst:
	if i not in ans:
		ans.insert(0, i)
		len_ans += 1
		if len_ans > k:
			ans.pop()
			len_ans -= 1
print(len_ans)
for i in ans:
	print(i, end=' ')
print()


import sys
from math import *
from collections import *
inp = lambda : map(int, input().split())
(n, k) = inp()
res = deque()
a = set(res)
for i in inp():
	if i not in a:
		a.add(i)
		if len(res) == k:
			a.remove(res[len(res) - 1])
			res.pop()
			res.appendleft(i)
		else:
			res.appendleft(i)
print(len(res))
print(*res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
	if a[i] in b:
		continue
	else:
		b.insert(0, a[i])
	if len(b) > k:
		b.pop()
print(len(b))
s = ''
for i in range(len(b)):
	s += str(b[i]) + ' '
print(s)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
for i in range(n):
	d[l[i]] = 0
l1 = []
cnt = 0
ind = 0
for i in range(n):
	if d[l[i]] != 1:
		if cnt < k:
			l1.append(l[i])
			cnt += 1
			d[l[i]] = 1
		else:
			d[l1[ind]] = 0
			l1.append(l[i])
			d[l[i]] = 1
			ind += 1
print(cnt)
for i in range(len(l1) - 1, ind - 1, -1):
	print(l1[i], end=' ')


from collections import deque
(n, k) = list(map(int, input().split()))
ar = list(map(int, input().split()))
lol = deque([])
for elem in ar:
	if elem not in lol:
		if len(lol) == k:
			lol.pop()
		lol.appendleft(elem)
print(len(lol))
print(*lol)


(m, k) = [int(_) for _ in input().split(' ')]
array = [int(_) for _ in input().split(' ')]
screen = []
for item in array:
	if len(screen) >= k:
		if not item in screen[len(screen) - k:]:
			screen.append(item)
	elif not item in screen:
		screen.append(item)
if len(screen) > k:
	print(k)
	for x in screen[:len(screen) - k - 1:-1]:
		print(x, end=' ')
else:
	print(len(screen))
	for x in screen[::-1]:
		print(x, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
num = min(len(set(arr)), k)
ans = []
for j in arr:
	if j not in ans:
		ans = [j] + ans
		if len(ans) > k:
			ans.pop()
print(num)
print(*ans)


(n, k) = map(int, input().split())
f = list(map(int, input().split()))
z = []
i = 0
for i in range(n):
	if z.count(f[i]) == 0:
		z.append(f[i])
		while z.__len__() > k:
			z.remove(z[0])
print(z.__len__())
z.reverse()
print(*z)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
sad = 0
for i in a:
	if not i in b:
		b = [i] + b
		sad += 1
		if sad > k:
			b = b[:k]
			sad -= 1
print(sad)
for i in b:
	print(i, end=' ')


from collections import deque
(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
l = deque()
ls = set()
c = 0
for i in d:
	if i in ls:
		continue
	if len(l) == k:
		ls.remove(l[-1])
		l.pop()
	l.appendleft(i)
	ls.add(i)
	c += 1
print(len(l))
print(*l)


(n, k) = map(int, input().split())
idi = list(map(int, input().split()))
l = []
for i in range(len(idi)):
	if idi[i] not in l:
		if len(l) == k:
			l.pop()
		l.insert(0, idi[i])
print(len(l))
for ele in l:
	print(ele, end=' ')
print()


from collections import deque
(n, k) = map(int, input().split())
screen = deque(maxlen=k)
for elem in map(int, input().split()):
	if elem not in screen:
		screen.append(elem)
print(len(screen))
print(*reversed(screen))


(n, m) = map(int, input().split())
mylist = list(map(int, input().split()))
arr = []
for val in mylist:
	if val in arr:
		continue
	arr.insert(0, val)
	if len(arr) > m:
		arr.pop()
print(len(arr))
for val in arr:
	print(val, end=' ')


def main():
	(n, k) = map(int, input().split(' '))
	gl = list(map(int, input().split(' ')))
	l = []
	for i in range(len(gl)):
		if len(l) < k:
			if gl[i] in l:
				pass
			else:
				l = [gl[i]] + l
		elif len(l) >= k:
			if gl[i] in l:
				pass
			else:
				l.pop()
				l = [gl[i]] + l
	print(len(l))
	for i in l:
		print(i, end=' ')
main()


from collections import deque
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
q = deque()
hash = {}
for i in range(len(a)):
	if hash.get(a[i]) == 1:
		continue
	if len(q) == k:
		hash.pop(q[len(q) - 1])
		q.pop()
	q.appendleft(a[i])
	hash.update({a[i]: 1})
print(len(q))
for i in range(len(q)):
	print(q[i], end=' ')


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dic = {}
calls = []
qtd = 0
for i in range(n):
	x = arr[i]
	if x not in dic or dic[x] < qtd - k:
		dic[x] = qtd
		calls += [x]
		qtd += 1
st = ''
for i in range(min(qtd, k)):
	st += str(calls[qtd - i - 1]) + ' '
print(min(qtd, k))
print(st)


(n, k) = [int(i) for i in input().split()]
ids = [int(i) for i in input().split()]
length = len(set(ids))
if length <= k:
	print(length)
else:
	print(k)
osf = []
for i in range(len(ids)):
	if ids[i] not in osf:
		osf.insert(0, ids[i])
	if len(osf) > k:
		osf.remove(osf[-1])
for i in osf:
	print(i, end=' ')
print()


(n, k) = map(int, input().split(' '))
stream = [*map(int, input().split(' '))]
h = []
for num in stream:
	if num not in h:
		if len(h) >= k:
			h = h[1:]
		h.append(num)
print(len(h))
for x in range(len(h) - 1, -1, -1):
	print(h[x], end=' ')


(n, k) = list(map(int, input().split()))
array = []
array.append(list(map(int, input().split())))
arr = []
for i in range(0, len(array[0])):
	count = 0
	length = len(arr)
	if length < k:
		for j in range(0, length):
			if array[0][i] == arr[j]:
				count = 1
				break
		if count == 0:
			arr.append(array[0][i])
	else:
		for j in range(0, length):
			if array[0][i] == arr[j]:
				count = 1
				break
		if count == 0:
			del arr[0]
			arr.append(array[0][i])
print(len(arr))
arr1 = []
for i in range(0, len(arr)):
	arr1.append(arr[len(arr) - 1 - i])
print(*arr1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
z = []
for i in range(n):
	if l[i] not in z:
		z.insert(0, l[i])
		if len(z) == m + 1:
			z.pop()
print(len(z))
print(*z)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
r = []
d = set()
for i in range(n):
	if a[i] in d:
		continue
	if len(r) >= k:
		d.remove(r.pop(0))
	r.append(a[i])
	d.add(a[i])
print(len(r))
for i in range(len(r) - 1, -1, -1):
	print(r[i], end=' ')


import os, sys, math
import collections
if os.path.exists('testing'):
	name = os.path.basename(__file__)
	if name.endswith('.py'):
		name = name[:-3]
	src = open(name + '.in.txt', encoding='utf8')
	input = src.readline
(n, k) = map(int, input().strip().split())
ns = list(map(int, input().strip().split()))

def solve():
	used = set()
	messages = collections.deque()
	for v in ns:
		if v not in used:
			used.add(v)
			messages.appendleft(v)
			if len(used) > k:
				z = messages.pop()
				used.remove(z)
	return list(messages)
res = solve()
print(len(res))
print(' '.join(map(str, res)))


from collections import *
r = []
(n, m) = map(int, input().split())
l = deque(list(map(int, input().split())))
r = deque(r)
for i in range(len(l)):
	if l[i] in r:
		pass
	if l[i] not in r:
		r.appendleft(l[i])
		if len(r) > m:
			r.pop()
print(len(r))
for i in r:
	print(i, end=' ')


(n, k) = map(int, input().split())
ids_in = list(map(int, input().split()))
ids_out = []
for id_ in ids_in:
	if id_ not in ids_out:
		ids_out.insert(0, id_)
		if len(ids_out) > k:
			del ids_out[-1]
print(len(ids_out))
print(*ids_out)


from collections import deque

def solve(n, k, ids):
	opened = set()
	chats = deque()
	for id in ids:
		if id in opened:
			continue
		if len(chats) >= k:
			opened.remove(chats.pop())
		opened.add(id)
		chats.appendleft(id)
	return chats
(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
chats = solve(n, k, ids)
print(len(chats))
print(' '.join(map(str, chats)))


import collections
(n, k) = map(int, input().split())
mem = set()
dq = collections.deque([])
arr = list(map(int, input().split()))
for v in arr:
	if v not in mem:
		dq.appendleft(v)
		mem.add(v)
		if len(dq) > k:
			mem.remove(dq.pop())
print(len(dq))
print(*dq)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
out = list()
for i in range(n):
	if arr[i] not in out:
		if len(out) < k:
			out.insert(0, arr[i])
		else:
			out.pop()
			out.insert(0, arr[i])
print(len(out))
print(*out)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(len(a)):
	d[a[i]] = 0
l = 0
i = 0
st = []
last_pos = 0
for i in range(len(a)):
	if d[a[i]] == 0:
		if l < k:
			st.append(a[i])
			d[a[i]] = 1
			l += 1
		else:
			d[st[last_pos]] = 0
			d[a[i]] = 1
			st.append(a[i])
			last_pos += 1
st.reverse()
if len(st) > k:
	print(k)
else:
	print(len(st))
print(*st[:k])


n_k = [int(x) for x in input().split()]
ids = input().split()
n = n_k[0]
k = n_k[1]
tela = []
for i in range(n):
	if ids[i] not in tela:
		if len(tela) == k:
			del tela[k - 1]
		tela.insert(0, ids[i])
print(len(tela))
print_string = ''
for id in tela:
	print_string = print_string + id + ' '
print_string.rstrip()
print(print_string)


from queue import Queue
from collections import deque
Q = deque()
in_conv = {}
(n, k) = list(map(int, input().split()))
msg = list(map(int, input().split()))
for i in msg:
	in_conv[i] = 0
size = 0
for i in msg:
	if size < k:
		if in_conv[i] == 0:
			Q.append(i)
			in_conv[i] = 1
			size += 1
	elif in_conv[i] == 0:
		Q.append(i)
		in_conv[i] = 1
		in_conv[Q.popleft()] = 0
result = list(Q)
print(len(result))
for i in range(len(result) - 1, -1, -1):
	print(result[i], end=' ')


from collections import deque, defaultdict
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = deque()
d = defaultdict(lambda : 0)
for i in range(n):
	if d[a[i]] == 0:
		if len(l) == k:
			x = l.pop()
			l.appendleft(a[i])
			d[x] = 0
			d[a[i]] = 1
		else:
			l.appendleft(a[i])
			d[a[i]] = 1
print(len(l))
print(*l)


(n, k) = map(int, input().split(' '))
id_ = list(map(int, input().split(' ')))
answer = []
for id_i in id_:
	if len(answer) < k and id_i not in answer:
		answer.insert(0, id_i)
	elif id_i not in answer:
		answer.pop(len(answer) - 1)
		answer.insert(0, id_i)
answer = [str(i) for i in answer]
print(len(answer))
print(' '.join(answer))


(n, k) = map(int, input().strip().split()[:2])
l = list(map(int, input().strip().split()[:n]))
z = []
for x in range(len(l)):
	if l[x] not in z:
		z.insert(0, l[x])
		z = z[:k]
print(len(z))
print(*z)


lis = list(map(int, input().split(' ')))
(n, k) = (lis[0], lis[1])
out = []
inp = list(map(int, input().split(' ')))
for i in inp:
	if i not in out:
		if len(out) < k:
			out.append(i)
		else:
			out.pop(0)
			out.append(i)
	else:
		pass
print(len(out))
for i in reversed(out):
	print(i, end=' ')


import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def Factor(n):
	Ans = []
	d = 2
	while d * d <= n:
		if n % d == 0:
			Ans.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		Ans.append(n)
	return Ans
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = set()
deq = deque()
for i in a:
	if i not in d:
		if len(deq) >= k:
			d.remove(deq.pop())
		deq.appendleft(i)
		d.add(i)
print(len(deq))
print(*deq)


import collections as cl
(n, k) = list(map(int, input().split(' ')))
N = cl.deque(list(map(int, input().split(' '))))
curr = cl.deque()
l = {}
tmp = []
A = ''
while N:
	cid = N.popleft()
	if l.get(cid, 0) == 0:
		l[cid] = 1
		if len(curr) == k:
			x = curr.pop()
			l[x] = 0
		curr.appendleft(cid)
print(len(curr))
print(*curr)


(n, k) = map(int, input().split(' '))
re = []
show = []
for i in range(k):
	show.append(0)
s = input()
re = s.split(' ')
re = list(map(int, re))
x = 0
for i in range(len(re)):
	mark = 0
	for j in range(k):
		if re[i] == show[j]:
			mark += 1
	if mark == 0:
		show[x] = re[i]
		x += 1
	if x == k:
		break
if n >= k:
	for i in range(k, n):
		mark = 0
		for j in range(k):
			if show[j] == re[i]:
				mark += 1
		if mark == 0:
			del show[0]
			show.append(re[i])
count = 0
for i in range(k - 1, -1, -1):
	if show[i] != 0:
		count += 1
print(count)
for i in range(k - 1, -1, -1):
	if show[i] != 0:
		print('%d' % show[i], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
kq = []
for i in a:
	them = True
	for j in kq:
		if i == j:
			them = False
			break
	if them:
		if len(kq) == k:
			kq = kq[:-1]
		kq = [i] + kq
print(len(kq))
for i in kq:
	print(i, end=' ')


(n, k) = map(int, input().split())
ID = list(map(int, input().split()))
con = []
for i in range(0, n):
	if not ID[i] in con:
		con = [ID[i]] + con
		if len(con) > k:
			con.pop(k)
l = len(con)
print(l)
ans = ' '.join(map(str, con))
print(ans)


import array
import collections
import math
import os
import sys

def main():
	(N, K) = read_ints()
	A = read_ints()
	ans = solve(N, K, A)
	print(len(ans))
	print(*ans)

def solve(N, K, A):
	q = collections.deque()
	d = dict()
	for a in A:
		if a in d:
			continue
		if len(q) == K:
			b = q.pop()
			d[b] -= 1
			if d[b] == 0:
				del d[b]
		q.appendleft(a)
		if a not in d:
			d[a] = 0
		d[a] += 1
	return q
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


(t, dc) = [*map(int, input().split())]
c = input().split()
display = []
for q in c:
	if q not in display:
		display.insert(0, q)
		if len(display) > dc:
			display.pop()
print(len(display))
print(' '.join(display))


import queue
v = input().split()
(n, k) = v
n = int(n)
k = int(k)
id = list(map(int, input().split()))
tela = queue.Queue(k)
settela = set()
cont = 0
for a in range(len(id)):
	i = id[a]
	cont += 1
	if cont == 1:
		tela.put(i)
		settela.add(i)
	elif i not in settela:
		if tela.full() == False:
			tela.put(i)
			settela.add(i)
		else:
			settela.remove(tela.get())
			tela.put(i)
			settela.add(i)
print(len(settela))
a = []
while not tela.empty():
	a.append(tela.get())
b = reversed(a)
for i in b:
	print(i, end=' ')


from collections import deque
(n, k) = input().split()
(n, k) = (int(n), int(k))
a = deque()
temp = [int(i) for i in input().split()]
for j in temp:
	if len(a) < k:
		if not j in a:
			a.appendleft(j)
	elif not j in a:
		a.pop()
		a.appendleft(j)
print(len(a))
print(' '.join([str(a) for a in a]))


(n, k) = [int(x) for x in input().split()]
ms = [int(x) for x in input().split()]
s = []
ons = set()
for m in ms:
	if m not in ons:
		s.append(m)
		ons.add(m)
		if len(ons) > k:
			ons.remove(s[-k - 1])
print(min(k, len(s)))
print(*reversed(s[-k:]))


(n, m) = map(int, input().split())
s = input().split()
sc = []
for j in range(n):
	if len(sc) < m and s[j] not in sc:
		sc.insert(0, s[j])
	elif s[j] not in sc:
		sc.pop()
		sc.insert(0, s[j])
print(len(sc))
print(*sc)


(n, k) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
B = list()
for i in A:
	if i not in B:
		B.insert(0, i)
	if len(B) > k:
		del B[-1]
print(len(B))
B = list(map(str, B))
print(' '.join(B))


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)
from collections import deque, Counter, OrderedDict, defaultdict
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd, log10, atan, tan

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
Arr = get_array()
Q = deque()
mydict = dict()
length = 0
i = 0
while length < k and i < n:
	if Arr[i] not in mydict:
		mydict[Arr[i]] = 1
		Q.appendleft(Arr[i])
		length += 1
	else:
		mydict[Arr[i]] += 1
	i += 1
for j in range(i, n):
	if Arr[j] in mydict:
		mydict[Arr[j]] += 1
	else:
		mydict[Arr[j]] = 1
		Q.appendleft(Arr[j])
		length += 1
		while length > k:
			element = Q.pop()
			del mydict[element]
			length -= 1
print(len(Q))
for i in Q:
	print(i, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
que = [arr[0]]
if n == 1 or k == 1:
	print('1')
	print(arr[-1])
else:
	for i in range(1, n):
		if len(que) >= k and arr[i] not in que:
			que.pop(0)
		if arr[i] not in que:
			que.append(arr[i])
	print(len(que))
	for i in range(len(que) - 1, -1, -1):
		print(que[i], end=' ')


from collections import deque
(n, k) = map(int, input().split())
arr = map(int, input().split())
convos = deque()
s = set()
for v in arr:
	if v in s:
		continue
	if len(s) == k:
		s.remove(convos.pop())
	convos.appendleft(v)
	s.add(v)
print(len(convos))
print(' '.join(map(str, list(convos))))


(n, k) = map(int, input().split())
msgs = input().split()
screen_msg = []
for msg in msgs:
	if msg in screen_msg:
		continue
	screen_msg.insert(0, msg)
	if len(screen_msg) > k:
		screen_msg.pop()
print(len(screen_msg))
print(' '.join(screen_msg))


(n, k) = map(int, input().split())
ii = list(map(int, input().split()))
arr = []
for i in range(n):
	if arr.count(ii[i]) == 0:
		arr.insert(0, ii[i])
		if len(arr) > k:
			del arr[-1]
print(len(arr))
for i in range(len(arr)):
	print(arr[i], end=' ')


(N, K) = input().split()
N = int(N)
K = int(K)
A = list(map(int, input().split()))
L = []
for i in range(N):
	if A[i] not in L and len(L) < K:
		L.insert(0, A[i])
	if A[i] not in L and len(L) == K:
		L.pop()
		L.insert(0, A[i])
print(len(L))
print(*L)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
p = min(n, k, len(set(arr)))
arr1 = [-1 for i in range(p)]
for i in arr:
	if i not in arr1:
		arr1.insert(0, i)
		arr1.pop(-1)
print(p)
print(*arr1)


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
screen = []
cur = 0
for i in ids:
	if not i in screen:
		if cur < k:
			screen.insert(0, i)
			cur = cur + 1
		elif cur >= k:
			screen.insert(0, i)
			screen.pop()
			cur = cur + 1
print(len(screen))
print(' '.join(map(str, screen)))


def swap_pos(a, l, r):
	get = (a[l], a[r])
	(a[l], a[r]) = get
	return a
inp_string_0 = input()
inp_0 = inp_string_0.split()
n = int(inp_0[0])
k = int(inp_0[1])
inp_string = input()
inp = inp_string.split()
a = []
for i in inp:
	ele = int(i)
	a.append(ele)
ans_lst = []
for i in range(len(a)):
	if len(ans_lst) < k:
		if a[i] not in ans_lst:
			ans_lst.append(a[i])
		else:
			a = swap_pos(a, i, len(ans_lst) - 1)
	elif a[i] in ans_lst:
		a = swap_pos(a, i, k - 1)
	else:
		ans_lst = ans_lst[1:]
		ans_lst.append(a[i])
print(len(ans_lst))
ans_lst = ans_lst[::-1]
for i in range(len(ans_lst)):
	print(ans_lst[i], end=' ')


def SocialNetwork():
	(amOfQuerries, convLimit) = map(int, input().split())
	ids = input().split()
	messagesShown = []
	Display = set()
	for index in range(len(ids)):
		if ids[index] not in Display:
			messagesShown.append(ids[index])
			Display.add(ids[index])
			if len(Display) > convLimit:
				Display.remove(messagesShown[-convLimit - 1])
	answer = str(len(Display)) + '\n' + ' '.join(messagesShown[-1:-convLimit - 1:-1])
	print(answer)
SocialNetwork()


(lenn, k) = list(map(int, input().split()))
li = list(map(int, input().split()))
answer = 0
output = []
for i in li:
	if not i in output:
		if k == len(output):
			del output[-1]
			output.insert(0, i)
		else:
			answer += 1
			output.insert(0, i)
print(answer)
print(*output)


(n, k) = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
l1 = []
s = set()
c = 0
for i in l:
	if i not in s:
		s.add(i)
		l1.append(i)
		if len(s) > k:
			s -= {l1[c]}
			c += 1
print(len(l1) - c)
print(*reversed(l1[c:]))


(n, k) = map(int, input().split())
arr = [int(k) for k in input().split()]
lis = []
dic = {}
for i in range(n):
	if arr[i] not in dic or dic[arr[i]] == 0:
		dic[arr[i]] = 1
		lis.insert(0, arr[i])
		if len(lis) > k:
			dic[lis[k]] = 0
			lis.pop(k)
if len(lis) < min(n, k):
	print(len(lis))
	print(*lis)
else:
	print(min(n, k))
	print(*lis)


(n, k) = map(int, input().split())
ide = input().split()
for i in range(n):
	ide[i] = int(ide[i])
a = []
for i in range(n):
	if ide[i] in a:
		continue
	elif len(a) < k:
		a.append(ide[i])
	else:
		a.pop(0)
		a.append(ide[i])
print(len(a))
for i in range(len(a)):
	print(a[len(a) - 1 - i], end=' ')
print()


(n, k) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
scr = []
for msg in l:
	if msg not in scr:
		if len(scr) < k:
			scr = [msg] + scr
		else:
			scr = [msg] + scr[:len(scr) - 1]
print(len(scr))
print(*scr)


(message, chat) = map(int, input().split())
id = list(map(int, input().split()))
current = []
for elem in id:
	if elem in current:
		continue
	if len(current) < chat:
		current.append(elem)
	else:
		current.pop(0)
		current.append(elem)
print(len(current))
print(*current[::-1])


from sys import stdin, stdout
for _ in range(1):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	l = []
	for i in range(n):
		if a[i] in l:
			continue
		l += [a[i]]
		if len(l) > k:
			l.pop(0)
	print(len(l))
	print(*l[::-1])


[N, K] = list(map(int, input().split()))
ids = set()
vals = []
IDS = list(map(int, input().split()))
for id_ in IDS:
	if not id_ in ids:
		vals.append(id_)
		ids.add(id_)
		if len(vals) > K:
			ids.remove(vals[0])
			vals = vals[1:]
print(len(vals))
print(' '.join([str(x) for x in vals[::-1]]))


(n, k) = map(int, input().split())
ids_cur = {}
ids = list(map(int, input().split()))
l = 0
i1 = 0
idi = 0
while i1 < n:
	if ids[i1] not in ids_cur:
		ids_cur[ids[i1]] = idi
		idi += 1
		l += 1
		if l == k:
			break
	i1 += 1
ids_cur2 = {val: key for (key, val) in ids_cur.items()}
for i in range(i1 + 1, n):
	if ids[i] not in ids_cur:
		del ids_cur[ids_cur2[idi - k]]
		ids_cur[ids[i]] = idi
		del ids_cur2[idi - k]
		ids_cur2[idi] = ids[i]
		idi += 1
print(len(ids_cur))
print(*[el[1] for el in sorted(ids_cur2.items(), reverse=True)])


import math
import sys
from collections import defaultdict, Counter, deque
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate
dp = []
(n, K) = ilele()
B = alele()
mark = {}
i = 0
x = len(B)
Q = deque()
for i in range(len(B)):
	if mark.get(B[i], -1) == -1:
		Q.appendleft(B[i])
		mark[B[i]] = 1
		if len(Q) > K:
			x = Q.pop()
			mark[x] = -1
print(len(Q))
print(*Q)


from collections import deque
(n, k) = map(int, input().split())
q = deque(maxlen=k)
c = list(map(int, input().split()))
for i in c:
	if i not in q:
		q.append(i)
	else:
		continue
print(len(q))
print(*list(q)[::-1])


(n, k) = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
result = list()
for j in range(len(lst)):
	if len(result) >= k and lst[j] not in result:
		result.pop()
	if lst[j] in result:
		continue
	else:
		result.insert(0, lst[j])
print(len(result))
print(*result)


def add(A, a, k):
	if len(A) == 0:
		A.append(a)
		return A
	if len(A) < k:
		if a in A:
			return A
		ln = len(A)
		A.append(a)
		for i in range(ln):
			v = A.pop(0)
			A.append(v)
		return A
	else:
		if a in A:
			return A
		A.pop(len(A) - 1)
		ln = len(A)
		A.append(a)
		for i in range(ln):
			v = A.pop(0)
			A.append(v)
		return A
(n, k) = input().split(' ')
(n, k) = (int(n), int(k))
ID = input().split(' ')
ID = [int(ID[i]) for i in range(n)]
A = []
for i in range(n):
	add(A, ID[i], k)
m = len(set(ID))
print(min(m, k))
w = ''
for i in range(len(A)):
	if i == len(A) - 1:
		w += str(A[i])
		continue
	w += str(A[i])
	w += ' '
print(w)


(n, k) = map(int, input().split())
l = []
m = list(map(int, input().split()))
for i in range(n):
	flag = 0
	for j in range(len(l)):
		if l[j] == m[i]:
			flag = 1
	if flag == 0:
		if len(l) == k:
			del l[0]
			l.append(m[i])
		else:
			l.append(m[i])
l1 = l[::-1]
print(len(l))
for x in l1:
	print(x, end=' ')


ilist = lambda : list(map(int, input().split()))
(n, k) = ilist()
messages = ilist()
checker = {}
current_nb_conversations = 0
for (i, message) in enumerate(messages):
	if current_nb_conversations == k and message not in checker:
		current_nb_conversations -= 1
		a = min(checker, key=checker.get)
		del checker[a]
	if message not in checker:
		checker[message] = i
		current_nb_conversations += 1
nb_conversations = min(len(set(messages)), k)
print(nb_conversations)
l = list(map(str, sorted(checker, key=checker.get)))
l.reverse()
print(' '.join(l))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in a:
	if i not in b:
		b = [i] + b
		b = b[:k]
print(len(b))
print(*b)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sc = []
on_screen = set()
i = 0
c = 0
while c < k:
	if a[i] not in on_screen:
		sc.append(a[i])
		on_screen.add(a[i])
		c += 1
	i += 1
	if i == n:
		break
sc.reverse()
for j in range(i, n):
	if a[j] not in on_screen:
		on_screen.remove(sc.pop())
		on_screen.add(a[j])
		sc.insert(0, a[j])
print(len(sc))
print(*sc)


from collections import deque

class ConstantQ:

	def __init__(self, kk):
		self.k = kk
		self.q = deque()
		self.presence = set()

	def add(self, idi):
		if idi not in self.presence:
			if len(self.q) >= self.k:
				self.presence.remove(self.q.pop())
			self.q.appendleft(idi)
			self.presence.add(idi)
		else:
			pass

	def printQ(self):
		print(len(self.q))
		print(*self.q)

def convo(n, k, ids):
	q = ConstantQ(k)
	for idi in ids:
		q.add(idi)
	q.printQ()

def io():
	(n, k) = map(int, input().split())
	ids = list(map(int, input().split()))
	convo(n, k, ids)
io()


from collections import deque
(n, k) = [x for x in map(int, input().split())]
A = [x for x in map(int, input().split())]
d = deque()
res = set()
for i in A:
	if i in res:
		continue
	res.add(i)
	d.appendleft(i)
	if len(d) > k:
		res.discard(d.pop())
print(len(d))
print(*d)


import math

def SocialNetwork(l, m, c):
	outputs = []
	buffer = []
	pointer = 0
	history = []
	for i in l:
		if str(i) in buffer:
			continue
		elif len(buffer) < c:
			buffer.insert(0, str(i))
			history.append(str(i))
		else:
			outputs.append(buffer.copy())
			history.append(str(i))
			del buffer[buffer.index(history[0])]
			del history[0]
			buffer.insert(0, str(i))
	print(len(buffer))
	print(' '.join(buffer) + ' ')
(m, c) = map(int, input().rstrip().split())
l = list(map(int, input().rstrip().split()))
SocialNetwork(l, m, c)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def int1():
	return int(input())
import math
from itertools import combinations

def main():
	(n, k) = get_array()
	a = get_array()
	l = []
	for i in a:
		if i not in l and len(l) < k:
			l.insert(0, i)
		elif i in l:
			continue
		elif len(l) >= k:
			l.pop()
			l.insert(0, i)
	print(len(l))
	print(*l)
main()


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
l = []
for i in m:
	if i not in l:
		if len(l) == k:
			l.pop(-1)
		l.insert(0, i)
print(len(l))
for i in l:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = [*map(int, input().split())]
from collections import deque
ans = deque()
ins = set()
for i in a:
	if i not in ins:
		if len(ans) == k:
			ins.remove(ans[0])
			ans.popleft()
		ans.append(i)
		ins.add(i)
ans.reverse()
print(len(ans))
print(*ans)


import queue
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
b = {}
mes = queue.Queue(maxsize=k)
mes.put(l[0])
b[l[0]] = 1
j = 1
for i in range(1, n):
	if b.get(l[i], 0) == 0:
		if j < k:
			mes.put(l[i])
			j += 1
			b[l[i]] = 1
		else:
			var = mes.get()
			mes.put(l[i])
			b[l[i]] = 1
			b[var] = 0
print(mes.qsize())
length = mes.qsize()
for i in range(length - 1, -1, -1):
	print(mes.queue[i], end=' ')


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
cur = []
for i in ids:
	if i not in cur:
		if len(cur) < k:
			cur = [i] + cur
		else:
			cur = [i] + cur[:len(cur) - 1]
print(len(cur))
print(*cur)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
mess = []
for i in l:
	if i not in mess:
		if len(mess) == k:
			mess.pop(0)
		mess.append(i)
mess.reverse()
print(len(mess))
for ele in mess:
	print(ele, end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
screen = [-1] * 700000
i = 233000
y = {}
for idd in l:
	y[idd] = -1
for j in range(n):
	if y[l[j]] == 1:
		continue
	else:
		screen[i] = l[j]
		y[l[j]] = 1
		if screen[i + k] > -1:
			y[screen[i + k]] = -1
		i -= 1
wyn = 0
odp = []
for j in range(i + 1, i + k + 1):
	if screen[j] > -1:
		wyn += 1
		odp.append(screen[j])
print(wyn)
print(*odp)


(n, m) = input().split()
c = list(map(int, input().split()))
r = []
k = []
sum = 0
t = 0
for i in range(0, len(c)):
	if c[i] not in r:
		sum = sum + 1
		r.append(c[i])
l = min(int(n), int(m), sum)
print(l)
p = 0
while len(k) != l:
	if c[0] not in k:
		k.insert(0, c[0])
		c.pop(p)
	else:
		c.pop(0)
for e in range(0, len(c)):
	if c[e] not in k:
		k.pop()
		k.insert(0, c[e])
for h in k:
	print(h, end=' ')


(n, k) = input().split()
(n, k) = (int(n), int(k))
arr = list(map(int, input().split()))
list1 = []
for val in arr:
	if val not in list1:
		if len(list1) < k:
			list1.insert(0, val)
		else:
			list1.pop()
			list1.insert(0, val)
print(min(len(list1), k))
print(*list1)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
li = []
a = input().split(' ')
for i in a:
	if i in li:
		pass
	else:
		li.append(i)
		if len(li) > k:
			li = li[1:]
print(len(li))
li.reverse()
for a in li:
	print(a, end=' ')


s = input()
s = s.split(' ')
n = s[0]
m = s[1]
s = input().split(' ')
s = list(map(int, s))
msg = []
for i in range(int(n)):
	if not s[i] in msg:
		if len(msg) >= int(m):
			del msg[0]
		msg.append(s[i])
print(len(msg))
msg.reverse()
for i in range(len(msg)):
	print(msg[i], end=' ')
print()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
t = []
le = 0
for i in l:
	if i in t:
		continue
	elif le < k:
		t.insert(0, i)
		le += 1
	else:
		t.pop()
		t.insert(0, i)
print(le)
print(*t)


s = []
(n, k) = map(int, input().split())
li = list(map(int, input().split()))
cnt = 0
for i in li:
	if i in s:
		continue
	if cnt < k:
		s.append(i)
		cnt += 1
	else:
		s.append(i)
		s.pop(0)
print(len(s))
print(*s[::-1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = [0] * k
for i in a:
	if i in l:
		continue
	if i not in l and 0 in l:
		l.remove(0)
		l = [i] + l
	if i not in l and 0 not in l:
		l = [i] + l
		l = l[:k]
while 0 in l:
	l.remove(0)
print(len(l))
print(*l)


from queue import Queue
(n, k) = map(int, input().split())
msgs = list(map(int, input().split()))
scr = Queue()
scr_set = set()
for m in msgs:
	if m in scr_set:
		pass
	else:
		if scr.qsize() == k:
			scr_set.remove(scr.get())
		scr.put(m)
		scr_set.add(m)
print(scr.qsize())
nscr = []
while scr.qsize() > 0:
	nscr.append(scr.get())
nscr.reverse()
print(*nscr)


from collections import deque
(n, m) = map(int, input().split())
sms = list(map(int, input().split()))
p = deque()
s = set()
for e in range(len(sms)):
	if sms[e] not in s:
		p.appendleft(sms[e])
		s.add(sms[e])
	if len(p) > m:
		s.remove(p.pop())
print(len(p))
print(*p)


(n, k) = list(map(int, input().split()))
queue = [0] * k
last = k - 1
ip = list(map(int, input().split()))
for elem in ip:
	if elem not in queue:
		queue[last] = elem
		last = (last + 1) % k
last -= 1
if last < 0:
	last = k - 1
elem = queue[last]
queue = [i for i in queue if i != 0]
k = len(queue)
last = queue.index(elem)
print(k)
for _ in range(k):
	if queue[last] != 0:
		print(queue[last], end=' ')
	last -= 1
	if last < 0:
		last = k - 1


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
q = {}
w = []
r = 0
for i in set(l):
	q[i] = 0
for i in range(n):
	if q[l[i]] == 0:
		q[l[i]] = 1
		w.append(l[i])
		r += 1
		if r > k:
			q[w[-k - 1]] = 0
e = w[-1:-k - 1:-1]
print(len(e))
print(' '.join(map(str, e)))


(n, m) = map(int, input().split())
data = list(map(int, input().split()))
array = []
c = 0
for i in data:
	if i not in array:
		c += 1
		if c > m:
			array = [i] + array[:-1]
		else:
			array = [i] + array
print(m if c >= m else c)
print(*array)


(n, k) = map(int, input().split())
listn = list(map(int, input().split()))
q = []
for i in range(len(listn)):
	if listn[i] not in q:
		q.append(listn[i])
		if len(q) > k:
			q.pop(0)
print(len(q))
q.reverse()
for i in q:
	print(i, end=' ')


(n1, k1) = map(int, input().split())
l = list(map(int, input().split()))
l1 = []
for i in l:
	if i in l1:
		continue
	if len(l1) <= k1 - 1:
		l1.insert(0, i)
	else:
		l1.pop()
		l1.insert(0, i)
print(len(l1))
for i in l1:
	print(i, end=' ')


(n, k) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
x = [0] * k
count = 0
for i in l:
	if i not in x:
		x.insert(0, i)
		x.pop()
print(len(x) - x.count(0))
for i in x:
	if i != 0:
		print(i, end=' ')


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cur_friends = set()
queue = deque()
for i in a:
	if len(queue) < k and i not in cur_friends:
		queue.append(i)
		cur_friends.add(i)
	elif i not in cur_friends:
		cur_friends.remove(queue.popleft())
		cur_friends.add(i)
		queue.append(i)
queue.reverse()
print(len(queue))
print(' '.join(list(map(str, queue))))


import sys
(n, k) = map(int, sys.stdin.readline().split())
ar = []
suma = 0
id = list(map(int, input().split()))
for i in range(n):
	if len(ar) < k and id[i] not in ar:
		ar.append(id[i])
	elif len(ar) == k and id[i] not in ar:
		ar.remove(ar[0])
		ar.append(id[i])
print(len(ar))
for i in range(-1, -len(ar) - 1, -1):
	print(ar[i], end=' ')


from collections import deque
q = deque()
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
	if len(q) < k and a[i] not in q:
		q.append(a[i])
	if a[i] in q:
		continue
	if len(q) == k and a[i] not in q:
		q.popleft()
		q.append(a[i])
print(len(q))
for i in range(len(q)):
	print(q.pop(), end=' ')


from collections import deque
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
now = set()
letters = deque()
for i in range(n):
	if a[i] not in now:
		now.add(a[i])
		if len(letters) < k:
			letters.append(a[i])
		else:
			now.remove(letters.popleft())
			letters.append(a[i])
print(len(letters))
print(*list(letters)[::-1])


from collections import deque
(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
screen = deque(maxlen=k)
for item in ids:
	if item not in screen:
		screen.append(item)
print(len(screen))
print(*list(screen)[::-1])


(n, k) = map(int, input().split())
a = [''] * n
s = []
a[0:n] = map(str, input().split())
for i in range(n):
	q = 0
	for o in range(len(s)):
		if a[i] == s[o]:
			q = 1
	if len(s) < k and q == 0:
		s.append(0)
		s[1:len(s)] = s[0:len(s) - 1]
		s[0] = a[i]
	elif q == 0:
		s[1:len(s)] = s[0:len(s) - 1]
		s[0] = a[i]
print(len(s))
for i in range(len(s)):
	print(s[i], end=' ')


list1 = input().split(' ')
n = int(list1[0])
k = int(list1[1])
list2 = input().split(' ')
x = len(set(list2))
print(min(k, x))
mlist = ['s'] * k
if k == 1:
	mlist[0] = list2[n - 1]
else:
	for i in range(0, n):
		c = mlist.count('s')
		if (list2[i] in mlist) == False:
			if c != 0:
				mlist[c - 1] = list2[i]
			else:
				for j in range(1, k):
					mlist[k - j] = mlist[k - j - 1]
				mlist[0] = list2[i]
while ('s' in mlist) == True:
	mlist.remove('s')
for i in mlist:
	print(i, end=' ')


(n, k) = map(int, input().split())
id = [int(val) for val in input().split()]
ans = []
for i in id:
	if i in ans:
		continue
	if len(ans) == k:
		ans.remove(ans[0])
	ans.append(i)
print(len(ans))
for i in reversed(ans):
	print(i, end=' ')


(n, k) = map(int, input().split())
a = []
for i in map(int, input().split()):
	if i in a:
		continue
	elif len(a) < k:
		a.append(i)
		continue
	else:
		del a[0]
		a.append(i)
print(len(a))
print(*a[::-1])


import sys
from math import cos, pi, ceil, pi, tan, floor, gcd, sqrt, log2, factorial, log10
from collections import Counter
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase
from statistics import mean, median, mode
alpha = ascii_lowercase
beta = ascii_uppercase

def nextPowerOf2(n):
	p = 1
	if n and (not n & n - 1):
		return n
	while p < n:
		p <<= 1
	return p

def get_Divisors(n):
	arr = []
	i = 1
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				arr.append(i)
			else:
				arr.append(i)
				arr.append(n // i)
		i = i + 1
	return arr

def isprime(n):
	if n == 1:
		return 0
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 0
		i += 1
	return 1

def Sieve(n):
	prime = [True for i in range(n + 1)]
	prime[0] = False
	prime[1] = False
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def create_matrix(n, m):
	mat = [[] for i in range(n)]
	for i in range(n):
		for j in range(m):
			mat[i].append(0)
	return mat

def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	res = []
	for i in arr:
		if i not in res and len(res) < k:
			res.append(i)
		elif i not in res and len(res) == k:
			res.pop(0)
			res.append(i)
	print(len(res))
	print(*res[::-1])
main()


from collections import deque
(n, k) = tuple(map(int, input().split()))
ids = list(map(int, input().split()))
S = set()
Q = deque()
for id in ids:
	if not id in S:
		S.add(id)
		Q.appendleft(id)
		if len(Q) > k:
			S.remove(Q.pop())
print(len(Q))
print(' '.join([str(q) for q in Q]))


(n, k) = [int(i) for i in input().strip().split()]
i_d = [int(i) for i in input().strip().split()]
res = []
for i in range(n):
	if len(res) <= k:
		if i_d[i] not in res:
			if len(res) == k:
				res.remove(res[k - 1])
			res = [i_d[i]] + res
		else:
			continue
print(len(res), end='\n')
print(*res)


inp = list(map(int, input().split()))
n = inp[0]
k = inp[1]
inp = list(map(int, input().split()))
ids = inp
final = []
for i in range(n):
	if ids[i] not in final:
		final.insert(0, ids[i])
		if len(final) > k:
			final.pop()
m = len(final)
print(m)
print(*final, sep=' ')


(n, k) = [int(x) for x in input().split()]
l = list([int(x) for x in input().split()])
conv = []
for i in range(n):
	if l[i] not in conv:
		if len(conv) < k:
			conv.append(l[i])
		else:
			conv.append(l[i])
			conv.pop(0)
conv.reverse()
print(len(conv))
for i in conv:
	print(i, end=' ')


(n, k) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
di = []
count = {}
temp = 0
for i in range(n):
	if temp == k:
		break
	if A[i] not in count:
		count[A[i]] = 1
		di.append(A[i])
		temp += 1
for j in range(i, n):
	if A[j] not in count:
		del count[di[-k]]
		count[A[j]] = 1
		di.append(A[j])
print(len(count))
count = 1
j = len(di) - 1
while count <= k and j >= 0:
	print(di[j], end=' ')
	count += 1
	j -= 1


(n, r) = input().split()
n = int(n)
r = int(r)
lst = list(map(int, input().split()))
con = []
for i in lst:
	if i in con:
		continue
	con.insert(0, i)
	if len(con) > r:
		del con[-1]
print(min(r, len(con)))
for i in con:
	print(i, end=' ')


g = list(map(int, input().split()))
l = list(map(int, input().split()))
n = g[0]
k = g[1]
h = []
for i in range(n):
	if l[i] not in h:
		if len(h) == k:
			h.pop()
			h.insert(0, l[i])
		else:
			h.insert(0, l[i])
print(len(h))
for i in range(len(h)):
	print(h[i], end=' ')


from collections import defaultdict as dfd
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
mp = dfd(int)
indices = dfd(int)
size = 0
least_val = 1
for i in range(n):
	if size < k:
		if mp[arr[i]] == 0:
			size += 1
			mp[arr[i]] = size
			indices[size] = arr[i]
	if size >= k and mp[arr[i]] == 0:
		element_to_remove = indices[least_val]
		mp[element_to_remove] = 0
		least_val += 1
		size += 1
		mp[arr[i]] = size
		indices[size] = arr[i]
arr = []
for (i, j) in mp.items():
	if j > 0:
		arr.append((j, i))
arr.sort(reverse=True)
ans = []
for _ in range(len(arr)):
	ans.append(arr[_][1])
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
screen = []
for i in range(n):
	if arr[i] not in screen:
		if len(screen) == k:
			screen.remove(screen[-1])
			screen.insert(0, arr[i])
		else:
			screen.insert(0, arr[i])
print(len(screen))
print(*screen)


from collections import deque

def solve(n, k, arr):
	count = 0
	screen = deque([])
	dict = {}
	for i in arr:
		if dict.get(i, 0) == 0:
			if count == k:
				dict[screen.pop()] = 0
				count -= 1
			screen.appendleft(i)
			dict[i] = 1
			count += 1
	return str(len(screen)) + '\n' + ' '.join((str(x) for x in list(screen)))
output = ''
(n, k) = map(int, input().split(' '))
arr = [int(x) for x in input().split(' ')]
output += solve(n, k, arr)
print(output)


from queue import Queue
from collections import defaultdict
(m, k) = map(int, input().split())
Messages = [int(x) for x in input().split()]
q = Queue(maxsize=k)
Dict = defaultdict(bool)
for i in range(m):
	if q.full():
		if Dict[Messages[i]] == False:
			Dict[q.get()] = False
			q.put(Messages[i])
			Dict[Messages[i]] = True
	elif Dict[Messages[i]] == False:
		q.put(Messages[i])
		Dict[Messages[i]] = True
print(q.qsize())
List = []
for i in range(q.qsize()):
	List.append(q.get())
print(*List[::-1])


(n, k) = map(int, input().split())
f = tuple(map(int, input().split()))
b = []
for i in range(n):
	if f[i] not in b:
		b.insert(0, f[i])
		if len(b) > k:
			b = b[:len(b) - 1]
print(len(b))
print(*b)


from collections import deque
(n, k) = [int(elem) for elem in input().split()]
id = [int(elem) for elem in input().split()]
qu = deque([], k)
for elem in id:
	if elem not in qu:
		qu.append(elem)
print(len(qu))
print(*list(qu)[::-1], sep=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
l = []
for i in a:
	if i not in d:
		d[i] = 1
		if len(l) < k:
			l.append(i)
		else:
			z = l.pop(0)
			del d[z]
			l.append(i)
print(len(l))
print(*l[::-1])


(n, k) = (int(x) for x in input().split())
msgs = [int(x) for x in input().split()]
convs = []
for i in range(n):
	if msgs[i] not in convs:
		if len(convs) < k:
			convs.insert(0, msgs[i])
		else:
			del convs[k - 1]
			convs.insert(0, msgs[i])
l = len(convs)
print(l)
for i in range(l):
	if i != l - 1:
		print(convs[i], end=' ')
	else:
		print(convs[i])


class Node:

	def __init__(self, val):
		self.next = None
		self.id = val

def process(A, k):
	n = len(A)
	p1 = Node(A[0])
	p2 = None
	my_set = set([A[0]])
	curr = 1
	for i in range(1, n):
		if A[i] not in my_set:
			new_node = Node(A[i])
			my_set.add(A[i])
			if p2 is None:
				p2 = new_node
				p1.next = p2
			else:
				p2.next = new_node
				p2 = p2.next
			if curr < k:
				curr += 1
			else:
				v1 = p1.id
				my_set.remove(v1)
				p1 = p1.next
	answer = []
	while p1 != None:
		answer.append(p1.id)
		p1 = p1.next
	return answer[::-1]
(n, k) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
answer = process(A, k)
print(len(answer))
print(' '.join(map(str, answer)))


from collections import deque
import sys
str = input()
words = str.split()
n = int(words[0])
k = int(words[1])
d = deque(maxlen=k)
s = set()
str = input()
words = str.split()
for i in range(n):
	x = words[i]
	if x in s:
		continue
	else:
		if len(d) >= k:
			y = d.popleft()
			s.remove(y)
		d.append(x)
		s.add(x)
print(len(d))
while len(d) > 0:
	print(d.pop() + ' ', end='')


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
(n, k) = f()
l = il()
y = 0
x = 0
dq = deque()
s = set()
for i in l:
	if not i in s:
		if len(dq) == k:
			s.discard(dq[-1])
			dq.pop()
		dq.appendleft(i)
		s.add(i)
print(len(dq))
for i in dq:
	print(i, end=' ')


def compute(arr, n, k):
	queue = []
	dic = set()
	for i in arr:
		if len(queue) < k:
			if not i in dic:
				queue.insert(0, i)
				dic.add(i)
		elif not i in dic:
			temp = queue.pop()
			dic.remove(temp)
			queue.insert(0, i)
			dic.add(i)
	print(len(queue))
	return queue
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
print(*compute(arr, n, k))


(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
l = []
c = 0
for i in d:
	if i in l:
		continue
	if len(l) == k:
		l.pop()
	l.insert(0, i)
	c += 1
print(len(l))
print(*l)


n = [int(x) for x in input().split()]
maxSize = n[1]
lst = list()
s = set()
numbers = [int(x) for x in input().split()]
for num in numbers:
	n1 = len(s)
	s.add(num)
	n2 = len(s)
	if n1 == n2:
		continue
	elif len(lst) < maxSize:
		lst.insert(0, num)
	else:
		s.remove(lst[-1])
		del lst[-1]
		lst.insert(0, num)
print(len(lst))
for num in lst:
	print(num, end=' ')


data = [int(i) for i in input().split()]
N = data[0]
K = data[1]
data = [int(i) for i in input().split()]
queue = []
for i in range(N):
	if data[i] in queue:
		continue
	else:
		queue.append(data[i])
		if len(queue) == K + 1:
			queue.pop(0)
print(len(queue))
for i in range(len(queue)):
	print(queue[-i - 1], end=' ')


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = []
for i in a:
	if i not in b:
		if len(b) >= k:
			b.pop()
		b.insert(0, i)
print(len(b))
for j in b:
	print(j, end=' ')


cons = list(map(int, input().split()))
n = cons[0]
k = cons[1]
a = list(map(int, input().split()))
dic = {}
result = [0] * k
index = 0
for i in range(n):
	if dic.get(a[i]) is not None:
		continue
	old_val = result[index]
	dic[old_val] = None
	result[index] = a[i]
	dic[a[i]] = True
	index += 1
	if index == k:
		index = 0
res = []
for x in range(index - 1, -1, -1):
	if result[x] != 0:
		res.append(result[x])
for x in range(k - 1, index - 1, -1):
	if result[x] != 0:
		res.append(result[x])
print(len(res))
print(' '.join(map(str, res)))


(n, k) = input().split()
n = int(n)
k = int(k)
l = []
m = []
f = 0
a = list(map(int, input().strip().split()))[:n]
for i in a:
	if m.count(i) == 0:
		m.append(i)
s = len(m)
j = min(n, k)
if s <= j:
	print(s)
	for i in a:
		for x in range(s):
			l.append('0')
	for i in a:
		for x in range(s):
			if l[x] != i:
				f = 1
			else:
				f = 0
				break
		if f == 1:
			l.insert(0, i)
	for r in range(s):
		print(l[r], end=' ')
else:
	print(j)
	for i in a:
		for x in range(j):
			l.append('0')
	for i in a:
		for x in range(j):
			if l[x] != i:
				f = 1
			else:
				f = 0
				break
		if f == 1:
			l.insert(0, i)
	for r in range(j):
		print(l[r], end=' ')


from collections import deque
for i in range(1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	q = deque()
	w = {}
	c = 0
	for j in range(len(a)):
		w[a[j] - 1] = 0
	for j in range(len(a)):
		if w[a[j] - 1] == 0:
			q.append(a[j])
			c = c + 1
			w[a[j] - 1] = 1
		if c > k:
			qw = q.popleft()
			w[qw - 1] = 0
			c = c - 1
	print(len(q))
	q.reverse()
	print(*q)


from collections import deque
(n, k) = map(int, input().split())
l = map(int, input().split())
ln = deque()
s = set()
for val in l:
	if val in s:
		continue
	if len(ln) == k:
		s.remove(ln.pop())
	ln.appendleft(val)
	s.add(val)
print(len(ln))
print(' '.join(map(str, list(ln))))


from collections import deque
from sys import stdin

def main():
	(N, K) = map(int, input().split())
	ID = map(int, input().split())
	id = deque([], K)
	for i in ID:
		if i not in id:
			id.appendleft(i)
	print(len(id))
	print(*id)

def input():
	return stdin.readline()[:-1]
main()


from collections import OrderedDict

class LRUCache:

	def __init__(self, capacity):
		self.capacity = capacity
		self.cache = OrderedDict()

	def set(self, key, value):
		if len(self.cache) == self.capacity:
			self.cache.popitem(last=False)
		self.cache[key] = value
(n, k) = map(int, input().strip().split())
ids = map(int, input().strip().split())
convs = LRUCache(k)
for i in ids:
	if i in convs.cache:
		continue
	else:
		convs.set(i, None)
print(len(convs.cache))
print(' '.join(map(str, reversed(convs.cache.keys()))))


from collections import deque
d = deque()
s = set()
(n, k) = map(int, input().split())
all = [int(i) for i in input().split()]
for i in all:
	if i not in d:
		d.appendleft(i)
	if len(d) > k:
		d.pop()
print(len(d))
print(*d)


import queue
(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
m = []
st = set()
L = queue.Queue(maxsize=s)
for i in range(n):
	if L.full() != True and arr[i] not in st:
		st.add(arr[i])
		L.put(arr[i])
	elif L.full() == True and arr[i] not in st:
		x = L.get()
		st.remove(x)
		L.put(arr[i])
		st.add(arr[i])
while L.empty() == False:
	x = L.get()
	m.append(x)
print(len(m))
print(*m[::-1])


(n, k) = map(int, input().split())
id = map(int, input().split())
ekran = []
for i in id:
	if not ekran:
		ekran.append(i)
		continue
	if i in ekran:
		continue
	if len(ekran) == k:
		ekran.pop(-1)
	ekran.insert(0, i)
print(len(ekran))
print(' '.join([str(_) for _ in ekran]))


from bisect import bisect_right as br
import sys
from collections import *
from math import *
import re

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	c = 0
	for i in range(2, n):
		if prime[i]:
			c += 1
	return c

def iseven(n):
	return [False, True][0 if n % 2 else 1]

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

def inp():
	return map(int, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
max_int = sys.maxsize
mod = 10 ** 9 + 7
(n, k) = inp()
arr = inp_arr()
res = []
for i in arr:
	if i not in res:
		if len(res) < k:
			res.insert(0, i)
		else:
			res.pop()
			res.insert(0, i)
print(len(res))
print(*res)


from queue import Queue
(n, k) = map(int, input().split())
cnt = 0
a = Queue()
b = {}
h = list(map(int, input().split()))
for i in range(n):
	n1 = h[i]
	if n1 not in b:
		b[n1] = 0
	if not b[n1]:
		if not a.empty() and cnt > k - 1:
			b[a.get()] = 0
			cnt -= 1
		a.put(n1)
		b[n1] = 1
		cnt += 1
print(cnt)
b = []
while cnt > 0:
	b.append(a.get())
	cnt -= 1
print(*reversed(b))


from sys import stdin, stdout
from os import path
rd = lambda : stdin.readline().strip()
wr = stdout.write
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
import math
(n, k) = map(int, rd().split())
mylist = list(map(int, rd().split()))
queue = []
amr = dict()
for item in mylist:
	if item not in amr:
		amr[item] = 1
		if len(queue) == k:
			del amr[queue[-1]]
			queue.pop()
			queue.insert(0, item)
		else:
			queue.insert(0, item)
print(len(queue))
print(*queue)


from collections import deque
(n, k) = map(int, input().split(' '))
lis = [int(k) for k in input().split(' ')]
tot = deque([])
sto = set()
ltot = 0
for i in range(n):
	next = lis[i]
	if next in sto:
		continue
	elif ltot < k:
		tot.appendleft(next)
		sto.add(next)
		ltot += 1
	else:
		tot.appendleft(next)
		last = tot.pop()
		sto.remove(last)
		sto.add(next)
print(ltot)
print(' '.join((str(k) for k in tot)))


(am, space) = input().split(' ')
(am, space) = (int(am), int(space))
arr = list(map(int, input().split(' ')))
screen = []
for i in range(len(arr)):
	if not arr[i] in screen:
		if len(screen) == space:
			screen = screen[:space - 1]
		screen = [arr[i]] + screen
print(len(screen))
print(' '.join(map(str, screen)))


ar = []
for x in input().split(' '):
	ar.append(int(x))
n = ar[0]
k = ar[1]
ar2 = []
for x in input().split(' '):
	ar2.append(int(x))
curr = []
s = set()
for x in ar2:
	if x in s:
		continue
	if len(curr) == k:
		curr.append(x)
		s.add(x)
		s.discard(curr[0])
		curr.pop(0)
	else:
		curr.append(x)
		s.add(x)
print(len(curr))
print(*reversed(curr))


lst = []
(n, k) = [int(x) for x in input().split()]
lst = [int(x) for x in input().split()]
import queue
q = queue.Queue()
s = set()
for i in lst:
	if i not in s:
		if q.qsize() >= k:
			s.remove(q.get())
			q.put(i)
			s.add(i)
		else:
			q.put(i)
			s.add(i)
p = []
for i in range(q.qsize()):
	p.append(q.get())
p.reverse()
print(len(p))
for i in p:
	print(i, end=' ')


(n, k) = map(int, input().split())
msgs = [int(a) for a in input().split()]
from collections import deque
a = deque([], maxlen=k)
for id in msgs:
	if id in a:
		continue
	a.append(id)
l = min(n, k)
out = list(a)[l::-1]
print(len(out))
print(*out)


from collections import deque
n_m = list(map(int, input().split()))
mass = list(map(int, input().split()))
conf = [0] * n_m[1]
d = deque(conf, len(conf))
for i in range(n_m[0]):
	if mass[i] not in d:
		d.appendleft(mass[i])
count = 0
for (i, val) in enumerate(d):
	if val != 0:
		count += 1
		conf[i] = val
print(count)
print(' '.join((str(a) for a in conf if a != 0)))


import sys
import math
from math import ceil
import bisect
from collections import deque

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def modst(a, s):
	res = 1
	while s:
		if s % 2:
			res *= a
		a *= a
		s //= 2
	return res

def main():
	(n, k) = rinput()
	s = set()
	res = deque()
	for i in rinput():
		if i in s:
			continue
		if len(res) == k:
			s.discard(res.pop())
		res.appendleft(i)
		s.add(i)
	print(len(res))
	print(*res)
main()


class ConstantQ:

	def __init__(self, kk):
		self.k = kk
		self.q = []

	def add(self, idi):
		if idi not in self.q:
			if len(self.q) < self.k:
				self.q = [idi] + self.q
			else:
				del self.q[-1]
				self.q = [idi] + self.q
		else:
			pass

	def printQ(self):
		print(len(self.q))
		for idi in self.q:
			print(idi, end=' ')

def convo(n, k, ids):
	q = ConstantQ(k)
	for idi in ids:
		q.add(idi)
	q.printQ()

def io():
	(n, k) = map(int, input().split())
	ids = list(map(int, input().split()))
	convo(n, k, ids)
io()


def main():
	from collections import deque
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		d[i] = 0
	scr = deque()
	for idf in a:
		if d[idf] == 0:
			d[idf] = 1
			if len(scr) == k:
				d[scr.popleft()] = 0
			scr.append(idf)
	print(len(scr))
	for i in range(len(scr)):
		print(scr.pop(), end=' ')
main()


result = []
(n, k) = [int(i) for i in input().split(' ')]
msgs = [int(i) for i in input().split(' ')]
for msg in msgs:
	if len(result) == k:
		if msg not in result:
			result = [msg] + result[:-1]
	elif msg not in result:
		result = [msg] + result
print(len(result))
print(' '.join([str(i) for i in result]))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
res = []
for i in arr:
	if len(res) < k:
		if i not in res:
			res.insert(0, i)
		else:
			continue
	elif i not in res:
		res.pop()
		res.insert(0, i)
	else:
		continue
print(len(res))
for k in res:
	print(k, end=' ')


(n, k) = map(int, input().split())
q = []
isv = {}
id = list(map(int, input().split()))
for v in id:
	if isv.get(v) == None:
		isv[v] = 1
		if len(q) == k:
			x = q.pop(0)
			isv.pop(x)
		q.append(v)
print(len(q))
for i in range(len(q) - 1, -1, -1):
	print(q[i], end=' ')


from collections import deque
(messages, capacity) = [int(i) for i in input().split()]
friends = [int(i) for i in input().split()]
messages_queue = deque()
messages_set = set()
for f in friends:
	if f not in messages_set:
		messages_set.add(f)
		messages_queue.append(f)
		if len(messages_queue) > capacity:
			pop_friend = messages_queue.popleft()
			messages_set.discard(pop_friend)
print(len(messages_queue))
print(' '.join((str(n) for n in reversed(messages_queue))))


(n, k) = (int(i) for i in input().split(' '))
ids = [int(i) for i in input().split(' ')]
current_screen_list = []
current_screen_set = set()
for _id in ids:
	if _id not in current_screen_set:
		if len(current_screen_set) == k:
			last = current_screen_list.pop()
			current_screen_set.discard(last)
		current_screen_list.insert(0, _id)
		current_screen_set.add(_id)
print(len(current_screen_list))
print(' '.join([str(i) for i in current_screen_list]))


from collections import defaultdict
dic = defaultdict(lambda : 0)
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
arp = []
for nm in ar:
	if dic[nm] == 0 and len(arp) < k:
		dic[nm] = 1
		arp.append(nm)
	elif len(arp) >= k and dic[nm] == 0:
		dic[nm] = 1
		x = arp.pop(0)
		dic[x] = 0
		arp.append(nm)
print(len(arp))
print(*arp[::-1])


from collections import deque
(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
S = set()
que = deque()
for a in l:
	if a in S:
		continue
	if len(que) == m:
		b = que.popleft()
		S.remove(b)
	que.append(a)
	S.add(a)
print(len(que))
print(*reversed(que))


from collections import deque
(n, k) = map(int, input().split())
q = list(map(int, input().split()))
z = {}
w = deque()
for i in q:
	if not (i in z and z[i] == 1):
		z[i] = 1
		if len(w) < k:
			w.append(i)
		else:
			x = w.popleft()
			z[x] = -1
			w.append(i)
print(len(w))
print(*reversed(w))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
z = []
for i in l:
	if len(z) < k and i not in z:
		z.insert(0, i)
	if len(z) == k:
		if i in z:
			continue
		if i not in z:
			z.remove(z[len(z) - 1])
			z.insert(0, i)
print(len(z))
for y in z:
	print(y, end=' ')


(a, b) = list(map(int, input().split()))
l = list(map(int, input().split()))
px = list(set(l))
lx = []
t = len(px)
if t >= b:
	t = b
lp = 0
print(t)
for i in l:
	if i not in lx and lp == b:
		lx.pop(0)
		lp -= 1
	if i not in lx:
		lx.append(i)
		lp += 1
print(*lx[::-1])


(n, k) = map(int, input().split())
ids = list(map(int, input().split()))
a = []
for i in range(n):
	if len(a) < k:
		if ids[i] not in a:
			a.insert(0, ids[i])
	elif ids[i] not in a:
		a.pop()
		a.insert(0, ids[i])
print(len(a))
print(*a)


(n, k) = list(map(int, input().split()))
m = list(map(int, input().split()))
s = set()
tela = []
for i in m:
	if len(tela) < k:
		if i not in s:
			tela.append(i)
			s.add(i)
	elif i not in s:
		s.remove(tela.pop(0))
		tela.append(i)
		s.add(i)
tela.reverse()
print(len(tela))
r = ''
for i in tela:
	r += str(i) + ' '
print(r.rstrip())


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
sub = []
for i in range(n):
	if not a[i] in sub:
		if len(sub) == k:
			sub.pop(len(sub) - 1)
		sub.insert(0, a[i])
print(len(sub))
print(*sub)


from collections import deque
(k, n) = map(int, input().split())
s = map(int, input().split())
a = deque()
b = set()
kk = 0
for i in s:
	if i in b:
		pass
	else:
		if kk < n:
			kk += 1
		else:
			c = a.popleft()
			b.remove(c)
		b.add(i)
		a.append(i)
print(kk)
for i in range(kk):
	print(a[kk - i - 1], end=' ')


import sys
(n, k) = map(int, input().split())
ids = [int(x) for x in input().split()]
on = dict()
for id in ids:
	on[id] = 0
conv = []
for id in ids:
	if on[id] == 1:
		continue
	if len(conv) == k:
		on[conv[0]] = 0
		del conv[0]
		conv.append(id)
	else:
		conv.append(id)
	on[id] = 1
print(len(conv))
for i in range(len(conv)):
	print(conv[-i - 1], end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
present = {}
display = []
for i in arr:
	if len(display) != k:
		try:
			t = present[i]
		except KeyError:
			display.insert(0, i)
			present[i] = 1
	else:
		try:
			t = present[i]
		except KeyError:
			x = display.pop()
			del present[x]
			present[i] = 1
			display.insert(0, i)
print(len(display))
for i in display:
	print(i, end=' ')
print()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
from collections import deque
from collections import defaultdict
b = deque()
c = defaultdict(int)
for i in a:
	c[i] = 0
l = 0
i = 0
while i < n:
	if l < k:
		if c[a[i]] == 1:
			i = i + 1
			continue
		else:
			b.appendleft(a[i])
			c[a[i]] = 1
			l = l + 1
			i = i + 1
	elif c[a[i]] == 1:
		i = i + 1
		continue
	else:
		e = b.pop()
		c[e] = 0
		c[a[i]] = 1
		b.appendleft(a[i])
		i = i + 1
print(len(b))
print(*b)


(n, k) = map(int, input().split())
vetor = list(map(int, input().split()))
stack = []
for num in vetor:
	if num not in stack:
		if len(stack) < k:
			stack = [num] + stack
		else:
			stack.pop()
			stack = [num] + stack
print(len(stack))
print(' '.join(list(map(str, stack))))


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
print(min(k, min(n, len(set(arr)))))
tel = []
for i in arr:
	if not i in tel:
		if len(tel) < k:
			tel = [i] + tel
		else:
			tel = [i] + tel[:len(tel) - 1]
print(*tel)


(n, k) = list(map(int, input().split()))
ids = list(map(int, input().split()))
screen = [None] * k
convs = 0
if k >= 1:
	for i in ids:
		if i not in screen:
			screen[1:] = screen[0:k - 1]
			screen[0] = i
		else:
			continue
for i in screen:
	if i:
		convs += 1
print(convs)
print(*screen[0:convs])


(n, k) = input().split()
n = int(n)
k = int(k)
arr = list(map(int, input().split()))
list1 = []
for i in arr:
	if i in list1:
		continue
	if i not in list1 and len(list1) == k:
		list1.pop()
		list1.insert(0, i)
	elif i not in list1 and len(list1) < k:
		list1.insert(0, i)
print(len(list1))
for j in list1:
	print(j, end=' ')


(n, k) = map(int, input().split())
a = [0] * k
l = 0
curr = set()
ids = map(int, input().split())
for id in ids:
	if id not in curr:
		curr.add(id)
		if a[-1] != 0:
			curr.remove(a[-1])
		a[1:] = a[:-1]
		a[0] = id
		l = min(l + 1, k)
print(l)
print(' '.join(map(str, a[:l])))


from collections import deque
(n, k) = [int(t) for t in input().split(' ')]
ids = [int(t) for t in input().split(' ')]
cont = set()
q = deque()
for id in ids:
	if id in cont:
		continue
	if len(q) == k:
		o = q.pop()
		cont.remove(o)
	q.appendleft(id)
	cont.add(id)
print(len(q))
print(' '.join([str(t) for t in q]))


(n, k) = list(map(int, input().split()))
ar = list(map(int, input().split()))
res = []
count = 0
for x in ar:
	if count < k:
		if x in res:
			continue
		else:
			res.insert(0, x)
			count += 1
	elif x in res:
		continue
	else:
		res.pop()
		res.insert(0, x)
print(count)
for i in range(len(res)):
	print(res[i], end=' ')


(n, k) = [int(x) for x in input().split()]
ids = [x for x in input().split()]
c = []
for i in range(n):
	m = ids[i]
	if m not in c:
		if len(c) == k:
			del c[-1]
			c.insert(0, m)
		else:
			c.insert(0, m)
print(len(c))
print(' '.join(c))


(n, k) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
M = []
for i in range(n):
	if a[i] in M:
		continue
	elif len(M) == k:
		M.pop(0)
	M.append(a[i])
print(str(len(M)))
print(' '.join(list(map(str, M[::-1]))))


(n, k) = list(map(int, input().split()))
L = list(map(int, input().split()))
L1 = []
s = set(L)
s1 = set()
x = 0
for i in range(len(L)):
	if len(s) == len(s1):
		break
	if L[i] in s1:
		continue
	elif len(L1) < k:
		L1.append(L[i])
		s1.add(L[i])
	else:
		L1.append(L[i])
		s1.remove(L1[x])
		s1.add(L[i])
		x += 1
print(len(s1))
for i in range(len(L1) - 1, max(len(L1) - k - 1, -1), -1):
	print(L1[i], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
import collections
screen = collections.OrderedDict()
for m in a:
	if m not in screen:
		screen[m] = m
		if len(screen) > k:
			screen.popitem(last=False)
print(len(screen))
onscreen = ''
while screen:
	onscreen += str(screen.popitem()[0]) + ' '
print(onscreen.strip())


(n, k) = [int(ele) for ele in input().split()]
id_array = [int(ele) for ele in input().split()]
Dict = {}
stack_list = []
for Id in id_array:
	if Id not in Dict:
		stack_list.insert(0, Id)
		Dict[Id] = 1
	if len(stack_list) > k:
		a = stack_list.pop()
		del Dict[a]
print(len(stack_list))
stack_list = ' '.join([str(ele) for ele in stack_list])
print(stack_list)


(n, k) = map(int, input().split())
sata = list(map(int, input().split()))
queue = []
queue.append(sata[0])
for i in range(1, n):
	t = True
	for g in range(len(queue)):
		if sata[i] == queue[g]:
			t = False
			break
	if t and len(queue) < k:
		queue.append(sata[i])
	elif t and len(queue) == k:
		queue.pop(0)
		queue.append(sata[i])
u = len(queue)
print(u)
for i in range(u - 1, -1, -1):
	print(queue[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
v = []
top = -1
p = 0
for i in range(n):
	if l[i] in v:
		continue
	elif len(v) == k:
		v.pop()
		v.insert(0, l[i])
	else:
		v.insert(0, l[i])
print(len(v))
print(*v)


from collections import deque

def soln() -> None:

	def logic() -> None:
		(n, k) = [int(x) for x in input().split()]
		arr = [int(x) for x in input().split()]
		s = set()
		q = deque(maxlen=k)
		for i in arr:
			if i not in s:
				if len(q) == k:
					s.remove(q[-1])
				q.appendleft(i)
				s.add(i)
		print(len(q))
		for i in q:
			print(i, end=' ')
		print()
	logic()
soln()


from collections import deque
s = input().split()
n = int(s[0])
k = int(s[1])
s = input().split()
id = deque()
visible = set()
for i in s:
	elem = int(i)
	if elem not in visible:
		id.appendleft(elem)
		visible.add(elem)
		if len(id) > k:
			x = id.pop()
			visible.remove(x)
print(len(id))
s = ''
for i in id:
	s += str(i) + ' '
print(s)


from collections import deque

def main():
	(n, k) = map(int, input().split())
	messages = [int(c) for c in input().split()]
	queue = deque()
	elms = set()
	for m in messages:
		if m not in elms:
			queue.appendleft(m)
			elms.add(m)
		if len(queue) > k:
			elms.discard(queue.pop())
	print(len(queue))
	print(*queue)
main()


p = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
k = p[1]
c = {i - 1: 0 for i in a}
d = [a[0]]
c[a[0] - 1] = 1
for e in a[1:]:
	if c[e - 1] == 0:
		d.append(e)
		c[e - 1] = 1
	if len(d) > k:
		c[d[-k - 1] - 1] = 0
print(len(d) if len(d) < k else k)
print(' '.join(list(map(str, d[-1:-k - 1:-1]))))


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
msk = []
for i in lis:
	if i not in msk[0:k]:
		msk.insert(0, i)
print(len(msk[0:k]))
print(*msk[0:k])


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

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

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
(n, k) = mi()
a = li()
ans = []
for i in range(n):
	t = 0
	la = len(ans)
	for j in range(la):
		if a[i] != ans[j]:
			t += 1
	if t == la:
		ans.append(a[i])
	if len(ans) > k:
		ans.remove(ans[0])
print(len(ans))
print(wr(reversed(ans)))


(n, k) = [int(x) for x in input().split()]
a = [int(y) for y in input().split()]
b = []
for w in a:
	if w in b:
		pass
	else:
		b.append(w)
		if len(b) > k:
			b.pop(0)
b.reverse()
print(len(b))
for f in b:
	print(f, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
new = []
s = set()
for (i, ele) in enumerate(arr):
	if ele not in s:
		if len(new) == k:
			s.remove(new.pop(0))
		new.append(ele)
		s.add(ele)
print(len(new))
print(*new[::-1])


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = deque([], maxlen=k)
for x in a:
	if x in l:
		continue
	l.appendleft(x)
print(len(l))
print(*l)


m = [int(a) for a in input().split()]
(n, k) = (m[0], m[1])
ans = list()
for i in input().split():
	i = int(i)
	if i in ans:
		continue
	if len(ans) == k:
		ans.remove(ans[k - 1])
	ans.insert(0, i)
print(len(ans))
for i in ans:
	print(i, end=' ')


from collections import deque

def soln() -> None:

	def logic() -> None:
		(n, k) = [int(x) for x in input().split()]
		arr = [int(x) for x in input().split()]
		q = deque(maxlen=k)
		for i in arr:
			if i not in q:
				q.appendleft(i)
		print(len(q))
		for i in q:
			print(i, end=' ')
		print()
	logic()
soln()


from collections import deque

def solution(arr, n) -> None:
	d = deque(maxlen=n)
	for v in arr:
		if v not in d:
			d.appendleft(v)
	print('{}\n{}'.format(len(d), ' '.join((str(i) for i in d))))

def main():
	(p, q) = map(int, input().split())
	arr = map(int, input().split())
	solution(arr, q)
main()


from sys import stdin, stdout
import collections
de = collections.deque([])
inp = stdin.readline().split()
n = int(inp[0])
k = int(inp[1])
inp = stdin.readline().split()
a = list(map(int, inp))
d = {}
for i in range(len(a)):
	if a[i] not in d:
		d[a[i]] = 1
		if len(de) == k:
			del d[de.pop()]
		de.appendleft(a[i])
print(len(de))
for i in de:
	print(i, end=' ')


l1 = [int(x) for x in input().split()]
(n, k) = (l1[0], l1[1])
window = []
l2 = [int(x) for x in input().split()]
for x in range(n):
	if len(window) < k:
		if l2[x] not in window:
			window.append(l2[x])
	elif l2[x] not in window:
		window.remove(window[0])
		window.append(l2[x])
window.reverse()
print(len(window))
print(*window)


class Nod:

	def __init__(self, n):
		self.val = n
		self.n = None
(n, k) = map(int, input().split())
s = set()
l = r = None
for i in map(int, input().split()):
	if i not in s:
		if len(s) == k:
			s.remove(l.val)
			if l == r:
				l = r = None
			else:
				l = l.n
		s.add(i)
		if l == None:
			l = r = Nod(i)
		else:
			r.n = Nod(i)
			r = r.n
ll = []
while l != None:
	ll.append(l.val)
	l = l.n
print(len(ll))
print(*ll[::-1])


(a, b) = map(int, input().split())
l = []
for i in input().split():
	if len(l) == b and i not in l:
		l.pop(0)
		l.append(i)
	elif i not in l:
		l.append(i)
print(len(l))
print(*l[::-1])


(N, K) = map(int, input().split())
id_list = list(map(int, input().split()))
from collections import deque
que = deque()
used = set()
for id in id_list:
	if id in used:
		continue
	else:
		if len(que) >= K:
			q = que.pop()
			used.remove(q)
		que.appendleft(id)
		used.add(id)
print(len(que))
while len(que) != 0:
	print(que.popleft(), end=' ')


from collections import deque
(n, k) = map(int, input().split())
a = [*map(int, input().split())]
que = deque()
s = set()
for el in a:
	if el in s:
		continue
	if len(que) == k:
		b = que.pop()
		s.remove(b)
	que.appendleft(el)
	s.add(el)
print(len(que))
print(*que)


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
stack = []
d = {}
count1 = 0
for i in range(len(li)):
	if li[i] not in d:
		stack.insert(0, li[i])
		count1 += 1
		d[li[i]] = 1
		if len(stack) == k + 1:
			a1 = stack.pop(len(stack) - 1)
			del d[a1]
print(min(k, count1))
for i in range(len(stack)):
	print(stack[i], end=' ')


(inps, box) = input().split()
inps = int(inps)
box = int(box)
ms = [int(x) for x in input().split()]
outs = []
for i in ms:
	if i not in outs:
		outs.insert(0, i)
	if len(outs) > box:
		outs.pop(-1)
print(len(outs))
for i in outs:
	print(i, end=' ')


import math
inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
(n, k) = inp()
A = inp()
(B, S) = ([], set())
(l, r) = (0, -1)
for a in A:
	if a not in S:
		S.add(a)
		B.append(a)
		r += 1
		if r - l + 1 > k:
			S.remove(B[l])
			l += 1
print(r - l + 1)
for b in B[l:][::-1]:
	print(b, end=' ')


from collections import deque
(n, k) = map(int, input().split())
q = deque()
isv = set()
id = list(map(int, input().split()))
for v in id:
	if v not in isv:
		isv.add(v)
		if len(q) == k:
			x = q.popleft()
			isv.remove(x)
		q.append(v)
print(len(q))
for i in range(len(q) - 1, -1, -1):
	print(q[i], end=' ')


from collections import defaultdict
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = []
d = defaultdict(int)
for i in range(n):
	if d[a[i]] == 1:
		pass
	else:
		l.insert(0, a[i])
		d[a[i]] = 1
	if len(l) > k:
		c = l.pop(-1)
		d[c] = 0
print(len(l))
print(*l)


(n, k) = map(int, input().split())
id1 = [int(i) for i in input().split()]
arr = []
for i in range(n):
	if id1[i] in arr:
		continue
	elif len(arr) == k:
		arr.pop(0)
		arr.append(id1[i])
	elif len(arr) < k:
		arr.append(id1[i])
	else:
		break
print(len(arr))
arr = arr[::-1]
print(*arr)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
t = []
for j in l:
	if j in t:
		pass
	elif len(t) == k:
		t = t[:-1]
		t.insert(0, j)
	else:
		t.insert(0, j)
print(len(t))
print(*t)


k = []
b = input()
ki = b.split(' ')
c = input()
ni = c.split(' ')
for i in ni:
	if i not in k:
		if len(k) < int(ki[1]):
			k.insert(0, i)
		else:
			k.insert(0, i)
			k.pop()
print(len(k))
print(*k)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = []
for i in range(n):
	if l[i] not in m and len(m) < k:
		m.insert(0, l[i])
	elif l[i] not in m and len(m) == k:
		m.remove(m[k - 1])
		m.insert(0, l[i])
print(len(m))
print(*m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = []
s = set()
for i in a:
	if i not in s:
		s.add(i)
		l.append(i)
		if len(s) > k:
			s.remove(l[0])
			l.pop(0)
print(len(s))
print(*l[::-1])


from sys import stdin, stdout
from collections import *

def read():
	return list(map(int, stdin.readline().split()))
(n, k) = read()
inque = set()
q = deque()
ids = read()
for i in range(len(ids)):
	id = ids[i]
	if id in inque:
		continue
	if len(q) == k:
		inque.remove(q.pop())
	q.appendleft(id)
	inque.add(id)
stdout.write(str(len(q)))
stdout.write('\n')
for i in range(len(q)):
	if i:
		stdout.write(' ')
	stdout.write(str(q[i]))
stdout.write('\n')


from collections import defaultdict as dfd
(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
val = dfd(int)
B = []
for i in range(len(A)):
	if len(B) < Q and val[A[i]] != 1:
		B.append(A[i])
		val[A[i]] = 1
	elif val[A[i]] == 1:
		continue
	else:
		temp = B.pop(0)
		val[temp] = 0
		B.append(A[i])
		val[A[i]] = 1
print(len(B))
print(*B[::-1])


num = list(map(int, input().split()))
vals = list(map(int, input().split()))
size = num[1]
arr = []
for i in vals:
	if len(arr) < size:
		if i in arr:
			continue
		else:
			arr.append(i)
	elif i in arr:
		continue
	else:
		arr.remove(arr[0])
		arr.append(i)
print(len(arr))
for i in reversed(arr):
	print(i, end=' ')


nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
ids = list(map(int, input().split()))
current_screen = set()
screen = []
for cur_id in ids:
	found = False
	if cur_id not in current_screen:
		if len(screen) >= k:
			current_screen.remove(screen[-k])
		screen.append(cur_id)
		current_screen.add(cur_id)
if len(screen) <= k:
	print(len(screen))
	print(' '.join(map(str, screen[::-1])))
else:
	print(k)
	print(' '.join(map(str, screen[-k:][::-1])))


import math

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

def num():
	return map(int, input().split())

def nu():
	return int(input())

def solve():
	(n, k) = num()
	l = li()
	s = []
	s.append(l[0])
	for i in range(1, n):
		if l[i] not in s:
			s.insert(0, l[i])
			if len(s) > k:
				del s[k]
	print(len(s))
	print(' '.join(map(str, s)))
solve()


def getMessage(screen, ID, k):
	result = screen
	if ID in result:
		return result
	if len(result) < k:
		result.insert(0, ID)
	else:
		result.pop()
		result.insert(0, ID)
	return result
(messages, talks) = map(int, input().split())
seq = list(map(int, input().split()))
screen = []
for mes in seq:
	screen = getMessage(screen, mes, talks)
print(len(screen))
for mes in screen:
	print(mes, end=' ')


import sys
from collections import deque
from itertools import islice
(n, k) = map(int, sys.stdin.readline().rstrip().split())
mes = sys.stdin.readline().rstrip().split()
screen = deque()
sc_s = set()
diff_s = set()
for i in range(k):
	screen.appendleft(i)
	sc_s.add(i)
	diff_s.add(i)
for m in mes:
	if m not in sc_s:
		sc_s.add(m)
		sc_s.remove(screen.pop())
		screen.appendleft(m)
sc_s.difference_update(diff_s)
print(len(sc_s))
print(' '.join(islice(screen, 0, len(sc_s))))


(n, m) = tuple(map(int, input().split()))
num_arr = list(map(int, input().split()))
results = [0] * m
for i in range(len(num_arr)):
	if num_arr[i] in results:
		continue
	elif 0 in results:
		zero_index = results.index(0)
		results[1:zero_index + 1] = results[0:zero_index]
		results[0] = num_arr[i]
	else:
		results[1:m] = results[0:m - 1]
		results[0] = num_arr[i]
results = [str(i) for i in results if i != 0]
print(len(results))
print(' '.join(results))


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

class Node:

	def __init__(self):
		self.Data = None
		self.Next = None

class LinkedList:

	def __init__(self):
		self.Head = None

	def InsEnd(self, data):
		if self.Head == None:
			x = Node()
			x.Data = data
			self.Head = x
		else:
			i = self.Head
			while i.Next != None:
				i = i.Next
			x = Node()
			x.Data = data
			i.Next = x

	def InsBeg(self, data):
		if self.Head == None:
			x = Node()
			x.Data = data
			self.Head = x
		else:
			x = Node()
			x.Data = data
			x.Next = self.Head
			self.Head = x

	def DelEnd(self):
		i = self.Head
		while i.Next.Next != None:
			i = i.Next
		x = i.Next.Data
		i.Next = None
		return x

	def AddToBeg(self, Node):
		i = self.Head
		if i == Node:
			return self.Head
		else:
			while i.Next != Node:
				i = i.Next
			x = i.Next
			y = i.Next.Next
			x.Next = self.Head
			self.Head = x
			i.Next = y
			return self.Head

	def Size(self):
		if self.Head == None:
			return 0
		else:
			i = self.Head
			cnt = 0
			while i == None:
				i = i.Next
				cnt += 1
			return cnt

	def SchL(self, key):
		if self.Head == None:
			return -1
		else:
			i = self.Head
			while i != None and i.Data != key:
				i = i.Next
			return i

	def pll(self):
		i = self.Head
		while i != None:
			print(i.Data, end=' ')
			i = i.Next
a = list(map(int, input().split()))
ll = LinkedList()
d = {}
size = 0
for j in a:
	if d.get(j):
		d[j] += 1
	else:
		d[j] = 1
		if size < k:
			ll.InsBeg(j)
			size = size + 1
		else:
			ll.InsBeg(j)
			d.pop(ll.DelEnd())
print(min(len(d), k))
ll.pll()


def social_network(arr, k):
	res = [0] * k
	for i in arr:
		if i in res:
			pass
		else:
			res.insert(0, i)
			res.pop()
	n = res.count(0)
	for i in range(n):
		res.pop()
	return res
nk = list(map(int, input().strip().split()))
n = nk[0]
k = nk[1]
arr = list(map(int, input().strip().split()))
result = social_network(arr, k)
print(len(result))
print(*result)


(n, k) = map(int, input().split())
j = [int(i) for i in input().split()]
otv = []
for i in range(n):
	if len(otv) < k and otv.count(j[i]) == 0:
		otv = [j[i]] + otv
	elif otv.count(j[i]) == 0:
		otv.pop()
		otv = [j[i]] + otv
print(len(otv))
print(*otv)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = []
s = set()
j = 0
for i in a:
	if i not in s:
		s.add(i)
		ans.append(i)
		if len(ans) > k:
			s -= {ans[j]}
			j += 1
print(len(ans) - j)
print(*reversed(ans[j:]))


(n, k) = input().split()
n = int(n)
k = int(k)
lis = list(map(int, input().split()))
lis1 = []
for i in lis:
	if i not in lis1:
		lis1.append(i)
		if len(lis1) > k:
			del lis1[0]
print(len(lis1))
for i in range(len(lis1)):
	print(lis1[len(lis1) - 1 - i], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	if a[i] not in ans:
		ans = [a[i]] + ans
	if len(ans) > k:
		del ans[-1:]
print(len(ans))
print(*ans)


from collections import deque
d = deque()

def conversation(array, n, k):
	s = set()
	count = 0
	i = 0
	while i < n and count != k:
		if i < n and array[i] not in s:
			d.appendleft(array[i])
			s.add(array[i])
			count += 1
		i += 1
	while i < n:
		if array[i] not in s:
			d.appendleft(array[i])
			x = d.pop()
			s.add(array[i])
			s.discard(x)
		i += 1
	return d
(n, k) = map(int, input().split())
array = list(map(int, input().split()))
ans = conversation(array, n, k)
print(len(ans))
print(*ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())

class node:

	def __init__(self, nxt, val):
		self.next = nxt
		self.prev = None
		self.val = val
		if nxt:
			nxt.prev = self

class ll:

	def __init__(self):
		self.fst = self.lst = None

	def add(self, val):
		if self.fst == None:
			self.fst = self.lst = node(None, val)
		else:
			self.lst = node(self.lst, val)

	def pop(self):
		if not self.fst:
			return None
		(f2, self.fst) = (self.fst.val, self.fst.prev)
		if self.fst == None:
			self.lst = None
		return f2
(n, k) = kk()
(s, size) = (set(), 0)
l = ll()
for i in kk():
	if i in s:
		continue
	s.add(i)
	l.add(i)
	size += 1
	if size > k:
		s.remove(l.pop())
		size -= 1
print(size)
vals = [str(l.pop()) for _ in range(size)]
print(' '.join(reversed(vals)))
exit()


(n, k) = input().split()
(n, k) = (int(n), int(k))
ar = list(map(int, input().split()))
a = []
for i in range(n):
	if not ar[i] in a:
		a.insert(0, ar[i])
		if len(a) > k:
			del a[k:]
print(len(a))
print(*a, sep=' ')


(n, k) = map(int, input().split())
messages = list(map(int, input().split()))
displayed = []
for m in messages:
	if m in displayed:
		continue
	elif len(displayed) < k:
		displayed = [m] + displayed
	else:
		displayed = [m] + displayed[:-1]
print(len(displayed))
print(*displayed, sep=' ')


(n, k) = map(int, input().split())
bess = []
tl = set()
tail = 0
head = 0
n_list = list(map(int, input().split()))
for i in range(n):
	if not n_list[i] in tl:
		if head >= k:
			tl.remove(bess[tail])
			tail += 1
		bess.append(n_list[i])
		tl.add(n_list[i])
		head += 1
print(len(tl))
bess = bess[::-1]
for i in range(len(tl)):
	print(bess[i], end=' ')


from collections import deque

def solve(history, k):
	seen = set()
	feed = deque()
	for friend in history:
		if friend in seen:
			continue
		if len(feed) == k:
			evicted = feed.pop()
			seen.remove(evicted)
		seen.add(friend)
		feed.appendleft(friend)
	return feed
(_, k) = map(int, input().split())
history = map(int, input().split())
shown = solve(history, k)
print(len(shown))
print(' '.join(map(str, shown)))


(n, k) = map(int, input().split())
ids = [int(x) for x in input().split()]
q = []
for i in range(n):
	if not ids[i] in q:
		if len(q) >= k:
			q.pop()
		q.insert(0, ids[i])
print(len(q))
for x in q:
	print(x, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
store = []
for i in arr:
	if i not in store:
		if len(store) < k:
			store.insert(0, i)
		elif len(store) >= k:
			store.pop()
			store.insert(0, i)
print(len(store))
for i in store:
	print(i, end=' ')


import collections
[n, k] = [int(x) for x in input().split(' ')]
messages = [int(x) for x in input().split(' ')]
cur = list([None for _ in range(k)])
for x in messages:
	if x not in cur:
		for j in range(k - 1, 0, -1):
			cur[j] = cur[j - 1]
		cur[0] = x
r = [str(k) for k in filter(lambda x: x is not None, cur)]
print(len(r))
print(' '.join(r))


def run():
	(n, k) = list(map(int, input().split()))
	ids = list(map(int, input().split()))
	screen = []
	for i in range(n):
		if ids[i] in screen:
			continue
		else:
			screen.insert(0, ids[i])
			if len(screen) > k:
				screen = screen[:k]
	print(len(screen))
	print(' '.join(list(map(str, screen))))
run()


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]

def round(n):
	return int(n + 0.5)
DEBUG = 1
DEBUG = 0

def debug(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)
(n, k) = viread()
cons = viread()
q = []
present = set()
for c in cons:
	if c not in present:
		if len(q) == k:
			present.remove(q.pop(0))
		q.append(c)
		present.add(c)
print(len(q))
print(*q[::-1])


import collections
(n, k) = map(int, input().split())
li = list(map(int, input().split()))
l = collections.deque([])
for i in li:
	if l.count(i) == 0:
		if len(l) == k:
			l.pop()
		l.appendleft(i)
print(len(l))
print(*l)


cons = list(map(int, input().split()))
n = cons[0]
k = cons[1]
result = list()
a = list(map(int, input().split()))
for i in range(n):
	if a[i] in result:
		continue
	if len(result) == k:
		result = result[:-1]
	result.insert(0, a[i])
print(len(result))
print(' '.join(map(str, result)))


(n, k) = map(int, input().split())
arr = list(input().split())
ans = []
for i in arr:
	if i not in ans:
		if len(ans) == k:
			del ans[0]
		ans.append(i)
print(len(ans))
print(' '.join(ans[::-1]))


specs = input().split()
for i in range(len(specs)):
	specs[i] = int(specs[i])
k = specs[1]
order = input().split()
for i in range(len(order)):
	order[i] = int(order[i])
from collections import deque
queue = deque()
s = set()
for i in range(len(order)):
	flag = 0
	if order[i] in s:
		flag = 1
	if flag == 0:
		if len(queue) == k:
			delta = queue.popleft()
			s.remove(delta)
			queue.append(order[i])
			s.add(order[i])
		else:
			s.add(order[i])
			queue.append(order[i])
print(len(queue))
queue.reverse()
for x in queue:
	print(x, end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque
q = deque()
s = set()
for id in l:
	if id not in s:
		if len(q) != k:
			q.append(id)
			s.add(id)
		else:
			x = q.popleft()
			s.discard(x)
			q.append(id)
		s.add(id)
	else:
		continue
q = list(q)
q.reverse()
print(len(q))
print(' '.join(map(str, q)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
y = []
x = set()
for i in l:
	if i not in x:
		x.add(i)
		y.append(i)
		if len(x) > k:
			x.remove(y[0])
			y.pop(0)
print(len(x))
print(*y[::-1])


from sys import stdin, stdout, setrecursionlimit
from collections import OrderedDict

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		(n, k) = [int(x) for x in R().split()]
		ID = [int(x) for x in R().split()]
		conversation = OrderedDict()
		right = 1
		for j in range(n):
			if ID[j] not in conversation:
				conversation[ID[j]] = True
				if len(conversation) > k:
					conversation.popitem(last=False)
		ans.append(str(len(conversation)))
		ans.append('\n')
		while len(conversation):
			ans.append(str(conversation.popitem()[0]))
			ans.append(' ')
		W(''.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


l1 = list(input().split(' '))
l = list(input().split(' '))
l2 = []
j = 0
while j < int(l1[0]):
	if l[j] not in l2:
		l2 = [l[j]] + l2
		l2 = l2[:int(l1[1])]
	j += 1
print(len(l2))
print(' '.join(l2))


(n, k) = list(map(int, input().split()))
nums = []
l = list(map(int, input().split()))
for i in l:
	if len(nums) >= k and i not in nums:
		nums.pop(-1)
		nums.insert(0, i)
	elif len(nums) < k and i not in nums:
		nums.insert(0, i)
print(len(nums))
for i in nums:
	print(i, end=' ')


records = list(map(int, input().split()))
n = records[0]
k = records[1]
arr = list(map(int, input().split()))
ans = []
for i in arr:
	if i not in ans:
		if len(ans) == k:
			del ans[-1]
		ans.insert(0, i)
print(len(ans))
for i in ans:
	print(i, end=' ')


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
l = []
for i in range(0, len(a)):
	if a[i] in l:
		pass
	elif len(l) < m:
		l.insert(0, a[i])
	else:
		l.pop(len(l) - 1)
		l.insert(0, a[i])
print(len(l))
print(*l)


from collections import deque
(n, k) = map(int, input().split())
g = {}
s = list(map(int, input().split()))
h = deque()
for i in range(n):
	if not g.get(s[i]):
		if len(g) == k:
			g.pop(h.pop())
		g[s[i]] = 1
		h.appendleft(s[i])
print(len(h))
print(*h)


from math import gcd, ceil
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
inp = lambda : int(stdin.readline())
sip = lambda : stdin.readline()
mulip = lambda : map(int, stdin.readline().split())
lst = lambda : list(map(int, stdin.readline().split()))
slst = lambda : list(sip())
M = pow(10, 9) + 7
(n, k) = mulip()
A = lst()
d = defaultdict(int)
q = deque()
for i in range(n):
	if len(q) < k:
		if A[i] not in d:
			q.appendleft(A[i])
			d[A[i]] = A[i]
	elif A[i] not in d:
		del d[q[-1]]
		q.pop()
		q.appendleft(A[i])
		d[A[i]] = A[i]
print(len(q))
for i in q:
	print(i, end=' ')
print()


(n, k) = [int(x) for x in input().split(' ')]
conversation_list = []
friend_list = input().split(' ')
for i in friend_list:
	if i not in conversation_list:
		conversation_list = [i] + conversation_list
		conversation_list = conversation_list[:k]
print(len(conversation_list))
print(' '.join(conversation_list))


import heapq
(n, k) = (int(i) for i in input().split())
a = list(map(int, input().split()))
ans = []
heapq.heapify(ans)
s = set()
for (i, j) in enumerate(a):
	if j in s:
		continue
	else:
		s.add(j)
		if len(ans) < k:
			heapq.heappush(ans, (i, j))
		else:
			temp = heapq.heappop(ans)
			s.remove(temp[1])
			heapq.heappush(ans, (i, j))
			s.add(j)
ans2 = []
flag = False
while len(ans) != 0:
	ans2.append(heapq.heappop(ans)[1])
print(len(ans2))
for i in range(len(ans2) - 1, -1, -1):
	print(ans2[i], end=' ')
	flag = True
if flag:
	print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
dic = {}
pos = 0
for item in set(a):
	dic[item] = 0
for i in range(n):
	if dic[a[i]] != 1:
		dic[a[i]] = 1
		ans.append(a[i])
		pos += 1
		if pos > k:
			dic[ans[-k - 1]] = 0
ans = ans[:-k - 1:-1]
print(len(ans))
print(*ans)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
(N, K) = map(int, input().split())
L = list(map(int, input().split()))
ANS = []
for l in L:
	if l in ANS:
		continue
	else:
		ANS.append(l)
		if len(ANS) > K:
			ANS.remove(ANS[0])
print(len(ANS))
print(' '.join(map(str, ANS[::-1])))


(n, k) = map(int, input().split())
IDS = map(int, input().split())
messages = []
for ID in IDS:
	if len(messages) < k and (not messages.count(ID)):
		messages.insert(0, ID)
	elif len(messages) == k and (not messages.count(ID)):
		messages.insert(0, ID)
		messages.pop(k)
	elif messages.count(ID):
		continue
print(len(messages))
messages = ' '.join(list(map(str, messages)))
print(messages)


from collections import deque
(m, n) = list(map(int, input().split()))
arr = list(map(int, input().split()))
stack = deque([])
my_set = set()
for el in arr:
	if el in my_set:
		continue
	elif len(stack) == n:
		my_set.remove(stack.pop())
		stack.appendleft(el)
		my_set.add(el)
	else:
		stack.appendleft(el)
		my_set.add(el)
print(len(stack))
print(' '.join(list(map(str, stack))))


l = list(map(int, input().split(' ')))
n = l[0]
k = l[1]
messages = list(map(int, input().split(' ')))
screen = []
for id in messages:
	if id not in screen and len(screen) < k:
		screen.insert(0, id)
	elif id not in screen and len(screen) == k:
		del screen[-1]
		screen.insert(0, id)
print(len(screen))
for res in screen:
	print(res, end=' ')


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
tmp = []
for i in range(n):
	if a[i] in tmp:
		continue
	if len(tmp) >= k:
		tmp.pop(0)
	tmp.append(a[i])
print(len(tmp))
print(' '.join(map(str, tmp[::-1])))


(n, k) = input().split()
n = int(n)
k = int(k)
rec = map(int, input().split())
msg = []
for i in rec:
	if i not in msg:
		msg.insert(0, i)
		if len(msg) > k:
			msg.pop()
print(len(msg))
for j in range(len(msg) - 1):
	print(f'{msg[j]}', end=' ')
print(msg[len(msg) - 1])


class conversation:

	def __init__(self, size):
		self.arr = []
		self.size = size

	def add(self, num):
		if len(self.arr) < self.size:
			if num in self.arr:
				return
			self.arr.insert(0, num)
		else:
			if num in self.arr:
				return
			self.arr.insert(0, num)
			self.arr.pop()
(n, m) = map(int, input().split())
obj = conversation(m)
for some in list(map(int, input().split())):
	obj.add(some)
print(len(obj.arr))
print(*obj.arr)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
count = []
for x in a:
	if x not in count:
		if len(count) == k:
			count.pop()
		count.insert(0, x)
print(len(count))
for x in count:
	print(x, end=' ')


(n, k) = map(int, input().split())
id = list(map(int, input().split()))
ids = [None] * k
m = 0
for i in range(n):
	if id[i] not in ids:
		ids.insert(0, id[i])
		del ids[k]
for i in range(len(ids)):
	m += 1
	if ids[i] == None:
		m -= 1
ids = filter(None, ids)
print(m)
print(' '.join(map(str, ids)))


(q, w) = map(int, input().split())
e = input().split()
r = []
for i in range(q):
	if e[i] in r:
		pass
	else:
		r.append(e[i])
		if len(r) > w:
			r.pop(0)
print(len(r))
print(' '.join(r[::-1]))


def binarySearch(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return -1
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
s = list(set(l))
s.sort()
sl = len(s)
cou = []
for j in range(sl):
	cou.append(0)
m = 0
h = 0
for j in range(n):
	a = binarySearch(s, 0, sl - 1, l[j])
	if cou[a] == 0:
		if m == k + h:
			b = binarySearch(s, 0, sl - 1, ans[h])
			cou[b] -= 1
			h += 1
			ans.append(l[j])
			cou[a] += 1
			m += 1
		else:
			ans.append(l[j])
			cou[a] += 1
			m += 1
print(m - h)
for j in range(m - 1, h - 1, -1):
	print(ans[j], end=' ')


import math
inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
(n, k) = inp()
A = inp()
B = []
for a in A:
	if a in B:
		continue
	B = [a] + B
	if len(B) > k:
		B.pop()
print(len(B))
for b in B:
	print(b, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
	if a[i] not in b:
		if len(b) < m:
			b.append(a[i])
		else:
			b.remove(b[0])
			b.append(a[i])
	else:
		continue
b.reverse()
print(len(b))
print(*b)


(n, k) = [int(element) for element in input().split(' ')]
messages = [int(element) for element in input().split(' ')]
resList = []
for val in messages:
	if val not in resList:
		resList = [val] + resList
	if len(resList) > k:
		resList = resList[:k]
print(len(resList))
for val in resList:
	print(val, end=' ')


from collections import defaultdict
hash = defaultdict(bool)
(n, k) = map(int, input().split())
la = list(map(int, input().split()))
l = [0] * 10 ** 6
j = -1
count = 0
last = -1
i = 0
while i < n:
	if count < k:
		if hash[la[i]] == False:
			l[j] = la[i]
			j -= 1
			hash[la[i]] = True
			count += 1
	elif hash[la[i]] == False:
		z = l[last]
		hash[z] = False
		l[last] = 0
		last -= 1
		l[j] = la[i]
		j -= 1
		hash[la[i]] = True
	i += 1
ans = []
for i in l:
	if i != 0:
		ans.append(i)
print(len(ans))
print(*ans)


from collections import deque
(n, k) = map(int, input().split())
inp = list(map(int, input().split()))
listt = deque()
dictt = {}
for i in inp:
	dictt[i] = False
for i in inp:
	if len(listt) < k:
		if dictt[i] == False:
			listt.appendleft(i)
			dictt[i] = True
	if len(listt) == k:
		if dictt[i] == False:
			dictt[i] = True
			dictt[listt[-1]] = False
			listt.appendleft(i)
			listt.pop()
print(len(listt))
print(*listt)


z = list(map(int, input().split()))
n = z[0]
k = z[1]
a = list(map(int, input().split()))
s = [0] * (n + 2)
d = [0] * (n + 2)
dd = [0] * (n + 2)
l = 1
r = 0

def tknp(x):
	u = 1
	v = n + 1
	m = int((u + v) / 2)
	while v - u > 1:
		if s[m + 1] > x:
			v = m
		else:
			u = m
		m = int((u + v) / 2)
	return u
for i in range(n):
	s[i] = a[i]
s.sort()
for i in range(n):
	x = tknp(a[i])
	if dd[x] == 0:
		r += 1
		d[r] = a[i]
		dd[x] = 1
		if r - l == k:
			x = tknp(d[l])
			dd[x] = 0
			l += 1
print(r - l + 1)
for i in range(r - l + 1):
	print(d[r - i], end=' ')