using System;

namespace Zadatak2._1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]), k = int.Parse(s[1]);
            int[] niz = new int[n];
            s = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                niz[i] = int.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);
        }
    }
}