#include <bits/stdc++.h>

using namespace std;

int ar[1000000];
vector<int> v;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, k;

    cin >> n >> k;

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

    sort(ar, ar+n);

    int _k = 0, lst = INT_MAX, res = 0;
    for(int i = 0; i < n; i++)
    {
        if(ar[i] == lst)
        {
            _k++;
        }
        else
        {
            _k = 1;
            lst = ar[i];
        }

        if(_k == k)
        {
            res++;
            v.push_back(ar[i]);
        }
    }

    cout << res << "\n";
    for(auto e : v)
    {
        cout << e << " ";
    }
}