#include <bits/stdc++.h>
#include <vector>
using namespace std;
template<typename T>
void removeDuplicates(std::vector<T>& vec)
{
    std::sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
}
int main()
{
    long long int b[100000];
    long long int c[100000];
    int n,k,j=1,a,br=0,f=0,d=1;
    vector<int> myVector;
    vector<int> v;
    scanf("%d%d",&n,&k);
    for (int h=0;h<n;h++ )
    {
        scanf("%d",&a);
        myVector.push_back(a);
    }

    sort(myVector.begin(), myVector.end());

        while(j<myVector.size())
        {
            if (myVector[j]==myVector[j-1])
            {
            c[d]=myVector[j];
            b[d]=b[d]+1;
            j++;
            }
            else
            {
                b[d]+=1;
                d++;
                j++;
            }
        }
    if (k!=1)
    {
    for (unsigned int i = 1; i < myVector.size(); i++)
    {
    for (int g=1;g<d;g++)
    {
    if ((myVector[i] == myVector[i-1])&&(myVector[i]==c[g] && b[g]>=k) )
    {
        v.push_back(myVector[i]);
    }
    }
    }
    removeDuplicates<int>(v);
    cout << v.size() << endl;
    for (unsigned int k = 0;k < v.size();k++)
    {
        printf("%d ",v[k]);
    }
    }
    else if(k==1)
    {
    removeDuplicates<int>(myVector);
    cout << myVector.size() << endl;
    for (unsigned int k = 0;k < myVector.size();k++)
    {
        printf("%d ",myVector[k]);
    }
    }
    return 0;
}