#include <iostream>
#include <algorithm>
int a[1000000], b[1000000];
int main()
{
    int n, k;
    std::cin >> n>>k;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    std::sort(a, a + n);
    int j = 0, p = -n - 1, i = 0;
    while (j < n)
    {
        if(a[j]!=p)
        if (a[j] == a[j + k - 1])
        {
            b[i]= a[j];
            i++;
            j = j + k-1;
        }
        p = a[j];
        j++;
    }
    printf("%d\n", i);
    for(int l=0; l<i; l++)
        printf("%d ", b[l]);
}