using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PRVI
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] r = Console.ReadLine().Split(' ');
            long n = long.Parse(r[0]);
            long k = long.Parse(r[1]);
            string[] r1 = Console.ReadLine().Split(' ');
            long[] niz = new long[n];
            bool[] b = new bool[n];
            for (long i = 0; i < r1.Length; i++)
            {
                niz[i] = long.Parse(r1[i]);
            }
            string resenje = "";
            long brresenja = 0;
            long br = 0;
            for (long i = 0; i < n-1; i++)
            {
                br = 1;
                if (b[i] == false)
                    for (long j = i + 1; j < n; j++)
                    {
                        
                            if (niz[i] == niz[j])
                            {
                                br++;
                                b[j] = true;
                            }
                    }
                if (br >= k)
                {
                    resenje += niz[i] + " ";
                    brresenja+=br/k;
                }
            }

            Console.WriteLine(brresenja);
            Console.WriteLine(resenje);

        }
    }
}