#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,k,x,s=0,y,z=1;
    cin>>n>>k;
    vector<int> v;
    vector<int> v1;
    for(int i=0;i<n;i++){
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    y=v[0];
    for(int i=1;i<n;i++){
        if(v[i]==y){
            z++;
        }
        else{
            z=1;
            y=v[i];
        }
        if(z==k){
            s++;
            v1.push_back(y);
        }
    }
    cout << s << endl;
    for(int i=0;i<s;i++){
        cout<<v1[i]<<" ";
    }
    return 0;
}