#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    // input

    int n, a;
    cin >> n >> a;
    vector<int> v;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    
    // algo

    sort(v.begin(), v.end());

    set<int> change;

    int prevNum = v[0];
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == prevNum) {
            cnt++;
        } else {
            cnt = 1;
        }

        if (cnt == a) {
            cnt = 0;
            change.insert(v[i]);
        }

        prevNum = v[i];
    }
    
    // output

    cout << change.size() << endl;

    for (set<int>::iterator it = change.begin(); it != change.end(); ++it) {
        cout << (*it) << ' ';
    }

    return 0;
}