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

int n,niz[1000002],a,ds[1000002],br,k,br3,br2;


int main(){

cin>>n>>k;
br2=1;
br3=0;

for (int i=1; i<=n; i++) {
      cin>>a;
      ds[a]++;
}

for (int i=1; i<=n; i++) {

        for (int j=1; j<=ds[i]; j++)
                niz[++br]=i;


	if(niz[i]==niz[i+1]){
            br2++;
}

	//cout<<br2<<endl;
	 if(br2>=k){
        br2=1;
        br3++;
	}
	}


	///for (int i=1; i<=n; i++) cout<<niz[i];
cout<<br3<<endl;

for (int i=1; i<=n; i++) {

        for (int j=1; j<=ds[i]; j++)
                niz[++br]=i;


	if(niz[i]==niz[i+1]){
            cout<<niz[i]<<" ";
}
}
return 0;
}