#include <bits/stdc++.h>

using namespace std;
long long a[1000001];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n,k;
    cin>>n>>k;
    for(long long i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    /*for(long long i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<"\n";*/
    vector<long long> pz;
    if(k>1)
    {long long nzr=1;
    for(long long i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
        {
            nzr++;
            if(nzr==k)
            {
                pz.push_back(a[i]);
            }
        }
        else
        {
            nzr=1;
        }
    }
    }
    else
    {
        pz.push_back(a[0]);
        for(long long i=1;i<n;i++)
            if(a[i]!=a[i-1])
            pz.push_back(a[i]);
    }
    cout<<pz.size()<<"\n";
    for(long long i=0;i<pz.size();i++)
        cout<<pz[i]<<" ";
}