#include <iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
    map<int, int> p;  //second  = -1 ako je vec promenjena
    static int ispis[1000000];

    int n;
    int k;
    int counter = 0;  //za menjanje
    cin >> n;
    cin >> k;
    map<int, int>::iterator it;
    for (int i = 0; i < n; i++)
    {
        int point;
        cin >> point;
        it = p.find(point);
        if (it != p.end())
        {

            if (it->second != -1) {
                int num = it->second;
                it->second = num +1;
                if (it->second >= k) {
                   ispis[counter++] = it->first;
                    it->second = -1;
               }
            }
        }
        else
        {
            p.insert({ point, 1});
        }



    }
    cout << counter << endl;
    for (int i = 0; i < counter; i++)cout << ispis[i] << " ";



}