using System;

namespace Zadatak2._1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long n = long.Parse(s[0]), k = long.Parse(s[1]);
            long[] niz = new long[n];
            s = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                niz[i] = long.Parse(s[i]);
            }
            Array.Sort(niz);
            int br = 0,up = 0;
            string ispis = null;
            for (int i = 1; i < n; i++)
            {
                if (niz[i - 1] == niz[i])
                    br++;
                else br = 0;
                if (br == k - 1)
                {
                    if (ispis != null)
                        ispis = ispis + " " + niz[i];
                    else ispis = ispis + niz[i];
                    up++;
                }
            }
            Console.WriteLine(up);
            Console.WriteLine(ispis);
        }
    }
}