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

using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false);
    int n, k, ans = 0;
    scanf("%d %d",&n, &k);
    unordered_map<int, int> comp;
    vector<int> a;

    int d;
    for(int 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){
                comp[d]++;
                if(comp[d] == k){
                    ans++;
                    a.push_back(d);
                }
            }
        }
    }
    cout << ans << endl;
    for(int i = 0;i < ans;i++){
        cout << a[i] << " ";
    }
}