#include <iostream>
#include <algorithm>
using namespace std;
main()
{

            long int n;
            long int k;
            cin>>n;
            cin>>k;
            long int niz[n];
            for (int i = 0; i < n; i++)
            {
                cin>>niz[i];
            }
            sort(niz, niz+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)
                        {
                            pk = 1;
                            piz[br] = pom;
                            br++;
                        }
                    }
                }
                else
                {
                    if (niz[i] == pom)
                    {
                        pk++;
                    }
                    else
                    {
                        if (pk >= k)
                        {
                            pk = 1;
                            piz[br] = pom;
                            br++;
                        }
                        else
                        {
                            pk = 1;
                        }
                    }
                    pom = niz[i];
                }
            }
            cout<<br<<endl;
            for (long int i = 0; i < br; i++)
            {
               if (i==br-1)
               cout<<piz[i];
               else
               cout<<piz[i]<<" ";
            }

        }