#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n,k;
    cin >>n >>k;
    int a[n],rez[n];
    for (int i = 0; i<n; i++)
        cin >> a[i];
    sort(a,a+n);
    int f = 0,s = 0;
    int brojac = 0, brojacrez = 0;
    while (f!=n)
    {
        while (f!=n && a[f]==a[s])
        {
            brojac++;
            f++;
        }
        if (brojac / k >0)
        {
            rez[brojacrez] = a[s];
            brojacrez = brojacrez + 1;
        }
        brojac = 0;
        s = f;
    }
    cout <<brojacrez<<endl;
    for (int i = 0; i<brojacrez; i++)
        cout <<rez[i]<<" ";
}