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: Runtime Error)

//#define DEB1 //output check function
//#define DEB2 //same output, input from input.txt

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <sstream>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);--i)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);++i)
#define RNG(i,start,fin) for(int i=(start);i<(fin);++i)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;

/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


#ifdef DEB1
#define DPRINT(x) cout<< #x << "=" << (x) << endl; // print at debug mode
#else
#define DPRINT(x) ;
#endif
#ifdef DEB1
#define DCHECK(x) cout<< "debug check" << #x << endl;
#else
#define DCHECK(x) ;
#endif
 


/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    int N; cin >> N;
    LL K; cin >> K;
    int max_k = log2(N*K);

    map<int,VI> key_id; //key_id

    VLL tmp(N,-1);
    DPRINT(max_k)
    vector<VLL> next(max_k+1,tmp);

    // input, next[0][]
    VI A(N*2);
    REP(i,2*N){
        if(i<N){
            cin >> A[i];
            A[N+i]=A[i]; // 1 2 3 2 3 1 2 3 2 3
        }
        // same exist before
        if(key_id.count(A[i])!=0){
            int id = key_id[A[i]].back(); //- - - 1 2, 0 3 4 ..  
            DPRINT(id)
            if (id<N) next[0][id] = i - id + 1;
        }
        // add key
        key_id[A[i]].PB(i);
         //several id for one key
    }
    // doubling
    REP(k,max_k){
        DPRINT(k)
        REP(i,N){
            LL nowid = i + next[k][i];
            DPRINT(nowid)
            LL nextid = nowid + next[k][nowid%N];
           // DPRINT(nextid)
            next[k+1][i] = nextid - i;
            //DPRINT(nextid)
        }
    }
    //change out of range to -1
    REP(k,max_k){
        REP(i,N){
            if(next[k][i]+i > N*K) next[k][i] = -1;
        }
    }

    //start from id = 0
    LL gid = 0; // global id
    CIREP(k,max_k,0){
        DPRINT(k)
        int id = gid%N; // id in a Line
        LL nextid = gid + next[k][id];
        //DPRINT(nextid)
        if(next[k][id]!=-1 && nextid < N*K){
            gid = nextid;
        }
        //DPRINT(id)
    }

    // Do as the task
    int id = gid%N;
    DPRINT(id)
    VI ans;

    CREP(i,id,N-1){
        //already deleted
        int stop = next[0][i]+i-1;
        
        if(next[0][i]==-1){
            continue;
        }
        
        //do not appear
        if(stop >= N){
            DPRINT(i)
            int a = A[i];
            //ans.PB(A[i]);
        }
        //appear
         
        else{
            CREP(j,i,stop){
                DPRINT(j)
                next[0][j] = -1; //delete
            }
        }
        
    }
    REP(i,SZ(ans)) cout<<ans[i]<< " ";
    cout << endl;

}



// ----------------------------------------------
int main() {

#ifdef DEB2
    cout << "DEBUG MODE"  << endl;
	ifstream in("input.txt"); //for debug
	cin.rdbuf(in.rdbuf()); //for debug
#endif

	int T=1; 

	for (int i = 0; i < T; ++i) {
		solve();
	}
}