#include<iostream>
#include<algorithm>
#include<vector>
#include<iterator>
using namespace std;
void unos(vector<int> a, int n)
{
    int b;

}
int main()
{
    vector<int> a;
    vector<int> c;
    vector<int>::iterator i;
    i=a.begin();
    int n,k,b,broj=0,duz=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>b;
        a.push_back(b);
    }
    sort(a.begin(),a.end());
    for(i=a.begin()+1;i<a.end();i++)
    {
        if (*i==*(i-1))
            duz++;
        else
            if(duz!=0)
            {
                if (duz+1>=k)
                {
                    c.push_back(*(i-1));
                    broj++;
                    duz=0;
                }
            }
    }
    if(duz!=0)
        if (duz+1>=k)
        {
            c.push_back(*(i-1));
            broj++;
            duz=0;
        }
    cout<<broj<<endl;
    for (i=c.begin();i<c.end();i++)
        cout<<*i<<' ';
}