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

                long int n;
              long int k;
                cin>>n;
                    cin>>k;
                long int earray[n];
                for (int i = 0; i < n; i++)
            {
                    cin>>earray[i];
            }
					sort(earray, earray+n);
                long int tearray[n];
					long int cnt = 0; long int tmp2 = 1; long int tmp = earray[0];
                for (long int i = 1; i<n; i++)
                {
                    if (i == n - 1)
                {
                    if (earray[i] == tmp)
                    {
                        tmp2++;
                    }


                if (tmp2 >= k)
                {
                            if(k==1)
                    {
                        tmp2 = 1;
                        tearray[cnt] = tmp;
                        tearray[cnt+1] = earray[i];
                        cnt+=2;
                    }
                    else
                    {
                        tmp2 = 1;
                        tearray[cnt] = tmp;
                        cnt++;
                    }
                }

                }

                        else
                {
                   if (earray[i] == tmp)
                    {
                       tmp2++;
                    }
                        else
                    {
                      if (tmp2 >= k)
                        {
                            tmp2 = 1;
									tearray[cnt] = tmp;
                          cnt++;
                        }
                        else
                        {
                            tmp2 = 1;
                        }
                    }
                    tmp = earray[i];
                }
            }
               cout<<cnt<<endl;
         for (long int i = 0; i < cnt; i++)
            {

                 cout<<tearray[i]<<" ";
            }

        }