#include <bits/stdc++.h>
#include<vector>

using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    long n, k, ans = 0;
    cin >> n >> k;
    unordered_map<long, long> comp;
    vector<long> a;

    long d;
    for(long i = 0;i < n; i++){
        scanf("%d",&d);
        auto it = comp.find(d);
        if(it == comp.end()){
            comp[d] = 1;
        }else{
            if(comp[d] == k - 1){
                comp[d]++;
                ans++;
                a.push_back(d);
            }
        }
    }
    cout << ans << endl;
    for(long i = 0;i < ans;i++){
        cout << a[i] << " ";
    }
}