#include <bits/stdc++.h>

using namespace std;

void pikado(int a[], int n, int k){
    int pom[n], t = 0, p = 1, broj = 0;
    bool test = true;
    sort(a, a + n);
    for(int i = 0;i < n;i++){
        if(p >= k){
            broj++;
            pom[t] = a[i];
            test = false;
            t++;
        }
        if(a[i] == a[i+1]){
            p++;
            if(p >= k && test){
                broj++;
                pom[t] = a[i];
                t++;
                test = false;
            }
        }
        else{
            p = 1;
            test = true;
        }
    }
    cout << t << '\n';
    for(int i = 0;i < t;i++)
        cout << pom[i] << " ";
}

int main(){
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0;i < n;i++) cin >> a[i];
    pikado(a, n, k);
    return 0;
}