#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	int n, k, x=0,o=0;
	cin >> n;
	cin >> k;
	vector<int>a(n);
	vector<int>b;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++)
	for (int j=i+1;j<n;j++)
	{
		if (a[i] == a[j]) {
			x++;
		}
		else x = 1;
		if (x == k) {
			b.push_back(a[i]);
			o++;
			x = 1;
		}
	}
		cout << o << endl;
	for (int i = 0; i < b.size(); i++)
		cout << b[i] << " ";
	return 0;
}