Problem:
Score : 700 points

Problem Statement

We have a sequence of N \times K integers: X=(X_0,X_1,\cdots,X_{N \times K-1}).
Its elements are represented by another sequence of N integers: A=(A_0,A_1,\cdots,A_{N-1}). For each pair i, j (0 \leq i \leq K-1,\ 0 \leq j \leq N-1), X_{i \times N + j}=A_j holds.

Snuke has an integer sequence s, which is initially empty.
For each i=0,1,2,\cdots,N \times K-1, in this order, he will perform the following operation:

If s does not contain X_i: add X_i to the end of s.

If s does contain X_i: repeatedly delete the element at the end of s until s no longer contains X_i. Note that, in this case, we do not add X_i to the end of s.

Find the elements of s after Snuke finished the operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 10^{12}

1 \leq A_i \leq 2 \times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_0 A_1 \cdots A_{N-1}

Output

Print the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in between.

Sample Input 1

3 2
1 2 3

Sample Output 1

2 3

In this case, X=(1,2,3,1,2,3).
We will perform the operations as follows:

i=0: s does not contain 1, so we add 1 to the end of s, resulting in s=(1).

i=1: s does not contain 2, so we add 2 to the end of s, resulting in s=(1,2).

i=2: s does not contain 3, so we add 3 to the end of s, resulting in s=(1,2,3).

i=3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1, which causes the following changes to s: (1,2,3)→(1,2)→(1)→().

i=4: s does not contain 2, so we add 2 to the end of s, resulting in s=(2).

i=5: s does not contain 3, so we add 3 to the end of s, resulting in s=(2,3).

Sample Input 2

5 10
1 2 3 2 3

Sample Output 2

3

Sample Input 3

6 1000000000000
1 1 2 2 3 3

Sample Output 3

s may be empty in the end.

Sample Input 4

11 97
3 1 4 1 5 9 2 6 5 3 5

Sample Output 4

9 2 6

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace A
{
    partial class Program
    {

        public IEnumerable<string> Solve()
        {
            var n = Scan;
            var k = Scan;
            var a = ScanLongs(n);

            //var r = new Random((int)DateTime.Now.Ticks);
            ////k = r.Next(int.MaxValue) * int.MaxValue;
            //a = Loop(200001).Select(_ => (long)r.Next(200000) + 1).ToList();
            ////a = Loop(200001).Select(_ => (long)_).ToList();
            //n = a.Count;
            //k = 1;

            var nexts = Loop((int)n).Select(_ => -1L).ToArray();

            {
                var tails = Loop(200002).Select(_ => -1L).ToArray();

                long memoCount = 0;
                long pointer = 0;
                while (memoCount < n)
                {
                    var aa = a[(int)pointer];

                    if (tails[aa] >= 0 && nexts[tails[aa]] < 0)
                    {
                        nexts[tails[aa]] = (pointer + 1) % n;
                        memoCount++;
                    }

                    tails[aa] = pointer;

                    pointer++;
                    pointer %= n;
                }
            }


            long mod = 0;
            {
                var pointer = 0L;
                do
                {
                    var t = nexts[pointer];
                    if (pointer >= t - 1)
                        mod++;
                    pointer = t;
                }
                while (pointer != 0);
            }

            {
                var current = 0L;
                var kk = (k + mod - 1) % mod;
                var pointer = 0L;
                do
                {
                    var t = nexts[pointer];
                    if (pointer >= t - 1)
                    {
                        if (current >= kk)
                            break;

                        current++;
                    }
                    pointer = t;
                }
                while (true);

                var res = new List<long>();
                var memo = new Dictionary<long, int>();
                int tail = -1;

                for (long i = pointer; i < n; i++)
                {
                    var aa = a[(int)i];
                    if (memo.ContainsKey(aa) && memo[aa] >= 0)
                    {
                        tail = memo[aa] - 1;
                        memo[aa] = -1;
                    }
                    else
                    {
                        tail++;
                        if (tail < res.Count)
                            res[tail] = aa;
                        else
                            res.Add(aa);
                        memo[aa] = tail;
                    }
                }

                yield return string.Join(" ", res.Take(tail + 1));

            }
        }
    }

    class StartingPoint
    {
        static void Main(string[] args)
        {
            if (args?.Any() == true)
            {
                var assembly = Assembly.GetEntryAssembly();
                var resourceName = "AtCoderCSharp.In.txt";
                var stream = assembly.GetManifestResourceStream(resourceName);
                var streamReader = new StreamReader(stream, Encoding.UTF8);
                var str = streamReader.ReadToEnd();
                var textReader = new StringReader(str);
                Console.SetIn(textReader);
            }

            try
            {
                foreach (var s in new Program().Solve())
                {
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (args?.Any() != true)
                    throw e;
            }

            if (args?.Any() == true)
                Console.ReadKey();
        }
    }

    partial class Program
    {
        public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList();
        public List<int> ScanInts(long count) => ScanInts((int)count);
        public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList();
        public List<long> ScanLongs(long count) => ScanLongs((int)count);
        public int ScanInt => int.Parse(Str);
        public long Scan => long.Parse(Str);
        public double ScanDouble => (double)Scan;

        StringBuilder sb = new StringBuilder();

        public string Str => ScanStr();
        public string ScanStr()
        {
            sb.Clear();

            int r = 0;
            bool? b = null;
            do
            {
                r = Console.Read();
                b = IsBreak(r);
            } while (b == true);

            if (b == null)
                throw new Exception("input error: unexpected end of stream");

            do
            {
                sb.Append((char)r);
                r = Console.Read();
                b = IsBreak(r);
            } while (b == false);

            return sb.ToString();
        }

        bool? IsBreak(int c)
        {
            switch (c)
            {
                case -1:
                    return null;
                case (int)' ':
                case (int)'\n':
                case (int)'\r':
                    return true;
                default:
                    return false;
            }
        }

        public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
        public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1);

        public string YesNo(bool isYes) => isYes ? "Yes" : "No";

        public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts);

        public int Gcm(int a, int b)
        {
            if (a < b)
                return GcmImpl(b, a);
            else
                return GcmImpl(a, b);
        }

        int GcmImpl(int a, int b)
        {
            var remainder = a % b;
            if (remainder == 0)
                return b;
            else
                return GcmImpl(b, remainder);
        }

        public int Lcm(int a, int b)
        {
            return a / Gcm(a, b) * b;
        }

        int GetFirstIndexGreater(long x, ref List<long> listOrdered)
        {
            var count = listOrdered.Count;

            if (count == 0)
                return 0;

            if (listOrdered[count - 1] <= x)
                return count;

            int low = 0;
            int high = listOrdered.Count - 1;

            while (low < high)
            {
                var mid = (low + high) / 2;

                if (listOrdered[mid] > x)
                    high = mid;
                else
                    low = mid + 1;
            }

            return low;
        }

        int GetFirstIndexGreater(int x, ref List<int> listOrdered)
        {
            var count = listOrdered.Count;

            if (count == 0)
                return 0;

            if (listOrdered[count - 1] <= x)
                return count;

            int low = 0;
            int high = listOrdered.Count - 1;

            while (low < high)
            {
                var mid = (low + high) / 2;

                if (listOrdered[mid] > x)
                    high = mid;
                else
                    low = mid + 1;
            }

            return low;
        }

        int GetLastIndexLess(long x, ref List<long> listOrdered)
        {
            var count = listOrdered.Count;

            if (count == 0)
                return -1;

            if (listOrdered[0] >= x)
                return -1;

            int low = 0;
            int high = listOrdered.Count - 1;

            while (low < high)
            {
                var mid = (low + high + 1) / 2;

                if (listOrdered[mid] < x)
                    low = mid;
                else
                    high = mid - 1;
            }

            return low;
        }

        int GetLastIndexLess(int x, ref List<int> listOrdered)
        {
            var count = listOrdered.Count;

            if (count == 0)
                return -1;

            if (listOrdered[0] >= x)
                return -1;

            int low = 0;
            int high = listOrdered.Count - 1;

            while (low < high)
            {
                var mid = (low + high + 1) / 2;

                if (listOrdered[mid] < x)
                    low = mid;
                else
                    high = mid - 1;
            }

            return low;
        }
    }

    class Mod
    {
        readonly int _divider = 1000000007;
        public Mod(int divider = 1000000007)
        {
            _divider = divider;
        }

        public int Add(int a, int b) => (int)Add((long)a, (long)b);
        public int Sub(int a, int b) => (int)Sub((long)a, (long)b);
        public int Mul(int a, int b) => (int)Mul((long)a, (long)b);
        public int Div(int a, int b) => (int)Div((long)a, (long)b);
        public int Pow(int a, int p) => (int)Pow((long)a, (long)p);

        public long Add(long a, long b) => (a + b) % _divider;

        public long Sub(long a, long b)
        {
            var t = (a - b) % _divider;
            if (t < 0)
                t += _divider;
            return t;
        }

        public long Mul(long a, long b) => (a * b) % _divider;

        public long Div(long a, long b) => Mul(a, Inv(b));

        public long Pow(long a, long p)
        {
            switch (p)
            {
                case 0: return 1;
                case 1: return a;
                default:
                    var halfP = p / 2;
                    var halfPowered = Pow(a, halfP);
                    var powered = Mul(halfPowered, halfPowered);
                    return p % 2 == 0 ? powered : Mul(powered, a);
            }
        }

        readonly Dictionary<long, long> invCache = new Dictionary<long, long>();
        long Inv(long a)
        {
            long cache = 0L;
            if (invCache.TryGetValue(a, out cache))
                return cache;

            var result = Pow(a, _divider - 2);
            invCache.Add(a, result);
            return result;
        }

        readonly List<int> facCache = new List<int>() { 1 };
        public int Fac(int a)
        {
            if (a < facCache.Count)
                return facCache[a];

            var val = facCache.Last();
            var start = facCache.Count;
            for (int i = start; i <= a; i++)
            {
                val = Mul(val, i);
                facCache.Add(val);
            }

            return val;
        }

        public int Perm(int n, int r)
        {
            if (n < r)
                return 0;

            if (r <= 0)
                return 1;

            int nn = Fac(n);
            int nr = Fac(n - r);
            return Div(nn, nr);
        }

        public int Comb(int n, int r)
        {
            if (n < r)
                return 0;

            if (n == r)
                return 1;

            int nn = Fac(n);
            int nr = Fac(n - r);
            int rr = Fac(r);
            return Div(Div(nn, nr), rr);
        }
    }
}