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++14 (GCC 5.4.1) (judge verdict: Accepted)

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("C:\\Users\\BOG\\CLionProjects\\EZZ\\kek.txt");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

ll a,k,sz;
vec<ll> m, nxt, lst, fir, emp;

void solve(){
    for(ll c = a-1-((sz-1)%a); sz;){
        ll p = nxt[c], nowdel = p==c ? a+1 : p>c ? p-c+1 : a+(p-c+1);
        if(nowdel<=sz) sz-=nowdel;
        else{
            lst = vec<ll>(3e5, 0);
            vec<ll> o;
            for(; c<a; c++){
                ll n = m[c];
                if(lst[n]==0){
                    lst[n] = 1;
                    o.pb(n);
                }
                else{
                    for(; o.back()!=n;){
                        lst[o.back()] = 0;
                        o.pop_back();
                    }
                    o.pop_back();
                    lst[n] = 0;
                }
            }
            for(ll i : o) cout<<i<<" ";
            return;
        }
        c = (p+1)%a;
    }
}

int main() {
    fast;
    cin>>a>>k;
    sz = a*k;
    m = vec<ll>(a);
    nxt = vec<ll>(a, -1);
    lst = vec<ll>(3e5, -1);
    fir = vec<ll>(3e5, -1);
    emp = vec<ll>(a, -1);
    for(int q=0; q<a; q++) cin>>m[q];
    for(int q=0; q<a; q++){
        if(fir[m[q]]==-1) fir[m[q]] = q;
        if(lst[m[q]]!=-1) nxt[lst[m[q]]] = q;
        lst[m[q]] = q;
    }
    for(int q=0; q<a; q++) if(nxt[q]==-1) nxt[q] = fir[m[q]];
    ll pred=0, per=0, cntdel=0, predd=0, perd=0;
    vec<ll> wasdel;
    for(ll xod=0, c=0; ; xod++){
        ll p = nxt[c];
        cntdel += p==c ? a+1 : p>c ? p-c+1 : a+(p-c+1);
        //cout<<"DEL: "<<cntdel<<endl;
        if(emp[p]==-1) emp[p] = xod, wasdel.pb(cntdel);
        else{
            per = xod - emp[p];
            pred = xod-per;
            predd = pred==0 ? 0 : wasdel[pred-1];
            perd = wasdel.back()-predd;
            break;
        }
        c = (p+1)%a;
    }
    //cout<<"PRED DEL: "<<predd<<endl;
    //cout<<"PER DEL: "<<perd<<endl;
    if(sz>=predd) sz-=predd, sz%=perd;
    solve();
}