#include<stdio.h>
#include<queue>
#include<set>
using namespace std;
int main()
{long n,k,p,pmj,br=0;
priority_queue<long> g;
set<long> gg;

scanf("%ld %ld",&n,&k);




	for(long j=0;j<n;j++)
	{   scanf("%ld",&p);
		g.push(p);
	
		
	}
	pmj=g.top();
	g.pop();

while(!g.empty())
	{
		p=g.top();
		g.pop();
		if(p==pmj)
		{br++;
			
			
		}
		else br=0;
		
		if(br>=k-1)
		gg.insert(p);
		
		pmj=p;
		
	}
	printf("%ld\n",gg.size());
	

set<long>::iterator it = gg.begin();
for (; it != gg.end(); it++)  printf("%ld ",*it);
	
	
	return 0;
	
	
}