#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    map<int,bool> mp;
    int n,k;cin>>n>>k;
    vi v(n);cin>>v;
    deque<int> dq;

    for(int i=0;i<k && k<=n;i++){
        if(!mp[v[i]]){
            dq.push_front(v[i]);
            mp[v[i]]=1;
        }
    }

    for(int i=k;i<n;i++){
        if(!mp[v[i]]){
            mp[v[i]]=1;
            dq.push_front(v[i]);
            if(dq.size()>k){
                mp[dq.back()]=0;
                dq.pop_back();
            }
        }
    }
    cout<<dq.size()<<"\n";
    for(int i:dq){
        cout<<i<<" ";
    }
}


#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    unordered_map<int,int> mp;
    int n,k;cin>>n>>k;
    vi v(n);cin>>v;
    deque<int> dq;
    for(int i=0;i<k;i++){
        if(!mp[v[i]])dq.push_front(v[i]);
        mp[v[i]]=1;
    }
    for(int i=k;i<n;i++){
        if(!mp[v[i]]){
            mp[v[i]]=1;
            dq.push_front(v[i]);
            mp[dq.back()]=0;
            dq.pop_back();
        }
    }
    for(int i:dq){
        cout<<i<<" ";
    }
}


#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    map<int,bool> mp;
    int n,k;cin>>n>>k;
    vi v(n);cin>>v;
    deque<int> dq;

    for(int i:v)mp[i]=0;

    for(int i=0;i<k;i++){
        if(!mp[v[i]]){
            dq.push_front(v[i]);
            mp[v[i]]=1;
        }
    }

    for(int i=k;i<n;i++){
        if(!mp[v[i]]){
            mp[v[i]]=1;
            dq.push_front(v[i]);
            if(dq.size()>k){
                mp[dq.back()]=0;
                dq.pop_back();
            }
        }
    }
    cout<<dq.size()<<"\n";
    for(int i:dq){
        cout<<i<<" ";
    }
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    unordered_map<int,int> m;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a])
        {}
        else
        {
            if(q.size() == k)
            {
                int l =q.front();
                m[l] = 0;
                q.pop_front();
            }
            q.push_back(a);
            m[a]=1;
        }

    }
    cout<<q.size()<<"\n";
    while(!q.empty())
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }

    return 0;
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    unordered_map<int,int> m;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a])
            continue;
        if(q.size() == k)
        {
            int l =q.front();
            m[l] = 0;
            q.pop_front();
        }
        q.push_back(a);
        m[a]=1;
    }
    cout<<q.size()<<"\n";
    while(!q.empty())
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }

    return 0;
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    unordered_map<int,int> m;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a])
            continue;
        if(q.size() == k)
        {
            m[q.front()] = 0;
            q.pop_front();
        }
        q.push_back(a);
        m[a]=1;
    }
    cout<<q.size()<<"\n";
    while(!q.empty())
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }

    return 0;
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    unordered_map<int,int> m;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a])
            continue;
        if(q.size() == k)
        {
            m[q.back()]--;
            q.pop_back();
        }
        q.push_front(a);
        m[a]++;
    }
    cout<<q.size()<<"\n";
    while(!q.empty())
    {
        cout<<q.front()<<" ";
        q.pop_front();
    }

    return 0;
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
map<int,int> m;
int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a]==1)
        {}
        else
        {
            if((int)q.size() == k)
            {
                int l =q.front();
                m[l] = 0;
                q.pop_front();
            }
            q.push_back(a);
            m[a]=1;
        }

    }
    cout<<q.size()<<"\n";
    while(q.size()>0)
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
unordered_map<int,int> m;
int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a]==1)
        {}
        else
        {
            if((int)q.size() == k)
            {
                int l =q.front();
                m[l] = 0;
                q.pop_front();
            }
            q.push_back(a);
            m[a]=1;
        }

    }
    cout<<q.size()<<"\n";
    while(q.size()>0)
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
unordered_map<int,int> m;
int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a]==1)
        {}
        else
        {
            if((int)q.size() == k)
            {
                int l =q.front();
                m[l] = 0;
                q.pop_front();
            }
            q.push_back(a);
            m[a]=1;
        }

    }
    cout<<q.size()<<"\n";
    while(q.size()>0)
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }

    return 0;
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
unordered_map<int,int> m;
int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a])
        {}
        else
        {
            if(q.size() == k)
            {
                int l =q.front();
                m[l] = 0;
                q.pop_front();
            }
            q.push_back(a);
            m[a]=1;
        }

    }
    cout<<q.size()<<"\n";
    while(q.size()>0)
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }

    return 0;
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    unordered_map<int,int> m;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a])
            continue;
        if(q.size() == k)
        {
            m[q.front()]--;
            q.pop_front();
        }
        q.push_back(a);
        m[a]++;
    }
    cout<<q.size()<<"\n";
    while(!q.empty())
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }

    return 0;
}


//PRINCE
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define ll long long int
typedef vector<ll> vll;
typedef vector<int> vii;

#define MOD 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll power(ll x,ll n){if(n==0)return 1;if(n%2)return x*power(x*x,(n-1)/2);return power(x*x,n/2);}
ll powerm(ll x,ll n){if(n==0)return 1;if(n%2)return (x*powerm((x*x)%MOD,(n-1)/2))%MOD;return powerm((x*x)%MOD,n/2);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int32_t main()
{

    //kiimati 4 line for sublime text
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);//FAST
    int n,k;cin>>n>>k;
    unordered_map<int,int> m;
    int a;
    deque<int> q;
    rep(i,0,n)
    {
        cin>>a;

        if(m[a])
        {}
        else
        {
            if(q.size() == k)
            {
                int l =q.front();
                m[l] = 0;
                q.pop_front();
            }
            q.push_back(a);
            m[a]=1;
        }

    }
    cout<<q.size()<<"\n";
    while(q.size()>0)
    {
        cout<<q.back()<<" ";
        q.pop_back();
    }

    return 0;
}


/*input
7 2
1 2 3 2 1 3 2

*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;

		cin>>n>>m;
		ll a[n];
		for(ll i=0;i < n;i++)
			cin>>a[i];

		set <ll > s;
		queue < ll > q;
		for (int i = 0; i < n; ++i)
		{
			if(s.count(a[i])==0)
			{
				s.insert(a[i]);
				if(q.size()<m)
				{
					q.push(a[i]);
				}
				else
				{
					tmp = q.front();
					s.erase(tmp);
					q.pop();
					q.push(a[i]);
				}
			}

		}
		cout << q.size() << endl;
		string res="";
		while(!q.empty())
		{
			tmp = q.front();
			q.pop();
			res = to_string(tmp) + " " + res;
		}
		// watch(tmp);
		cout << res << endl;
	}
	return 0;
}


/*input
10 4
2 3 3 1 1 2 1 2 3 3

*/
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

struct custom_hash {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return x + FIXED_RANDOM;
    }
};

int main()
{
	int n,k;
	cin >> n >> k;
	ll a[n];
	for (ll i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	queue < int > q;
	unordered_map <int , int, custom_hash> um;
	for (ll i = 0; i < n; ++i)
	{
		if (um.count(a[i])==0)
		{
			um[a[i]]=1;
			q.push(a[i]);
			if (q.size()>k)
			{
				um.erase(q.front());
			 q.pop();
			}

		}
	}
	cout << q.size() << endl;
	int x= q.size();
	stack <int > s;
	for (ll i = 0; i < x; ++i)
	{
		// cout << "yolo" << endl;
		// cout << q.front() << " ";
		s.push(q.front());
		q.pop();
	}
	x= s.size();
	for (ll i = 0; i < x; ++i)
	{
		cout <<s.top() << " ";
		s.pop();
	}
	cout << endl;
}


/*input
10 4
2 3 3 1 1 2 1 2 3 3

*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;

		cin>>n>>m;
		ll a[n];
		for(ll i=0;i < n;i++)
			cin>>a[i];

		set <ll > s;
		queue < ll > q;
		for (int i = 0; i < n; ++i)
		{
			if(s.count(a[i])==0)
			{
				s.insert(a[i]);
				if(q.size()<m)
				{
					q.push(a[i]);
				}
				else
				{
					tmp = q.front();
					s.erase(tmp);
					q.pop();
					q.push(a[i]);
				}
			}

		}
		cout << q.size() << endl;
		vll v;
		while(!q.empty())
		{
			v.eb(q.front());
			q.pop();
		}
		reverse(all(v));
		for (int i = 0; i < v.size(); ++i)
		{
			cout << v[i] << " ";
		}cout << endl;
	}
	return 0;
}


/*input
10 4
2 3 3 1 1 2 1 2 3 3

*/
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
	int n,k;
	cin >> n >> k;
	ll a[n];
	for (ll i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	queue < int > q;
	unordered_map <int , int, custom_hash> um;
	for (ll i = 0; i < n; ++i)
	{
		if (um.count(a[i])==0)
		{
			um[a[i]]=1;
			q.push(a[i]);
			if (q.size()>k)
			{
				um.erase(q.front());
			 q.pop();
			}

		}
	}
	cout << q.size() << endl;
	int x= q.size();
	stack <int > s;
	for (ll i = 0; i < x; ++i)
	{
		// cout << "yolo" << endl;
		// cout << q.front() << " ";
		s.push(q.front());
		q.pop();
	}
	x= s.size();
	for (ll i = 0; i < x; ++i)
	{
		cout <<s.top() << " ";
		s.pop();
	}
	cout << endl;
}


/*input
7 2
1 2 3 2 1 3 2

*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;

		cin>>n>>m;
		ll a[n];
		for(ll i=0;i < n;i++)
			cin>>a[i];

		// unordered_set <ll > s;
		ll arr[N*2] = { 0 };
		deque < ll > q;
		for (int i = 0; i < n; ++i)
		{
			if(arr[a[i]]==0)
			{
				arr[a[i]]=1;
				if(q.size()<m)
				{
					q.push_back(a[i]);
				}
				else
				{
					tmp = q.front();
					// s.erase(tmp);
					arr[tmp] = 0;
					q.pop_front();
					q.push_back(a[i]);
				}
			}

		}
		cout << q.size() << endl;
		// string res="";
		// while(!q.empty())
		// {
		// 	tmp = q.front();
		// 	q.pop();
		// 	res = to_string(tmp) + " " + res;
		// }
		// // watch(tmp);
		// cout << res << endl;
		while(!q.empty())
		{
			cout << q.back() << " ";
			q.pop_back();
		}cout << endl;

	}
	return 0;
}


/*input
10 4
2 3 3 1 1 2 1 2 3 3

*/
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;
	ll a[n];
	for (ll i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	queue < int > q;
	unordered_map <int , int> um;
	for (ll i = 0; i < n; ++i)
	{
		if (um.count(a[i])==0)
		{
			um[a[i]]=1;
			q.push(a[i]);
			if (q.size()>k)
			{
				um.erase(q.front());
			 q.pop();
			}

		}
	}
	cout << q.size() << endl;
	int x= q.size();
	stack <int > s;
	for (ll i = 0; i < x; ++i)
	{
		// cout << "yolo" << endl;
		// cout << q.front() << " ";
		s.push(q.front());
		q.pop();
	}
	x= s.size();
	for (ll i = 0; i < x; ++i)
	{
		cout <<s.top() << " ";
		s.pop();
	}
	cout << endl;
}


/*input
10 4
2 3 3 1 1 2 1 2 3 3

*/
#include <bits/stdc++.h>
#define ll long long int

using namespace std;
using namespace std::chrono;
int main()
{
	int n,k;
	cin >> n >> k;
	ll a[n];
	for (ll i = 0; i < n; ++i)
	{
		cin >> a[i];
	}

	queue < int > q;
	// unordered_map <int , int> um;
	int um[200005]= { 0 };
	// auto start = high_resolution_clock::now();
	for (ll i = 0; i < n; ++i)
	{
		if (um[a[i]]==0)
		{
			um[a[i]]=1;
			q.push(a[i]);
			if (q.size()>k)
			{
				um[q.front()]=0;
			 q.pop();
			}

		}
	}
// 	auto stop = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop - start);

    // cout << "Time taken by part1: "
    //      << duration.count() << " microseconds" << endl;
	cout << q.size() << endl;

	// start = high_resolution_clock::now();

	int x= q.size();
	stack <int > s;
	for (ll i = 0; i < x; ++i)
	{
		// cout << "yolo" << endl;
		// cout << q.front() << " ";
		s.push(q.front());
		q.pop();
	}
	x= s.size();
	// stop = high_resolution_clock::now();
	// duration = duration_cast<microseconds>(stop - start);

    // cout << "Time taken by part2: "
    //      << duration.count() << " microseconds" << endl;

    // start = high_resolution_clock::now();
	for (ll i = 0; i < x; ++i)
	{
		cout <<s.top() << " ";
		s.pop();
	}
	cout << endl;

	// stop = high_resolution_clock::now();
	// duration = duration_cast<microseconds>(stop - start);

 //    cout << "Time taken by part2: "
 //         << duration.count() << " microseconds" << endl;
}


/*input
7 2
1 2 3 2 1 3 2

*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;

		cin>>n>>m;
		ll a[n];
		for(ll i=0;i < n;i++)
			cin>>a[i];

		unordered_set <ll > s;
		deque < ll > q;
		for (int i = 0; i < n; ++i)
		{
			if(s.count(a[i])==0)
			{
				s.insert(a[i]);
				if(q.size()<m)
				{
					q.push_back(a[i]);
				}
				else
				{
					tmp = q.front();
					s.erase(tmp);
					q.pop_front();
					q.push_back(a[i]);
				}
			}

		}
		cout << q.size() << endl;
		// string res="";
		// while(!q.empty())
		// {
		// 	tmp = q.front();
		// 	q.pop();
		// 	res = to_string(tmp) + " " + res;
		// }
		// // watch(tmp);
		// cout << res << endl;
		while(!q.empty())
		{
			cout << q.back() << " ";
			q.pop_back();
		}cout << endl;

	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cstdio>
using namespace std;
unordered_map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	int n, m;
	cin >> n >> m;
	int num;
	queue<int> que;
	while(n--){
		scanf("%d", &num);
		if(M[num]){
			continue;
		}
		M[num] = true;
		que.push(num);
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	int Sz = que.size();
	printf("%d\n", Sz);
	stack<int> sta;
	while(!que.empty()){
		num = que.front();
		que.pop();
		sta.push(num);
	}
	while(!sta.empty()){
		num = sta.top();
		sta.pop();
		printf("%d ", num);
	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cstdio>
using namespace std;
unordered_map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	int n, m;
	cin >> n >> m;
	int num;
	queue<int> que;
	while(n--){
		scanf("%d", &num);
		cin >> num;
		if(M[num]){
			continue;
		}
		M[num] = true;
		que.push(num);
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	int Sz = que.size();
	printf("%d\n", Sz);
	stack<int> sta;
	while(!que.empty()){
		num = que.front();
		que.pop();
		sta.push(num);
	}
	while(!sta.empty()){
		num = sta.top();
		sta.pop();
		printf("%d ", num);
	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
using namespace std;
unordered_map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	int num;
	int A[n + 20];
	for(int i = 0; i < n; ++i) scanf("%d", &A[i]);
	queue<int> que;
	for(int i = 0; i < n; ++i){
		num = A[i];
		if(M[num]){
			continue;
		}
		M[num] = true;
		que.push(num);
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	int Sz = que.size();
	printf("%d\n", Sz);
	stack<int> sta;
	vector<int> ans;
	while(!que.empty()){
		num = que.front();
		que.pop();
		ans.push_back(num);
	}
	for(int i = ans.size() - 1; i >= 0; --i){
		printf("%d ", ans[i]);
	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;
unordered_map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	int num;
	int A[n + 20];
	for(int i = 0; i < n; ++i) scanf("%d", &A[i]);
	queue<int> que;
	for(int i = 0; i < n; ++i){
		num = A[i];
		if(que.size() < m){
			que.push(num);
			M[num] = true;
		}else{
			if(M[num]) continue;
			que.push(num);
			M[num] = true;
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	int Sz = que.size();
	printf("%d\n", Sz);
	vector<int> ans;
	while(!que.empty()){
		num = que.front();
		que.pop();
		ans.push_back(num);
	}
	for(int i = ans.size() - 1; i >= 0; --i){
		printf("%d ", ans[i]);
	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <stack>
using namespace std;
using LL = long long;
unordered_map<LL, int> M;
int main(){
	//freopen("test", "r", stdin);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	LL num;
	queue<LL> que;
	while(n--){
		cin >> num;
		if(M[num]){
			continue;
		}
		M[num]++;
		que.push(num);
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num]--;
		}
	}
	cout << que.size() << '\n';
	stack<LL> sta;
	while(!que.empty()){
		num = que.front();
		que.pop();
		sta.push(num);
	}
	while(!sta.empty()){
		num = sta.top();
		sta.pop();
		cout << num << " ";
	}
	return 0;
}


#include <iostream>
#include <map>
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;
map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	int num;
	int A[n + 20];
	for(int i = 0; i < n; ++i) scanf("%d", &A[i]);
	queue<int> que;
	for(int i = 0; i < n; ++i){
		num = A[i];
		if(M[num]) continue;
		que.push(num);
		M[num] = true;
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	int Sz = que.size();
	printf("%d\n", Sz);
	vector<int> ans;
	while(!que.empty()){
		num = que.front();
		que.pop();
		ans.push_back(num);
	}
	for(int i = ans.size() - 1; i >= 0; --i){
		printf("%d ", ans[i]);
	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;
unordered_map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	int num;
	int A[n + 20];
	for(int i = 0; i < n; ++i) scanf("%d", &A[i]);
	queue<int> que;
	for(int i = 0; i < n; ++i){
		num = A[i];
		if(M[num]) continue;
		que.push(num);
		M[num] = true;
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	int Sz = que.size();
	printf("%d\n", Sz);
	vector<int> ans;
	while(!que.empty()){
		num = que.front();
		que.pop();
		ans.push_back(num);
	}
	for(int i = ans.size() - 1; i >= 0; --i){
		printf("%d ", ans[i]);
	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cstdio>
using namespace std;
unordered_map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	int num;
	int A[n + 20];
	for(int i = 0; i < n; ++i) scanf("%d", &A[i]);
	queue<int> que;
	for(int i = 0; i < n; ++i){
		num = A[i];
		if(M[num]){
			continue;
		}
		M[num] = true;
		que.push(num);
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	int Sz = que.size();
	printf("%d\n", Sz);
	stack<int> sta;
	while(!que.empty()){
		num = que.front();
		que.pop();
		sta.push(num);
	}
	while(!sta.empty()){
		num = sta.top();
		sta.pop();
		printf("%d ", num);
	}
	return 0;
}


#include <iostream>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cstdio>
using namespace std;
unordered_map<int, bool> M;
int main(){
	//freopen("test", "r", stdin);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int num;
	queue<int> que;
	while(n--){
		scanf("%d", &num);
		cin >> num;
		if(M[num]){
			continue;
		}
		M[num] = true;
		que.push(num);
		if(que.size() > m){
			num = que.front();
			que.pop();
			M[num] = false;
		}
	}
	cout << que.size() << '\n';
	stack<int> sta;
	while(!que.empty()){
		num = que.front();
		que.pop();
		sta.push(num);
	}
	while(!sta.empty()){
		num = sta.top();
		sta.pop();
		printf("%d ", num);
	}
	return 0;
}


#include<bits/stdc++.h>
#include<stdlib.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    int n,k ;
    scanf("%d",&n) ;scanf("%d",&k) ;
    int a[n] ; unordered_map<int,int> m ;queue<int> q ;
    f(i,0,n) scanf("%d",&a[i]) ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     int r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    ll v[n+1],h=0 ;
    while(q.size()){
        v[h]=q.front() ; h++ ; q.pop() ;
    }
    printf("%d\n",h) ;
    for(int i=h-1;i>=0;i--)
   printf("%d ",v[i]) ;

}


#include<bits/stdc++.h>
#include<stdlib.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    int n,k ;
    scanf("%d",&n) ;scanf("%d",&k) ;
    int a[n+1] ; unordered_map<int,int> m ;queue<int> q ;
    f(i,0,n) scanf("%d",&a[i]) ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     int r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    int v[n+1],h=0 ;
    while(!q.empty()){
        v[h]=q.front() ; h++ ; q.pop() ;
    }
    printf("%d\n",h) ;
    for(int i=h-1;i>=0;i--)
   printf("%d ",v[i]) ;

}


#include<bits/stdc++.h>
#include<stdlib.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n,k ;
    scanf("%lld",&n) ;scanf("%lld",&k) ;
    ll a[n+1] ; unordered_map<ll,ll> m ;queue<ll> q ;
    f(i,0,n) scanf("%lld",&a[i]) ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     ll r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    ll v[n+1],h=0 ;
    while(!q.empty()){
        v[h]=q.front() ; h++ ; q.pop() ;
    }
    printf("%lld\n",h) ;
    for(int i=h-1;i>=0;i--)
   printf("%lld ",v[i]) ;

}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ll n,k ;
    cin>>n>>k ;
    ll a[n+1] ; unordered_map<ll,ll> m ;queue<ll> q ;
    f(i,0,n) cin>>a[i] ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     ll r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    ll v[n+1],h=0 ;
    while(!q.empty()){
        v[h]=q.front() ; h++ ; q.pop() ;
    }
    cout<<h<<"\n" ;
    for(int i=h-1;i>=0;i--)
    cout<<v[i]<<" " ;

}


#include<bits/stdc++.h>
#include<stdlib.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    int n,k ;
    scanf("%d",&n) ;scanf("%d",&k) ;
    int a[n] ; map<int,int> m ;queue<int> q ;
    f(i,0,n) scanf("%d",&a[i]) ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     int r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    ll v[n+1],h=0 ;
    while(q.size()){
        v[h]=q.front() ; h++ ; q.pop() ;
    }
    printf("%d\n",h) ;
    for(int i=h-1;i>=0;i--)
   printf("%d ",v[i]) ;

}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ll n,k ;
    cin>>n>>k ;
    ll a[n+1] ; map<ll,ll> m ;queue<ll> q ;
    f(i,0,n) cin>>a[i] ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     ll r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    vector<ll> v ;
    while(!q.empty()){
        v.pb(q.front()) ; q.pop() ;
    }
    cout<<v.size()<<"\n" ;
    for(int i=v.size()-1;i>=0;i--)
    cout<<v[i]<<" " ;

}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n,k ;
    cin>>n>>k ;
    ll a[n+1] ; unordered_map<ll,ll> m ;queue<ll> q ;
    f(i,0,n) cin>>a[i] ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     ll r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    ll v[n+1],h=0 ;
    while(!q.empty()){
        v[h]=q.front() ; h++ ; q.pop() ;
    }
    cout<<h<<"\n" ;
    for(int i=h-1;i>=0;i--)
    cout<<v[i]<<" " ;

}


#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{
    ll n,k,c=0,p ;
    cin>>n>>k ;
    queue<ll> q ;
    unordered_set<ll>s ;
    vector<ll> v ;
    for(int i=0;i<n;i++){
        cin>>p ;
        if(s.count(p)>0)
            continue ;
        else{
        if(q.size()==k){
            s.erase(q.front()) ;
            q.pop() ;
        }
        q.push(p) ;s.insert(p) ;
    }

    }
    while(!q.empty()){
        v.pb(q.front()) ;
        q.pop() ;
    }
    ll r=v.size() ;
    cout<<r<<"\n" ;
    for(int i=r-1;i>=0;i--)
        cout<<v[i]<<" " ;
}


#include<bits/stdc++.h>
#include<stdlib.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    int n,k ;
    scanf("%d",&n) ;scanf("%d",&k) ;
    int a[n] ; unordered_map<int,int> m ;queue<int> q ;
    f(i,0,n) scanf("%d",&a[i]) ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     ll r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    ll v[n+1],h=0 ;
    while(!q.empty()){
        v[h]=q.front() ; h++ ; q.pop() ;
    }
    printf("%d\n",h) ;
    for(int i=h-1;i>=0;i--)
   printf("%d ",v[i]) ;

}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std ;
#define fi first
#define se second
#define ll long long
#include <sstream>  // for string streams
#include <string>
#define mod 1000000007
#define f(i,p,n) for(int i=p;i<n;i++)
/*ll power(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res%mod * a%mod)%mod;
		a=(a%mod *a%mod)%mod;
		b=b>>1;
	}
	return res;
}*/
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.fi!=b.fi)
    return a.fi<b.fi ;
    else
    return (a.second < b.second);
}

int main()
{
    ll n,k ;
    cin>>n>>k ;
    ll a[n+1] ; unordered_map<ll,ll> m ;queue<ll> q ;
    f(i,0,n) cin>>a[i] ;
    for(int i=0;i<n;i++){
        if(m[a[i]]==0){
            //cout<<a[i]<<" " ;
            if(q.size()==k){
     ll r=q.front() ; m[r]-- ; q.pop() ;

         }
            q.push(a[i]) ;m[a[i]]++ ;

         }
    }
    vector<ll> v ;
    while(!q.empty()){
        v.pb(q.front()) ; q.pop() ;
    }
    cout<<v.size()<<"\n" ;
    for(int i=v.size()-1;i>=0;i--)
    cout<<v[i]<<" " ;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
    vector <int> v;
    set <int> h;
    int a,b;
    int num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.push_back(num);
            h.insert(num);
            if(v.size()>=b)
            {h.erase(v[0]); v.erase(v.begin(),v.end()-b);}
        }
    }
        cout<<v.size()<<"\n";
        for(int i=v.size()-1;i>=0;i--)
            cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <long long> v;
    set <long long> h;
    int a,b;
    long long num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.push_back(num);
            h.insert(num);
            h.erase(v[b]);
        }
    }
    if(v.size()>b)
    {
        cout<<b<<"\n";
        for(int i=b-1;i>=0;i--)
        {
            cout<<v[i]<<" ";
        }
    }
    else
    {
        cout<<v.size()<<"\n";
        for(int i=v.size()-1;i>=0;i--)
            cout<<v[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <long long> v;
    set <long long> h;
    int a,b;
    long long num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.insert(v.begin(),num);
            h.insert(num);
            if(v.size()>=b)
            h.erase(v[b]);
        }
    }
    if(v.size()>b)
    {
        cout<<b<<"\n";
        for(int i=0;i<b;i++)
        {
            cout<<v[i]<<" ";
        }
    }
    else
    {
        cout<<v.size()<<"\n";
        for(int i=0;i<v.size();i++)
            cout<<v[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <long long> v;
    set <long long> h;
    int a,b;
    long long num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.insert(v.begin(),num);
            h.insert(num);
            if(v.size()>=b)
            {h.erase(v[b]); v.erase(v.begin()+b,v.end());}
        }
    }
    if(v.size()>b)
    {
        cout<<b<<"\n";
        for(int i=0;i<b;i++)
        {
            cout<<v[i]<<" ";
        }
    }
    else
    {
        cout<<v.size()<<"\n";
        for(int i=0;i<v.size();i++)
            cout<<v[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
    vector <int> v;
    set <int> h;
    int a,b;
    int num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.push_back(num);
            h.insert(num);
            if(v.size()>=b)
            {h.erase(v[0]); v.erase(v.begin());}
        }
    }
        cout<<v.size()<<"\n";
        for(int i=v.size()-1;i>=0;i--)
            cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <long long> v;
    set <long long> h;
    int a,b;
    long long num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.push_back(num);
            h.insert(num);
            if(v.size()>=b)
            h.erase(v[b]);
        }
    }
    if(v.size()>b)
    {
        cout<<b<<"\n";
        for(int i=b-1;i>=0;i--)
        {
            cout<<v[i]<<" ";
        }
    }
    else
    {
        cout<<v.size()<<"\n";
        for(int i=v.size()-1;i>=0;i--)
            cout<<v[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <long long> v;
    set <long long> h;
    int a,b;
    long long num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.push_back(num);
            h.insert(num);
            if(v.size()>b)
            h.erase(v[b]);
        }
    }
    if(v.size()>b)
    {
        cout<<b<<"\n";
        for(int i=b-1;i>=0;i--)
        {
            cout<<v[i]<<" ";
        }
    }
    else
    {
        cout<<v.size()<<"\n";
        for(int i=v.size()-1;i>=0;i--)
            cout<<v[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
    vector <long long> v;
    set <long long> h;
    int a,b;
    long long num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.push_back(num);
            h.insert(num);
            if(v.size()>=b)
            {h.erase(v[0]); v.erase(v.begin(),v.end()-b);}
        }
    }
        cout<<v.size()<<"\n";
        for(int i=v.size()-1;i>=0;i--)
            cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
    vector <int> v;
    set <int> h;
    int a,b;
    int num;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        if(h.count(num)==1)
            continue;
        else
        {
            v.push_back(num);
            h.insert(num);
            if(v.size()>b)
            {h.erase(v[0]); v.erase(v.begin());}
        }
    }
        cout<<v.size()<<"\n";
        for(int i=v.size()-1;i>=0;i--)
            cout<<v[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector <long long> h;
int main()
{
    int a,b,r,num,c=0,bruh=0;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num;
        bruh=0;
        if(h.size()<b)
            r=h.size();
        else
            r=b;
        for(int j=0;j<r;j++)
        {
            if(num==h[j])
            {bruh++; break;}
        }
        if(bruh==0)
        {
            h.insert(h.begin(),num);
        }
        if(h.size()<b)
            r=h.size();
        else
            r=b;
    }
    for(int i=0;i<r;i++)
    {
            c++;
    }
    cout<<c<<"\n";
    for(int i=0;i<c;i++)
    {
        cout<<h[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	unordered_map<ll,ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(!mp.count(a))
    		{
    			// cout<<a<<"  "<<q.size();
    			if(q.size()<k)
    			{
    				q.push(a);
    			}
    			else
    			{
    				mp.erase(q.front());
    				q.pop();
    				q.push(a);
    			}
    			mp[a]++;
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	unordered_map<ll,ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(mp.count(a))
    		{
    			// cout<<a<<"  "<<q.size();
    			if(q.size()>=k)
    			{
    				mp.erase(q.front());
    				q.pop();
    			}
    			q.push(a);
    			mp[a]++;
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	map<ll,ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(!mp.count(a))
    		{
    			if(q.size()>=k)
    			{
    				mp.erase(q.front());
    				q.pop();
    			}
    			q.push(a);
    			mp.[a]++;
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	set<ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(!mp.count(a))
    		{
    			if(q.size()>=k)
    			{
    				mp.erase(q.front());
    				q.pop();
    			}
    			q.push(a);
    			mp.insert(a);
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	unordered_set<ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(mp.count(a)==0)
    		{
    			// cout<<a<<"  "<<q.size();
    			if(q.size()<k)
    			{
    				q.push(a);
    			}
    			else
    			{
    				mp.erase(q.front());
    				q.pop();
    				q.push(a);
    			}
    			mp.insert(a);
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	unordered_set<ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(mp.find(a)==mp.end())
    		{
    			// cout<<a<<"  "<<q.size();
    			if(q.size()<k)
    			{
    				q.push(a);
    			}
    			else
    			{
    				auto it=mp.find(q.front());
    				mp.erase(it);
    				q.pop();
    				q.push(a);
    			}
    			mp.insert(a);
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	unordered_set<ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(mp.find(a)!=mp.end())
    		{
    			// cout<<a<<"  "<<q.size();
    			if(q.size()<k)
    			{
    				q.push(a);
    			}
    			else
    			{
    				auto it=mp.find(q.front());
    				mp.erase(it);
    				q.pop();
    				q.push(a);
    			}
    			mp.insert(a);
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	unordered_set<ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(!mp.count(a))
    		{
    			if(q.size()>=k)
    			{
    				mp.erase(q.front());
    				q.pop();
    			}
    			q.push(a);
    			mp.insert(a);
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int n, k;
	cin >> n >> k;

	queue<int> q;
	set<int> vals;
	for (int i = 0; i < n; ++i) {
		int id;
		cin >> id;
		if (!vals.count(id)) {
			if (int(q.size()) >= k) {
				int cur = q.front();
				q.pop();
				vals.erase(cur);
			}
			vals.insert(id);
			q.push(id);
		}
	}

	vector<int> res;
	while (!q.empty()) {
		res.push_back(q.front());
		q.pop();
	}
	reverse(res.begin(), res.end());
	cout << res.size() << endl;
	for (auto it : res) cout << it << " ";
	cout << endl;

	return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	map<ll,ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(!mp.count(a))
    		{
    			if(q.size()>=k)
    			{
    				mp.erase(q.front());
    				q.pop();
    			}
    			q.push(a);
    			mp[a]++;
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


// #include <iostream>
// #include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,k;
    	cin>>n>>k;
    	queue<ll>q;
    	unordered_map<ll,ll>mp;
    	for(ll i=0;i<n;i++)
    	{
    		ll a;
    		cin>>a;
    		if(mp[a]==0)
    		{
    			// cout<<a<<"  "<<q.size();
    			if(q.size()<k)
    			{
    				q.push(a);
    			}
    			else
    			{
    				mp[q.front()]--;
    				q.pop();
    				q.push(a);
    			}
    			mp[a]++;
    		}

    	}
    	vector<ll>v;
    	while(!q.empty())
    	{
    		v.push_back(q.front());
    		q.pop();
    	}
    	cout<<v.size()<<endl;
    	for(ll i=v.size()-1;i>=0;i--)
    		cout<<v[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;
vector <int> v;

    f0(i,n){

      int x;
      cin>>x;

      if( m[x]!=0 && m.find(x)!=m.end()){

        continue;
      }

      if(v.size()<k){
        m[x]++;
        v.push_back(x);

        continue;
      }

      if(v.size()==k) {
          m[v[0]]=0;

        if(v.size()) v.erase(v.begin());

      }
      m[x]++;
        v.push_back(x);

    }

    cout<<v.size()<<endl;

    reverse(v.begin(),v.end());

    f0(j,v.size())
    cout<<v[j]<<" ";

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <ll,ll> m;
vector <ll> v;

    f0(i,n){

      ll x;
      cin>>x;

      if( m[x]!=0 && m.find(x)!=m.end()){

        continue;
      }

      if(v.size()<k){
        m[x]++;
        v.push_back(x);

        continue;
      }

      if(v.size()==k) {
          m[v[0]]=0;

        if(v.size()) v.erase(v.begin());

      }
      m[x]++;
        v.push_back(x);

    }

    cout<<v.size()<<endl;

    reverse(v.begin(),v.end());

    f0(j,v.size())
    cout<<v[j]<<" ";

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;
vector <int> v;
int sz=0;

    f0(i,n){

      int x;
      cin>>x;

      if( m[x]!=0 ){

        continue;
      }

      if(v.size()<k){
        m[x]++;
        v.push_back(x);
        sz++;
        continue;
      }

      if(v.size()==k) {
          m[v[0]]=0;

        if(v.size()) v.erase(v.begin(),v.begin()+1);

      }
      m[x]++;
        v.push_back(x);

    }

    cout<<v.size()<<endl;

    reverse(v.begin(),v.end());

    f0(j,v.size())
    cout<<v[j]<<" ";

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    ll int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;

queue <int> v;
int sz=0;

    f0(i,n){

      int x;
      cin>>x;

      if( m[x]!=0 && m.find(x)!=m.end()){
          continue;
      }else if(sz<k){
        sz++;
        m[x]++;
        v.push(x);

        continue;
      }else if(sz==k) {
        int a=v.front();
          m[a]=0;
         v.pop();

           m[x]++;
           v.push(x);
      }

    }

    cout<<v.size()<<endl;

stack <int> s;

while(!v.empty()){
  s.push(v.front());
  v.pop();
}

while(!s.empty()){
  cout<<s.top()<<" ";
  s.pop();
}

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;
vector <int> v;

int l=0;

    f0(i,n){

      int x;
      cin>>x;

      if( m.find(x) != m.end() ){

        continue;
      }

      if(m.size()<k){
        m[x]++;
        v.push_back(x);
        continue;
      }

      if(m.size()==k) {m.erase(v[l]);
           l++;
      }
      m[x]++;

    }

//  v.erase(v.begin(),v.begin()+l);
    cout<<v.size()<<endl;

    reverse(v.begin(),v.end());

    f0(j,v.size())
    cout<<v[j]<<" ";

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;
vector <int> v;

    f0(i,n){

      int x;
      cin>>x;

      if( m.find(x) != m.end() ){

        continue;
      }

      if(m.size()<k){
        m[x]++;
        v.push_back(x);
        continue;
      }

      if(m.size()==k) {m.erase(v[0]);

        if(v.size()) v.erase(v.begin());

      }
      m[x]++;
        v.push_back(x);

    }

    cout<<v.size()<<endl;

    reverse(v.begin(),v.end());

    f0(j,v.size())
    cout<<v[j]<<" ";

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    ll int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;

queue <int> v;
int sz=0;

    f0(i,n){

      int x;
      cin>>x;

      if( m[x]!=0){
          continue;
      }else if(sz<k){
        sz++;
        m[x]++;
        v.push(x);

        continue;
      }else if(sz==k) {
        int a=v.front();
          m[a]=0;
         v.pop();

           m[x]++;
           v.push(x);
      }

    }

    cout<<v.size()<<endl;
int l=v.size();
int p=l;
stack <int> s;

while(p--){
  s.push(v.front());
  v.pop();
}

while(l--){
  cout<<s.top()<<" ";
  s.pop();
}

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;
vector <int> v;
int sz=0;

    f0(i,n){

      int x;
      cin>>x;

      if( m[x]!=0 ){

        continue;
      }

      if(v.size()<k){
        m[x]++;
        v.push_back(x);
        sz++;
        continue;
      }

      if(v.size()==k) {
          m[v[0]]=0;

        if(v.size()) v.erase(v.begin());

      }
      m[x]++;
        v.push_back(x);

    }

    cout<<v.size()<<endl;

    reverse(v.begin(),v.end());

    f0(j,v.size())
    cout<<v[j]<<" ";

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;
queue <int> v;

    f0(i,n){

      int x;
      cin>>x;

      if( m[x]!=0 && m.find(x)!=m.end()){

        continue;
      }

      if(v.size()<k){
        m[x]++;
        v.push(x);

        continue;
      }

      if(v.size()==k) {
        int a=v.front();
          m[a]=0;

        if(v.size()) v.pop();

      }
      m[x]++;
        v.push(x);

    }

    cout<<v.size()<<endl;

stack <int> s;

while(!v.empty()){
  s.push(v.front());
  v.pop();
}

while(!s.empty()){
  cout<<s.top()<<" ";
  s.pop();
}

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    ll int n,k;
    cin>>n>>k;

  map <int,int> m;

queue <int> v;
int sz=0;

    f0(i,n){

      int x;
      cin>>x;

      if( m.find(x)!=m.end()){
          continue;
      }else if(sz<k){
        sz++;
        m[x]++;
        v.push(x);

      }else if(sz==k) {
        int a=v.front();
          m.erase(a);
         v.pop();

           m[x]++;
           v.push(x);
      }

    }

    cout<<v.size()<<endl;
int l=v.size();
int p=l;
stack <int> s;

while(p--){
  s.push(v.front());
  v.pop();
}

while(l--){
  cout<<s.top()<<" ";
  s.pop();
}

    }


#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
#define nl <<"/n"                  // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    unordered_map <int,int> m;
vector <int> v;

    f0(i,n){

      int x;
      cin>>x;

      if( m[x]!=0 ){

        continue;
      }

      if(m.size()<k){
        m[x]++;
        v.push_back(x);
        continue;
      }

      if(m.size()==k) {
          m[v[0]]=0;

        if(v.size()) v.erase(v.begin());

      }
      m[x]++;
        v.push_back(x);

    }

    cout<<v.size()<<endl;

    reverse(v.begin(),v.end());

    f0(j,v.size())
    cout<<v[j]<<" ";

    }


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll          long long
#define ld          long double
#define fi          first
#define se          second
#define pb          push_back
#define mp          make_pair
#define all(c)      (c).begin(), (c).end()

using namespace std;
using namespace __gnu_pbds;

typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void solve() {
    ll n, k, x;
    cin >> n >> k;
    deque <ll> d;
    map <ll, bool> mp;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        if (mp[x] == 0) {
            d.push_front(x);
            if (d.size() > k) {
                mp[d[k]] = 0;
                d.pop_back();
            }
            mp[x] = 1;
        }
    }
    cout << d.size() << endl;
    for (auto it : d) cout << it << " ";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ll t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, t;
    cin >> n >> k;
    vector<int> a;
    map<long long, bool> r;
    for(int i = 0; i < n; ++i){
        cin >> t;
        if(!r[t - 1]){
            a.insert(a.begin(), t);
            r[t - 1] = 1;
            if(a.size() > k){
                r[ a[a.size() - 1] - 1] = 0;
                a.pop_back();
            }
        }
    }
    cout << a.size() << endl;
    for(auto i: a)
        cout << i << " " ;
    return 0;
}


/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=0;i<n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}

using namespace std;
int64_t R=1;
void solution(){
    int64_t n, k;
    cin >> n >> k;
    set <char> st;
    map <int64_t, int64_t> mp;
    vector <int64_t> v;
    for (int i = 0; i < n; ++i) {
        int64_t x;
        cin >> x;
        if (mp[x] == 0) {
            v.push_back(x);
            mp[x] = 1;
        }
        st.insert(x);
    }
    cout << min((int64_t)sz(st), k) << endl;
    for (int i = min(k,(int64_t) v.size()) - 1; i >= 0; i--) {
        cout << v[i] << " ";
    }
}
int main(){
    // cin>>R;
    while(R--){solution();}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k, t;
    cin >> n >> k;
    deque<int> a;
    map<long long, bool> r;
    for(int i = 0; i < n; ++i){
        cin >> t;
        if(!r[t - 1]){
            a.push_front(t);
            r[t - 1] = 1;
            if(a.size() > k){
                r[ a[a.size() - 1] - 1] = 0;
                a.pop_back();
            }
        }
    }
    cout << a.size() << endl;
    for(auto i: a)
        cout << i << " " ;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, t;
    cin >> n >> k;
    vector<int> a;
    for(int i = 0; i < n; ++i){
        cin >> t;
        bool b = false;
        for(int j = 0; j < a.size(); ++j)
            if(a[j] == t)
                b = true;

        if(!b)
            a.insert(a.begin(), t);

        if(a.size() > k)
            a.pop_back();

    }
    cout << a.size() << endl;
    for(auto i: a)
        cout << i << " " ;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, t;
    cin >> n >> k;
    deque<int> a;
    map<long long, bool> r;
    for(int i = 0; i < n; ++i){
        cin >> t;
        if(!r[t - 1]){
            a.push_front(t);
            r[t - 1] = 1;
            if(a.size() > k){
                r[ a[a.size() - 1] - 1] = 0;
                a.pop_back();
            }
        }
    }
    cout << a.size() << endl;
    for(auto i: a)
        cout << i << " " ;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, t;
    cin >> n >> k;
    vector<int> a;
    map<long long, bool> r;
    for(int i = 0; i < n; ++i){
        cin >> t;
        if(!r[t - 1]){
            a.insert(a.begin(), t);
            r[t - 1] = 1;
        }
        if(a.size() > k){
            r[ a[a.size() - 1] - 1] = 0;
            a.pop_back();
        }
    }
    cout << a.size() << endl;
    for(auto i: a)
        cout << i << " " ;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, t;
    cin >> n >> k;
    vector<int> a;
    vector<int> r(10000000);
    for(int i = 0; i < n; ++i){
        cin >> t;
        if(!r[t - 1]){
            a.insert(a.begin(), t);
            r[t - 1] = 1;
        }
        if(a.size() > k){
            r[ a[a.size() - 1] - 1] = 0;
            a.pop_back();
        }
    }
    cout << a.size() << endl;
    for(auto i: a)
        cout << i << " " ;
    return 0;
}


#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
using namespace std;
vector<lli> primes;
void SOE(lli n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (lli p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (lli i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (lli p=2; p<=n; p++)
       if (prime[p])
       {
           primes.push_back(p);
       }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    lli i,r,c=0,j,k,t,f=0,q,n,l,f1=0,y,x,m,d;
    string s,s1,s2;
    cin>>t;
    for(i=0;i<t;i++)
    {
        x=0;
        y=0;
        c=0;
        cin>>n>>l;
        lli a[n],a1[n],a2[n];
        for(j=0;j<n;j++)
        {
            cin>>a[j];
        }
        x=0;y=0;
        for(j=0;j<n;j++)
        {
          if(a[j]%2==0)
          {
              a2[x]=a[j];
              x++;
          }
          else
          {
              a1[y]=a[j];
              y++;
          }
        }
        x=0;y=0;
        for(j=0;j<n;j++)
        {
            if(c%2==0)
            {
                c+=a1[y];
                y++;
            }
            else
            {
                c+=a2[x];
                x++;
            }
            if(j+1==l)
            {
                if(c%2==0)
                    cout<<"NO\n";
                else
                    cout<<"YES\n";
                break;
            }
        }
    }

}


#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
using namespace std;
vector<lli> primes;
void SOE(lli n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (lli p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (lli i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (lli p=2; p<=n; p++)
       if (prime[p])
       {
           primes.push_back(p);
       }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    lli i,r,c=0,j,k,t,f=0,q,n,l,f1=0,y,x,m,d;
    string s,s1,s2;
    cin>>t;
    for(i=0;i<t;i++)
    {
        x=0;
        y=0;
        c=0;
        cin>>n>>l;
        lli a[n],a1[n],a2[n];
        for(j=0;j<n;j++)
        {
            cin>>a[j];
        }
        x=0;y=0;
        for(j=0;j<n;j++)
        {
          if(a[j]%2==0)
          {
              a2[x]=a[j];
              x++;
          }
          else
          {
              a1[y]=a[j];
              y++;
          }
        }
        x=0;y=0;
        for(j=0;j<n;j++)
        {
            if(c%2==0)
            {
                c+=a1[y];
                y++;
            }
            else
            {
                c+=a2[x];
                x++;
            }
            if(j+1==l)
            {
                if(c%2==0)
                    cout<<"No\n";
                else
                    cout<<"Yes\n";
                break;
            }
        }
    }

}


#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
using namespace std;
vector<lli> primes;
void SOE(lli n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (lli p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (lli i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (lli p=2; p<=n; p++)
       if (prime[p])
       {
           primes.push_back(p);
       }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    lli i,r,c=0,j,k,t,f=0,q,n,l,f1=0,y,x,m,d;
    string s,s1,s2;
    cin>>t;
    for(i=0;i<t;i++)
    {
        x=0;
        y=0;
        c=0;
        cin>>n>>l;
        lli a[n],a1[n],a2[n];
        for(j=0;j<n;j++)
        {
            a1[j]=0;
            a2[j]=0;
        }
        for(j=0;j<n;j++)
        {
            cin>>a[j];
        }
        x=0;y=0;
        for(j=0;j<n;j++)
        {
          if(a[j]%2==0)
          {
              a2[x]=a[j];
              x++;
          }
          else
          {
              a1[y]=a[j];
              y++;
          }
        }
        x=0;y=0;
        for(j=0;j<n;j++)
        {
            if(c%2==0)
            {
                if(a1[y]>0)
                {
                c+=a1[y];
                y++;
                }
                else
                {
                c+=a2[x];
                x++;
                }
            }
            else
            {
                if(a2[x]>0)
                {
                c+=a2[x];
                x++;
                }
                else
                {
                c+=a1[y];
                y++;
                }
            }
            //cout<<c;
            if(j+1==l)
            {
                if(c%2==0)
                    cout<<"No\n";
                else
                    cout<<"Yes\n";
                break;
            }
        }
    }

}


#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
using namespace std;
vector<lli> primes;
void SOE(lli n)
{

    primes.erase(primes.begin(),primes.end());
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (lli p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (lli i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (lli p=2; p<=n; p++)
       if (prime[p])
       {
           primes.push_back(p);
       }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    lli i,c=0,j,k,t,f=0,q,n,f1=0,y,x,m,l=0,r,p;
    string s,s1,s2;
    cin>>t;
    while(t--)
    {
        cin>>n>>x;
        lli a[n],o=0,e=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]%2==0)
                e++;
            else
                o++;
        }
        if(n==x&&o%2==0)
            cout<<"No\n";
        else if(o>0&&x%2==1)
            cout<<"Yes\n";
        else if(o>0)
           {
               if(e>=x)
                cout<<"Yes\n";
               else if(e<x)
               {
                   if(x%2==0&&o%2==1)
                   {
                       cout<<"Yes\n";
                   }
                   else if(x%2==1&&(x-e)%2==1)
                    cout<<"Yes\n";
                   else
                    cout<<"No\n";
               }
               else
                cout<<"No\n";
           }
        else
            cout<<"No\n";

    }
}


#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
using namespace std;
vector<lli> primes;
void SOE(lli n)
{

    primes.erase(primes.begin(),primes.end());
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (lli p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (lli i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (lli p=2; p<=n; p++)
       if (prime[p])
       {
           primes.push_back(p);
       }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    lli i,c=0,j,k,t,f=0,q,n,f1=0,y,x,m,l=0,r,p;
    string s,s1,s2;
    cin>>t;
    while(t--)
    {
        cin>>n>>x;
        lli a[n],o=0,e=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]%2==0)
                e++;
            else
                o++;
        }
        if(n==x&&o%2==0)
            cout<<"No\n";
        else if(o>0&&x%2==1)
            cout<<"Yes\n";
        else if(o>0)
           {
               if(e>=x)
                cout<<"Yes\n";
               else if(e<x)
               {
                   if(x%2==0&&(x-e)%2!=0)
                   {
                       cout<<"Yes\n";
                   }
                   else if(x%2==1&&(x-e)%2==1)
                    cout<<"Yes\n";
                   else
                    cout<<"No\n";
               }
               else
                cout<<"No\n";
           }
        else
            cout<<"No\n";

    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        if(!od){
            cout<<"No\n";
            continue;
        }
        bool bo=0;
        od--;
        ev++;
        if(od%2)od--;
        if(ev+od>=x)bo=1;
        if(bo){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        if(!od){
            cout<<"No\n";
            continue;
        }
        bool bo=0;
        ev++;
        od--;
        if(ev>=x)bo=1;
        while(od>0){
            od-=2;
            ev+=2;
            if(ev==x)bo=1;
        }
        if(bo){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        if(!od){
            cout<<"No\n";
            continue;
        }
        bool bo=0;
        od--;
        ev++;
        if(ev>=x)bo=1;
        int ans=ev;
        int OD=od;
        if(OD%2)OD--;
        while(OD>0){
            OD-=2;
            ans+=2;
            if(ans==x)bo=1;
        }
        ev++;
        if(od%2)od--;
        while(od>0&&ev>0){
            od-=2;
            ev--;
            ans++;
            if(ans==x)bo=1;
        }
        if(bo){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int n,x;

main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>x;
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(a[i]%2)od++;
            else ev++;
        }
        if(!od){
            cout<<"No\n";
            continue;
        }
        bool bo=0;
        for(int i=1;i<=od;i+=2){
            if(x>=i&&x<=ev+i)bo=1;
        }
        if(bo)cout<<"Yes\n";
        else cout<<"No\n";
    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        bool bo=0;
        if(!od){
            cout<<"No\n";
            continue;
        }
        if(od%2)od--;
        if(ev+1>=x)bo=1;
        int ans=ev+1;
        if(od%2)od--;
        while(od>0){
            od-=2;
            ans+=2;
            if(ans==x)bo=1;
        }
        while(ev--){
            ans++;
            if(ans==x)bo=1;
        }
        if(bo){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        if(!od){
            cout<<"No\n";
            continue;
        }
        if(od%2==0)od--;
        if(od+ev>=x)cout<<"Yes\n";
        else cout<<"No\n";
    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        if(!od){
            cout<<"No\n";
            continue;
        }
        od--;
        ev++;
        if(od%2)od--;
        if(ev+od>=x)bo=1;
        if(bo){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        bool bo=0;
        if(!od){
            cout<<"No\n";
            continue;
        }
        if(od%2)od--;
        if(ev+1>=x)bo=1;
        int ans=ev+1;
        if(od%2)od--;
        while(od>0){
            od-=2
            ans+=2;
            if(ans==x)bo=1;
        }
        while(ev--){
            ans++;
            if(ans==x)bo=1;
        }
        if(bo){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1001;
int a[N];
int pow(int b,int p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2)return b*pow(b,p-1);
    int r=pow(b,p/2);
    return r*r;
}
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)cin>>a[i];
        int od=0,ev=0;
        for(int i=1;i<=n;i++){
            if(a[i]%2)od++;
            else ev++;
        }
        if(!od){
            cout<<"No\n";
            continue;
        }
        bool bo=0;
        ev++;
        od--;
        if(ev>=x)bo=1;
        if(od%2)od--;
        while(od>0){
            od-=2;
            ev+=2;
            if(ev==x)bo=1;
        }
        if(bo){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll  n,x;
		cin>>n>>x;
		ll arr[n];
		ll odd=0,even=0;
		for(ll i=0;i<n;i++)
		{
			cin>>arr[i];
			if(arr[i]%2==0)even++;
			else odd++;
		}
		if(x%2==0)
		{
			if(even>0 && odd>=x-1)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
		else
		{
			if(odd>=x)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll  n,x;
		cin>>n>>x;
		ll arr[n];
		ll odd=0,even=0;
		for(ll i=0;i<n;i++)
		{
			cin>>arr[i];
			if(arr[i]%2==0)even++;
			else odd++;
		}
		//cout<<even<<" "<<odd<<endl;
		if(odd==0)cout<<"No"<<endl;
		if(odd>=x)
		{
			if(x%2==0)
			{
				if(even>0)cout<<"Yes"<<endl;
				else cout<<"No"<<endl;
			}
			else cout<<"Yes"<<endl;
		}
		else
		{
			if(odd%2==0)
			{
				if(even>=x-odd+1)cout<<"Yes"<<endl;
				else  cout<<"No"<<endl;
			}
			else
			{
				if(even>=x-odd)cout<<"Yes"<<endl;
				else cout<<"No"<<endl;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll  n,x;
		cin>>n>>x;
		ll arr[n];
		vector<ll>dig(1010);
		ll odd=0,even=0;
		for(ll i=0;i<n;i++)
		{
			cin>>arr[i];
			dig[arr[i]]++;
			if(arr[i]%2==0)even++;
			else if(dig[arr[i]]==1)odd++;
			else
			{
				if(dig[arr[i]]%2==0) even++;
				else odd++;
			}

		}
		//cout<<even<<" "<<odd<<endl;
		if(x%2==0)
		{
			if(even>0 && odd>=x-1)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
		else
		{
			if(odd>=x)cout<<"Yes"<<endl;
			else if(odd%2==0 && even+odd-1>=x)cout<<"Yes"<<endl;
			else if(odd%2!=0 && even>=x-odd)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
	}
	return 0;
}