#include <bits/stdc++.h>

using namespace std;

unordered_multiset<int> setic;

int main()
{
    int n, k, r = 0;
    cin >> n >> k;
    int t[n/k];
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        setic.insert(a);
        if(setic.count(a) == k){
            t[r] = a;
            r++;
        }
    }
    cout << r << "\n";
    for(int i = 0; i < r; i++)cout << t[i] << " ";
    return 0;
}