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

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


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

                }

                        else
                {
                   if (array[i] == tmp)
                    {
                       tmp2++;
                    }
                        else
                    {
                      if (tmp2 >= k)
                        {
                            tmp2 = 1;
									tarray[cnt] = tmp;
                          cnt++;
                        }
                        else
                        {
                            tmp2 = 1;
                        }
                    }
                    tmp = array[i];

                    
                }
            }
               cout<<cnt<<endl;
         for (long int i = 0; i < cnt; i++)
            {
                 cout<<tarray[i]<<" ";
            }
        }