#include <bits/stdc++.h>
using namespace std;
const int QQ = 3e5 + 10;
const int maxN = 3e5 + 100;
const int maxM = 3e5 + 10;
const long long oo = 1e15;
const int module = 1e9 + 7;
const long double du = 1e-9;
void doc() {
  freopen(
      "solve"
      ".inp",
      "r", stdin);
  freopen(
      "solve"
      ".out",
      "w", stdout);
}
void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  vector<int> B;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    B.push_back(a[i]);
  }
  sort(B.begin(), B.end());
  B.resize(unique(B.begin(), B.end()) - B.begin());
  int D[n + 1];
  memset(D, -1, sizeof(D));
  int L = 0, R = -1;
  int Pos = 0;
  int tmp[n + 1];
  for (int i = 0; i < n; i++) {
    int id = lower_bound(B.begin(), B.end(), a[i]) - B.begin();
    if (D[id] != -1) continue;
    if (R - L + 1 >= k) {
      int pre_id = lower_bound(B.begin(), B.end(), tmp[L]) - B.begin();
      D[pre_id] = -1;
      L++;
    }
    D[id] = Pos;
    Pos++;
    R++;
    tmp[R] = a[i];
  }
  vector<int> Res;
  for (int i = 0; i < (int)B.size(); i++) {
    if (D[i] != -1) Res.push_back(i);
  }
  sort(Res.begin(), Res.end(), [&](int i, int j) { return D[i] > D[j]; });
  cout << (int)Res.size() << '\n';
  for (int x : Res) cout << B[x] << ' ';
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
}

### Prompt

Please formulate a cpp solution to the following problem:

The only difference between easy and hard versions are constraints on n and k.

You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0).

Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.

You (suddenly!) have the ability to see the future. You know that during the day you will receive n messages, the i-th message will be received from the friend with ID id_i (1 ≤ id_i ≤ 10^9).

If you receive a message from id_i in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.

Otherwise (i.e. if there is no conversation with id_i on the screen):

  * Firstly, if the number of conversations displayed on the screen is k, the last conversation (which has the position k) is removed from the screen. 
  * Now the number of conversations on the screen is guaranteed to be less than k and the conversation with the friend id_i is not displayed on the screen. 
  * The conversation with the friend id_i appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. 



Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all n messages.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 2 ⋅ 10^5) — the number of messages and the number of conversations your smartphone can show.

The second line of the input contains n integers id_1, id_2, ..., id_n (1 ≤ id_i ≤ 10^9), where id_i is the ID of the friend which sends you the i-th message.

Output

In the first line of the output print one integer m (1 ≤ m ≤ min(n, k)) — the number of conversations shown after receiving all n messages.

In the second line print m integers ids_1, ids_2, ..., ids_m, where ids_i should be equal to the ID of the friend corresponding to the conversation displayed on the position i after receiving all n messages.

Examples

Input


7 2
1 2 3 2 1 3 2


Output


2
2 1 


Input


10 4
2 3 3 1 1 2 1 2 3 3


Output


3
1 3 2 

Note

In the first example the list of conversations will change in the following way (in order from the first to last message):

  * []; 
  * [1]; 
  * [2, 1]; 
  * [3, 2]; 
  * [3, 2]; 
  * [1, 3]; 
  * [1, 3]; 
  * [2, 1]. 



In the second example the list of conversations will change in the following way:

  * []; 
  * [2]; 
  * [3, 2]; 
  * [3, 2]; 
  * [1, 3, 2]; 
  * and then the list will not change till the end. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int QQ = 3e5 + 10;
const int maxN = 3e5 + 100;
const int maxM = 3e5 + 10;
const long long oo = 1e15;
const int module = 1e9 + 7;
const long double du = 1e-9;
void doc() {
  freopen(
      "solve"
      ".inp",
      "r", stdin);
  freopen(
      "solve"
      ".out",
      "w", stdout);
}
void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  vector<int> B;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    B.push_back(a[i]);
  }
  sort(B.begin(), B.end());
  B.resize(unique(B.begin(), B.end()) - B.begin());
  int D[n + 1];
  memset(D, -1, sizeof(D));
  int L = 0, R = -1;
  int Pos = 0;
  int tmp[n + 1];
  for (int i = 0; i < n; i++) {
    int id = lower_bound(B.begin(), B.end(), a[i]) - B.begin();
    if (D[id] != -1) continue;
    if (R - L + 1 >= k) {
      int pre_id = lower_bound(B.begin(), B.end(), tmp[L]) - B.begin();
      D[pre_id] = -1;
      L++;
    }
    D[id] = Pos;
    Pos++;
    R++;
    tmp[R] = a[i];
  }
  vector<int> Res;
  for (int i = 0; i < (int)B.size(); i++) {
    if (D[i] != -1) Res.push_back(i);
  }
  sort(Res.begin(), Res.end(), [&](int i, int j) { return D[i] > D[j]; });
  cout << (int)Res.size() << '\n';
  for (int x : Res) cout << B[x] << ' ';
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
}

```