#include <iostream>

using namespace std;

int main()
{
    int k;
    unsigned long long n;
    cin>>n>>k;
    int a[n],b[n];
    int c=1,d=0;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for (int i=0;i<n-1;i++)
    {
        for (int j=i+1;j<n;j++)
        {
            if (a[j]<a[i])
                swap(a[j],a[i]);
        }
    }
    for (int i=0;i<n-1;i++)
    {
        c=1;
        for (int j=i+1;j<n;j++)
        {
            if (a[i]==a[j])
            {
                c=c+1;
                  if (c==k)
                {
                    b[d]=a[i];
                    d=d+1;
                    c=0;
                }
            }
        }
    }

    int s=1;
    for (int i=0;i<d-1;i++)
    {

        if(b[i]!=b[i+1])
        {
            s=s+1;


        }

    }
    cout<<s<<endl;
    for (int i=0;i<d-1;i++)
    {

        if(b[i]!=b[i+1])
        {
            cout<<b[i]<<" ";


        }

    }
    cout<<b[d-1];
    return 0;
}