https://codeforces.com/problemset/problem/1234/B1
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+10;
int a[N],n,k;
unordered_map<int,int>st;
queue<int>q;
int main(void)
{
cin>>n>>k;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++)
{
if(st[a[i]]) continue;
else
{
if(q.size()<k) q.push(a[i]),st[a[i]]=1;
else
{
auto temp=q.front(); q.pop();
q.push(a[i]);
st[temp]=0;
st[a[i]]=1;
};
}
}
cout<<q.size()<<endl;
vector<int>ve;
while(q.size()) ve.push_back(q.front()),q.pop();
for(int i=ve.size()-1;i>=0;i--) cout<<ve[i]<<" ";
return 0;
}