#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

void dodaj(int *h, int x, int d)
{
    h[d]=x;
    while (d && h[d] > h[(d-1)/2])
    {
        swap(h[d],h[(d-1)/2]);
        d = (d-1)/2;
    }

}

void uzmi(int *h, int d)
{
    int x=h[0],i=0;
    h[0]=h[d];
    h[d]=x;
    while (2*i+2<d)
        if (h[2*i+1]<h[2*i+2])
        {
            if (h[2*i+2] < h[i]) break;
            swap (h[2*i+2],h[i]);
            i=2*i+2;
        }
        else
        {
            if ( h[2*i+1] < h[i] ) break;
            swap ( h[2*i+1],h[i] );
            i=2*i+1;
        }
    if (d-1 == 2*i+1 && h[2*i+1]> h[i]) swap(h[i],h[2*i+1]);

}

void heapsort(int *a,int n)
{
    int h[n];
    for (int i=0; i<n; i++) dodaj(a, a[i], i);
    for (int i=0;i<n;i++ )uzmi(a,n-1-i);

}

int main()
{
    long long n;
    int k;
    scanf("%lld%d",&n,&k);
    int *a=(int*) calloc (n,sizeof(int));
    int *p=(int*) calloc (n,sizeof(int));
    for (int i=0;i<n;i++)
    {
        scanf("%d",&(a[i]));
        p[i]=1;
    }
    heapsort(a,n);
    int brojac=0;
    for (int i=0;i<n;i++)
    {
        int br=0;
        while (a[i]==a[i+1])
        {
            br++;
            i++;
        }
        p[i]+=br;
        if (k<=p[i]) brojac++;
    }
    printf("%d\n",brojac);
    for (int i=0;i<n;i++)
    {
        if (k<=p[i]) printf("%d ",a[i]);
    }
}