#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
int main()
{
	long long n,k;
	cin>>n>>k;
	vector<long long> brojevi;
	long long a[n];
	for(long long i=0; i<n; i++)
	{
		cin>>a[i];
	}
	sort(a, a+n);
	long long brojac=1;
	for(long long i=1; i<n; i++)
	{
		if(a[i]==a[i-1])
		{
			brojac++;
		}
		else
		{
			brojac=1;
		}
		if(brojac>=k)
		{
			brojevi.push_back(a[i]);
			brojac=1;
			long long k=0;
			while(a[i+k]==a[i+k+1])
			{
				k++;
			}
			i+=k;
		}
	}
	cout<<brojevi.size()<<endl;
	for(long long i=0;i<brojevi.size();i++)
	{
		cout<<brojevi[i]<<" ";
	}
	
	return 0;
}