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: Wrong Answer)

//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long lng;
typedef long long ll;
typedef vector<int> vi;
typedef vector<lng> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<lng> > vvl;
typedef pair<int,int> pi;
typedef pair<lng,lng> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////
ll n,k;
ll a[200020];
vector<int> pos[200020];
pair<ll,ll> _next[200020][63];

pair<ll,ll> getnext(int i,int j){
    return _next[i][j];
}
ll getnextid(int now,int x){
    return _next[now][x].first;
}
ll getroupe(int now,int x){
    return _next[now][x].second;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> k;
    rep(i,n){
        cin >> a[i];
        pos[a[i]].pb(i);
    } 
    rep(i,63){
        rep(j,200020){
            if(pos[j].size()){
                rep(k,pos[j].size()){
                    if(i == 0){
                        if(k == pos[j].size()-1){
                            _next[pos[j][k]][i] = make_pair((pos[j][0] + 1)%n,1);
                        }else{
                            _next[pos[j][k]][i] = make_pair((pos[j][k+1] + 1)%n,pos[j][k+1]+1>=n);
                        }
                    }else{
                        auto y = getnext(pos[j][k],i-1);
                        _next[pos[j][k]][i] = make_pair(getnextid(y.first,i-1) , y.second + getroupe(y.first,i-1));
                    }
                }
            }
        }
    }
    //return 0;
    ll now = 0;
    ll rp = 0;
    while(rp < k-1){
        int l = 0,r = 64;
        while(l + 1 != r){
            int m = (l + r) / 2;
            if(getroupe(now,m) >= LONG_MAX - rp){
                r = m;
                continue;
            }
            if(rp + getroupe(now,m) <= k-1){
                l = m;
            }else{
                r = m;
            }
        }
        rp += getroupe(now, l);
        now = getnextid(now , l);
    }
    stack<int> st;
    vector<bool> used(200020,false);
    for(int i = now;i < n;i++){
        if(!used[a[i]]) st.push(a[i]),used[a[i]] = true;
        else{
            while(st.top() != a[i]){
                used[st.top()] = false;
                st.pop();
            }
            st.pop();
            used[a[i]] = false;
        }
    }
    vector<int> ans;
    while(!st.empty()){
        ans.pb(st.top());
        st.pop();
    }
    if(ans.size())reverse(all(ans));
    for(int i = 0;i < ans.size();i++){
        if(!i)cout<< ans[i];
        else cout << ' ' << ans[i];
    }
    cout << '\n';
    return 0;
}