using System;

namespace ConsoleApp27
{
    class Program
    {private static void zameni(int[] a,int p,int d)
        {
            int v;
            v = a[p];
            a[p] = a[d];
            a[d] = v;
        }
        private static void qs(int[] a, int l, int d)
        {
         /*   for (int i = 0; i < 4; i++)
            { Console.Write(a[i] + " ");
            

            }
            Console.WriteLine();*/
            if (d - l == 1)
            {
                if (a[l] > a[d])
                {
                    zameni(a, l, d);
                }
            }
            else
            {
               int x = a[(l + d)/2];
                int i = l;
                int j = d;
                do
                {
                    while (a[i] < x)
                    {
                        i++;
                    }
                    while (a[j] > x)
                    {
                        j--;
                    }
                    if (i <= j)
                    {
                        zameni(a, i, j);
                        i++;
                        j--;
                    }
                }
                while (i <= j);
                if (j > l)
                {
                    qs(a, l, j);
                }
                if (i < d)
                {
                    qs(a, i, d);
                }
            }
        }
        static void Main(string[] args)
        {
            int n,k,x,brx=0,gbr=0,t=0;
            string[] r2 = Console.ReadLine().Split();
            n = int.Parse(r2[0]);
            k = int.Parse(r2[1]);
            int[] a = new int[n];
            int[] b = new int[n];
           string[] r = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(r[i]);
               
        }
            qs(a, 0, n-1);
            //Console.WriteLine();
            /*for (int i = 0; i < n; i++)
            { Console.Write(a[i] + " "); }*/
                for (int i = 0; i < n; i=i+brx)
            {
                brx = 0;
                 //Console.WriteLine("p " + a[i] + " ");
                for (int j = i; j < n; j++)
                {
                    //Console.WriteLine(a[i] + " " + a[j]);
                    if (a[i] == a[j])  brx++; //Console.WriteLine(brx); 
                    else break;
                    
                }
                if (brx >= k) { gbr++; b[t] = a[i]; t++; }
             
           


            }
           Console.WriteLine(gbr);
            for(int i =0; i<gbr;i++){ Console.Write(b[i]+" "); }
            Console.ReadLine();       
        }
     
    }
}