#include <iostream>
#include <algorithm>

using namespace std;


int main()
{
	long long int N = 0;
	long long int K = 0;
	int arr[100000];
	int zamena[100000];
	int zamenjivanje = 0;

	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		cin >> arr[i];
	}

	sort(arr, arr+N);

	if (K == 1)
	{
		int count = 0;
		for (int i = 0; i < N; i++)
		{
			zamena[count] = arr[i];
			count++;
			while (arr[i] == arr[i + 1])
				i++;
		}

		cout << count << endl;
		for (int i = 0; i < count; i++)
		{
			cout << zamena[i] << " ";
		}
	}
	else 
	{
		for (int i = 0; i < N; i++)
		{
			int counter = 0;
			if (arr[i] == arr[i + 1])
			{
				counter = 2;
				i++;
				while (arr[i] == arr[i + 1])
				{
					counter++;
					i++;
				}
				if (counter >= K)
				{
					zamena[zamenjivanje] = arr[i];
					zamenjivanje++;
				}
			}
		}
		cout << zamenjivanje << endl;
		for (int i = 0; i < zamenjivanje; i++)
		{
			cout << zamena[i] << " ";
		}
	}
}