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 maxn = 1e5 + 10;
struct SuffixArrary {
  int s[maxn];
  int sa[maxn], rk[maxn], tp[maxn], c[maxn], height[maxn];
  int n;
  void radixsort(int n, int m) {
    for (int i = 0; i <= m; ++i) c[i] = 0;
    for (int i = 1; i <= n; ++i) ++c[rk[i]];
    for (int i = 1; i <= m; ++i) c[i] += c[i - 1];
    for (int i = n; i >= 1; --i) sa[c[rk[tp[i]]]--] = tp[i];
  }
  void build_sa(int n, int m) {
    for (int i = 1; i <= n; ++i) {
      rk[i] = s[i], tp[i] = i;
    }
    radixsort(n, m);
    for (int k = 1; k <= n; k <<= 1) {
      int p = 0;
      for (int i = n - k + 1; i <= n; ++i) tp[++p] = i;
      for (int i = 1; i <= n; ++i) {
        if (sa[i] > k) tp[++p] = sa[i] - k;
      }
      radixsort(n, m);
      swap(rk, tp);
      p = rk[sa[1]] = 1;
      for (int i = 2; i <= n; ++i) {
        rk[sa[i]] =
            (tp[sa[i]] == tp[sa[i - 1]] && tp[sa[i] + k] == tp[sa[i - 1] + k])
                ? p
                : ++p;
      }
      if (p >= n) break;
      m = p;
    }
    int k = 0;
    for (int i = 1; i <= n; ++i) {
      if (k) --k;
      int j = sa[rk[i] - 1];
      while (s[i + k] == s[j + k]) ++k;
      height[rk[i]] = k;
    }
  }
  int dp[maxn][20];
  void init_rmq(int n) {
    for (int i = 1; i <= n; ++i) {
      dp[i][0] = height[i];
    }
    for (int j = 1; (1 << j) <= n; ++j) {
      for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
        dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  inline int rmq(int l, int r) {
    int k = 31 - __builtin_clz(r - l + 1);
    return min(dp[l][k], dp[r - (1 << k) + 1][k]);
  }
  inline int lcp(int l, int r) {
    if (l == r) return n - l + 1;
    l = rk[l], r = rk[r];
    if (l > r) swap(l, r);
    return rmq(l + 1, r);
  }
} sa;
vector<vector<int> > vec(maxn);
unordered_map<int, int> mp;
int a[maxn];
struct Node {
  int pos, len;
} b[maxn];
inline bool cmp(const Node &a, const Node &b) {
  if (a.len == b.len) return a.pos < b.pos;
  return a.len < b.len;
}
int main() {
  int n, tot = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (!mp.count(a[i])) mp[a[i]] = tot++;
  }
  for (int i = 1; i <= n; ++i) {
    sa.s[i] = mp[a[i]];
    vec[sa.s[i]].push_back(i);
  }
  sa.s[n + 1] = -1;
  sa.build_sa(n, tot);
  sa.init_rmq(n);
  int cnt = 0;
  for (int i = 1, x, y; i <= n; ++i) {
    x = sa.s[i];
    if ((int)vec[x].size() <= 1) continue;
    for (auto it = vec[x].begin(); it != vec[x].end(); ++it) {
      y = *it;
      if (y <= i) continue;
      int len = y - i;
      if (i >= len && sa.lcp(i - len + 1, y - len + 1) >= len) {
        b[++cnt].pos = i, b[cnt].len = len;
        break;
      }
    }
  }
  sort(b + 1, b + cnt + 1, cmp);
  int pos = 1;
  for (int i = 1; i <= cnt; ++i) {
    int tmp = b[i].pos - b[i].len + 1;
    if (tmp >= pos) pos = b[i].pos + 1;
  }
  printf("%d\n", n - pos + 1);
  for (int i = pos; i <= n; ++i) {
    printf("%d%c", a[i], (i == n) ? '\n' : ' ');
  }
  return 0;
}