#include <stdio.h>
#include <stdlib.h>

int main()
{
    long N, K;
    scanf("%ld %ld", &N, &K);
    long Ntemp = N;
    long i, j = 0;
    long arr[N], *pokarr;
    for(i = 0; i < N; i++) scanf("%ld", &arr[i]);
    pokarr = arr;
    sort(pokarr, N);
    long count = counter(pokarr, N, K);

    long karr[count], *pokk;
    long temp = 1, kt;

    for(i = 0; i < N-1; i++)
    {
        if(*(arr+i) == *(arr+i+1)){
           temp++;
           kt = *(arr+i);
        }
        else{
            if(temp >= K){
                karr[j] = kt;
                j++;
            }
            temp = 1;
        }
    }
    if(temp >= K){
        karr[j] = kt;
        j++;
    }
    printf("%ld \n", count);
    for(i = 0; i < count; i++) printf("%ld ", karr[i]);
}

int counter(long* arr, long N, long K)
{
    long count = 0, temp = 1;
    long i;
    for(i = 0; i < N-1; i++)
    {
        if(*(arr+i) == *(arr+i+1)) temp++;
        else{
            if(temp >= K) count++;
            temp = 1;
        }
    }
    if(temp >= K) count++;
    return count;
}

void sort(long* arr, long N)
{
    long temp;
    long i, j;
    for(i = 0; i < N-1; i++){
        for(j = i; j < N; j++){
            if(*(arr+i) > *(arr+j))
            {
                temp = *(arr+i);
                *(arr+i) = *(arr+j);
                *(arr+j) = temp;
            }
        }
    }
}