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 = 100005;
int wa[maxn], wb[maxn], wv[maxn], Ws[maxn];
int cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(const int *r, int *sa, int n, int m) {
  int i, j, p, *x = wa, *y = wb, *t;
  for (i = 0; i < m; i++) Ws[i] = 0;
  for (i = 0; i < n; i++) Ws[x[i] = r[i]]++;
  for (i = 1; i < m; i++) Ws[i] += Ws[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--Ws[x[i]]] = i;
  for (j = 1, p = 1; p < n; j *= 2, m = p) {
    for (p = 0, i = n - j; i < n; i++) y[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    for (i = 0; i < n; i++) wv[i] = x[y[i]];
    for (i = 0; i < m; i++) Ws[i] = 0;
    for (i = 0; i < n; i++) Ws[wv[i]]++;
    for (i = 1; i < m; i++) Ws[i] += Ws[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--Ws[wv[i]]] = y[i];
    for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; i++)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
  }
  return;
}
int sa[maxn], Rank[maxn], height[maxn];
void calheight(const int *r, int *sa, int n) {
  int i, j, k = 0;
  for (i = 1; i <= n; i++) Rank[sa[i]] = i;
  for (i = 0; i < n; height[Rank[i++]] = k)
    for (k ? k-- : 0, j = sa[Rank[i] - 1]; r[i + k] == r[j + k]; k++)
      ;
  return;
}
int b[maxn];
int a[maxn];
int LOG[maxn];
int dp[20][maxn];
int Min(int a, int b) {
  if (a < b) return a;
  return b;
}
void RMQ(int m) {
  int i, j;
  LOG[0] = -1;
  for (i = 1; i <= m; i++) LOG[i] = LOG[i >> 1] + 1;
  for (i = 1; i <= m; i++) dp[0][i] = height[i];
  for (j = 1; j <= LOG[m]; j++) {
    int limit = m + 1 - (1 << j);
    for (i = 1; i <= limit; i++) {
      int x = i + (1 << j >> 1);
      dp[j][i] = Min(dp[j - 1][x], dp[j - 1][i]);
    }
  }
}
int lcp(int l, int r) {
  l = Rank[l];
  r = Rank[r];
  if (l > r) {
    int tmp = l;
    l = r;
    r = tmp;
  }
  l++;
  int m = LOG[r - l + 1];
  return Min(dp[m][l], dp[m][r - (1 << m) + 1]);
}
map<int, int> mp;
vector<int> num[maxn];
int tot;
struct Node {
  int p, len;
  Node(int p = 0, int len = 0) : p(p), len(len) {}
  bool operator<(const Node &t) const {
    if (len != t.len) return len > t.len;
    return p > t.p;
  }
};
priority_queue<Node> que;
int main() {
  int tp, t;
  int p, len;
  int n, m;
  int i, j, k;
  while (scanf("%d", &n) != EOF) {
    tot = 0;
    mp.clear();
    for (i = 0; i <= n; i++) num[i].clear();
    for (i = 0; i < n; i++) {
      scanf("%d", &tp);
      b[i] = tp;
      t = mp[tp];
      if (!t) t = mp[tp] = ++tot;
      a[i] = t;
      num[t].push_back(i);
    }
    a[n] = 0;
    da(a, sa, n + 1, tot + 1);
    calheight(a, sa, n);
    RMQ(n);
    for (i = 1; i <= tot; i++) {
      for (j = 0; j < num[i].size(); j++) {
        for (k = j + 1; k < num[i].size(); k++) {
          int x = num[i][j];
          int y = num[i][k];
          len = lcp(x, y);
          if (len < y - x) continue;
          que.push(Node(x, y - x));
        }
      }
    }
    int ans = 0;
    while (!que.empty()) {
      p = que.top().p;
      len = que.top().len;
      que.pop();
      if (ans <= p) ans = p + len;
    }
    printf("%d\n", n - ans);
    for (i = ans; i < n; i++) printf("%d ", b[i]);
    puts("");
  }
  return 0;
}