#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long int n,k,num = 1,N = 0;
    bool btemp = false;

    cin >> n;
    cin >> k;

    long int niz[n],niz2[n];

    for(int i = 0; i < n; ++i) {
        cin >> niz[i];
    }

    sort(niz, niz + n);

    cout << endl;

    for(int i = 0; i < n - 1; ++i) {
        if(niz[i] != niz[i+1]) {
            btemp = false;
        } else {
            btemp = true;
        }

        if(btemp == false && num >= k) {
            niz2[N] = niz[i];
            N++;
        }

        if(niz[i] != niz[i+1]) {
            num = 1;
        } else {
            num++;
        }
    }

    if(num >= k) {
        niz2[N] = niz[n-1];
        N++;
    }

    cout << N << endl;

    for(int i = 0; i < N; ++i) {
        cout << niz2[i] << " ";
    }

    return 0;
}