Problem: Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coincides character by character with its second half. Bob started deleting all the repeats from the string. He does it as follows: while it's possible, Bob takes the shortest repeat, if it is not unique, he takes the leftmost one, and deletes its left half and everything that is to the left of this repeat.

You're given the string seen by Bob. Find out, what it will look like after Bob deletes all the repeats in the way described above.

Input

The first input line contains integer n (1 ≤ n ≤ 105) — length of the string. The following line contains n space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.

Output

In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.

Examples

Input

6
1 2 3 1 2 3


Output

3
1 2 3 


Input

7
4 5 6 5 6 7 7


Output

1
7 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
vector<pair<int, int> > v;
template <typename Ty>
struct SuffixArray {
  vector<Ty> in;
  vector<int> out;
  template <typename Pt>
  SuffixArray(Pt begin, Pt end) : in(begin, end) {}
  vector<int> build() {
    int n = (int)in.size(), c = 0;
    vector<int> temp(n), pos2bckt(n), bckt(n), bpos(n);
    out.resize(n);
    for (int i = 0; i < n; i++) out[i] = i;
    sort(out.begin(), out.end(), [&](int a, int b) { return in[a] < in[b]; });
    for (int i = 0; i < n; i++) {
      bckt[i] = c;
      if (i + 1 == n || in[out[i]] != in[out[i + 1]]) c++;
    }
    for (int h = 1; h < n && c < n; h <<= 1) {
      for (int i = 0; i < n; i++) pos2bckt[out[i]] = bckt[i];
      for (int i = n - 1; i >= 0; i--) bpos[bckt[i]] = i;
      for (int i = 0; i < n; i++)
        if (out[i] >= n - h) temp[bpos[bckt[i]]++] = out[i];
      for (int i = 0; i < n; i++)
        if (out[i] >= h) temp[bpos[pos2bckt[out[i] - h]]++] = out[i] - h;
      c = 0;
      for (int i = 0; i < n; i++) {
        int a = (i + 1 == n) || (bckt[i] != bckt[i + 1]) ||
                (temp[i] >= n - h) ||
                pos2bckt[temp[i + 1] + h] != pos2bckt[temp[i] + h];
        bckt[i] = c;
        c += a;
      }
      temp.swap(out);
    }
    return out;
  }
  vector<int> lcparray() {
    if (in.size() != out.size()) build();
    int n = (int)in.size();
    vector<int> rank(n);
    vector<int> height(n - 1);
    for (int i = 0; i < n; i++) rank[out[i]] = i;
    int h = 0;
    for (int i = 0; i < n; i++) {
      if (rank[i] == 0) continue;
      int j = out[rank[i] - 1];
      while (i + h < n && j + h < n && in[i + h] == in[j + h]) h++;
      height[rank[i] - 1] = h;
      if (h > 0) h--;
    }
    return height;
  }
};
vector<int> sfx, lcp;
int rev[100005], lg[100005];
int spt[17][100005];
int getlcp(int x, int y) {
  x = rev[x], y = rev[y];
  if (x > y) swap(x, y);
  int l = lg[y - x];
  return min(spt[l][x], spt[l][y - (1 << l)]);
}
bool ok(int s, int e) {
  if (2 * s < e) return 0;
  return getlcp(s - (e - s) + 1, s + 1) >= e - s;
}
vector<pair<int, int> > ls[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    lg[i] = lg[i - 1];
    while ((2 << lg[i]) <= i) lg[i]++;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v.emplace_back(a[i], i);
  }
  SuffixArray<int> sa(a + 1, a + n + 1);
  sfx = sa.build();
  lcp = sa.lcparray();
  for (int i = 0; i < n; i++) {
    rev[sfx[i] + 1] = i;
    if (i < n - 1) spt[0][i] = lcp[i];
  }
  for (int i = 1; i < 17; i++) {
    for (int j = 0; j < n - 1; j++) {
      spt[i][j] = spt[i - 1][j];
      if (j + (1 << (i - 1)) < n - 1)
        spt[i][j] = min(spt[i - 1][j], spt[i - 1][j + (1 << (i - 1))]);
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size();) {
    int e = i;
    while (e < v.size() && v[e].first == v[i].first) e++;
    for (int j = i; j < e; j++) {
      for (int k = j - 1; k >= i; k--) {
        if (ok(v[k].second, v[j].second)) {
          ls[v[j].second - v[k].second].emplace_back(v[k].second, v[j].second);
          break;
        }
      }
    }
    i = e;
  }
  int ep = 0;
  for (int i = 1; i <= n; i++) {
    sort(ls[i].begin(), ls[i].end());
    for (auto &j : ls[i]) {
      if (ep <= j.first - (j.second - j.first)) {
        ep = j.first;
      }
    }
  }
  printf("%d\n", n - ep);
  for (int i = ep + 1; i <= n; i++) {
    printf("%d ", a[i]);
  }
}