#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long int N;
    int K;
    int brojac = 0;
    long long int b;
    cin >> N;
    int a[N];
    cin >> K;
    map<long long int, int> mapa;
    long long int i;
    for(i=0; i<N; i++)
    {
        cin >>b;
        if (mapa[b]=='\0')
            mapa[b]=1;
        else
        if(++mapa[b]==K)
        {
            a[brojac]=b;
            brojac++;

        }
    }
    cout << brojac << '\n';
    for (i=0;i<brojac;i++)
        cout << a[i] << " ";

    return 0;
}