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;
const int N = (int)1e5 + 50, LOGN = 17, INF = (int)1e9;
int mm[N];
int n, k;
struct SA {
  int n;
  int rk[N], sa[N], ht[N];
  void build(int num[], int len) {
    n = len;
    static int set[N], a[N];
    for (int i = 1; i <= n; i++) set[i] = num[i];
    sort(set + 1, set + n + 1);
    int *end = unique(set + 1, set + n + 1);
    for (int i = 1; i <= n; i++)
      a[i] = (int)(lower_bound(set + 1, end, num[i]) - set);
    static int fir[N], sec[N], tmp[N], buc[N];
    fill(buc, buc + n + 1, 0);
    for (int i = 1; i <= n; i++) buc[a[i]]++;
    for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
    for (int i = 1; i <= n; i++) rk[i] = buc[a[i] - 1] + 1;
    for (int t = 1; t <= n; t *= 2) {
      for (int i = 1; i <= n; i++) fir[i] = rk[i];
      for (int i = 1; i <= n; i++) sec[i] = i + t > n ? 0 : rk[i + t];
      fill(buc, buc + n + 1, 0);
      for (int i = 1; i <= n; i++) buc[sec[i]]++;
      for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
      for (int i = 1; i <= n; i++) tmp[n - (--buc[sec[i]])] = i;
      fill(buc, buc + n + 1, 0);
      for (int i = 1; i <= n; i++) buc[fir[i]]++;
      for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
      for (int j = 1, i; j <= n; j++) i = tmp[j], sa[buc[fir[i]]--] = i;
      bool unique = true;
      for (int j = 1, i, last = 0; j <= n; j++) {
        i = sa[j];
        if (!last)
          rk[i] = 1;
        else if (fir[i] == fir[last] && sec[i] == sec[last])
          rk[i] = rk[last], unique = false;
        else
          rk[i] = rk[last] + 1;
        last = i;
      }
      if (unique) break;
    }
    for (int i = 1, k = 0; i <= n; i++) {
      if (rk[i] == 1)
        k = 0;
      else {
        if (k > 0) k--;
        int j = sa[rk[i] - 1];
        while (i + k <= n && j + k <= n && a[i + k] == a[j + k]) k++;
      }
      ht[rk[i]] = k;
    }
  }
} sa;
struct ST {
  int n;
  int st[LOGN + 1][N];
  void build() {
    n = sa.n + 1;
    for (int i = 0; i < n; i++) {
      st[0][i] = sa.ht[i];
    }
    for (int lg = 1; lg < LOGN; lg++) {
      for (int j = 0; j + (1 << lg) - 1 < n; j++) {
        st[lg][j] = min(st[lg - 1][j], st[lg - 1][j + (1 << (lg - 1))]);
      }
    }
  }
  int rmq(int l, int r) {
    int k = mm[r - l + 1];
    return min(st[k][l], st[k][r - (1 << k) + 1]);
  }
  int lcp(int l, int r) {
    if (l < r)
      return rmq(l + 1, r);
    else
      return rmq(r + 1, l);
  }
} st;
int num[N];
map<int, vector<int> > aper;
int find(int i) {
  int x = num[i];
  for (int loc : aper[x]) {
    if (loc > i && st.lcp(sa.rk[i], sa.rk[loc]) >= loc - i) return loc - i;
  }
  return -1;
}
int main() {
  mm[0] = -1;
  for (int i = 1; i < N; i++)
    mm[i] = (i & (i - 1)) == 0 ? mm[i - 1] + 1 : mm[i - 1];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
    aper[num[i]].push_back(i);
  }
  sa.build(num, n);
  st.build();
  vector<int> res;
  for (int i = 1; i <= n;) {
    int len = find(i);
    if (len == -1)
      res.push_back(num[i++]);
    else
      i += len, res.clear();
  }
  cout << res.size() << "\n";
  for (int x : res) cout << x << " ";
  cout << "\n";
}