#include <bits/stdc++.h>

#define pb push_back

using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;

    vector<int> sol;
    unordered_map<int, int> cnt;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;

        if(cnt[x] == k)
            sol.pb(x);
    }

    cout << sol.size() << endl;
    for(int k: sol)
        cout << k << " ";
    cout << endl;
    return 0;
}