#include <iostream>
#include <algorithm>
using namespace std;
main()
{
                long int n;
        long int k;
                cin>>n;
            cin>>k;
            long int niza[n];
    for (int i = 0; i < n; i++)
            {
                            cin>>niza[i];
            }
                sort(niza, niza+n);
            long int piz[n]; long int br = 0; long int pk = 1; long int pom = niz[0];
                for (long int i = 1; i<n; i++)
            {
                if(i == n - 1)
                {
                    if                                                      (niz[i] == pom)
                    {
                        pk++;
                    }
                if (pk >= k)
                {
                            if(k==1)
                    {
                        pk = 1;
            piz[br] = pom;
                        piz[br+1] = niza[i];
                        br+=2;
                    }
                    else
                    {
                        pk = 1;
                piz[br] = pom;
                        br++;
                    }
                }
                }
                else
                {
                    if (niza[i] == pom)
                    {
                        pk++;
                    }
                            else
                    {
                        if (pk >= k)
                        {
                            pk = 1;
                            piz[br] = pom;
                            br++;
                        }
                        else
                        {
                            pk = 1;
                        }
                    }
                    pom = niza[i];
                }
            }
                cout<<br<<endl;
            for (long int i = 0; i < br; i++)
            {
               cout<<piz[i]<<" ";
            }
        }