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 long long INF = 1000000007;
const long long INFLL = 100000000000000000ll;
const long long MOD = 1000000007;
const int MAX = 200005;
const int RIGHT = 262144;
const int SIZE = 550000;
int C[MAX], S[MAX], SA[MAX], RA[MAX], TRA[MAX], TSA[MAX], Phi[MAX], LCP[MAX],
    PLCP[MAX], N, T[SIZE], Inv[MAX];
set<int> Numbers;
unordered_map<int, int> Orig;
vector<int> Pos[MAX];
void countSort(int k) {
  int sz = max(255, N);
  for (int i = (0); i <= (sz); i++) C[i] = 0;
  for (int i = (0); i <= (N - 1); i++) C[RA[i + k]]++;
  int sum = 0;
  for (int i = (0); i <= (sz); i++) {
    int t = C[i];
    C[i] = sum;
    sum += t;
  }
  for (int i = (0); i <= (N - 1); i++) TSA[C[RA[SA[i] + k]]++] = SA[i];
  for (int i = (0); i <= (N - 1); i++) SA[i] = TSA[i];
}
void suffixArray() {
  N++;
  for (int i = (0); i <= (N - 1); i++) SA[i] = i, RA[i] = S[i];
  for (int k = 1; k < N; k *= 2) {
    countSort(k);
    countSort(0);
    TRA[SA[0]] = 0;
    for (int i = (1); i <= (N - 1); i++)
      TRA[SA[i]] =
          RA[SA[i]] == RA[SA[i - 1]] && RA[SA[i] + k] == RA[SA[i - 1] + k]
              ? TRA[SA[i - 1]]
              : i;
    for (int i = (0); i <= (N - 1); i++) RA[i] = TRA[i];
  }
}
void getLCP() {
  Phi[SA[0]] = -1;
  for (int i = (1); i <= (N - 1); i++) Phi[SA[i]] = SA[i - 1];
  int l = 0;
  for (int i = (0); i <= (N - 1); i++) {
    if (Phi[i] == -1) {
      PLCP[i] = 0;
      continue;
    }
    while (S[i + l] == S[Phi[i] + l]) l++;
    PLCP[i] = l;
    l = max(0, l - 1);
  }
  for (int i = (0); i <= (N - 1); i++) LCP[i] = PLCP[SA[i]];
}
int compress() {
  unordered_map<int, int> m;
  int c = 0;
  for (int k : Numbers) {
    m[k] = ++c;
    Orig[c] = k;
  }
  for (int i = (0); i <= (N - 1); i++) S[i] = m[S[i]];
  return c;
}
void update(int x, int v, int n, int a, int b) {
  if (a > x || b < x) return;
  if (a == b) {
    T[n] = v;
    return;
  }
  int mid = (a + b) / 2;
  update(x, v, 2 * n, a, mid);
  update(x, v, 2 * n + 1, mid + 1, b);
  T[n] = min(T[2 * n], T[2 * n + 1]);
}
int query(int l, int r, int n, int a, int b) {
  if (l > r) return query(r, l, n, a, b);
  if (a > r || b < l) return N + 1;
  if (a >= l && b <= r) return T[n];
  int mid = (a + b) / 2;
  return min(query(l, r, 2 * n, a, mid), query(l, r, 2 * n + 1, mid + 1, b));
}
int main() {
  cin >> N;
  for (int i = (0); i <= (N - 1); i++) {
    scanf("%d", &S[i]);
    Numbers.insert(S[i]);
  }
  int nums = compress();
  suffixArray();
  getLCP();
  for (int i = (0); i <= (N - 1); i++) Inv[SA[i]] = i;
  for (int i = (N - 1); i >= (0); i--) Pos[S[i]].push_back(i);
  int left = 0;
  vector<pair<long long, long long>> pairs;
  for (int i = (1); i <= (nums); i++)
    for (int p1 : Pos[i])
      for (int p2 : Pos[i])
        if (p2 > p1) pairs.push_back({p2 - p1, p2});
  sort(pairs.begin(), pairs.end());
  int last = 0;
  while (true) {
    int cut = -1;
    for (int i = (last); i <= (((int)pairs.size()) - 1); i++) {
      int len = pairs[i].first;
      int p1 = pairs[i].second - len;
      int p2 = pairs[i].second;
      if (p1 < left || p2 < left) continue;
      int lcp;
      int idx1 = Inv[p1], idx2 = Inv[p2];
      if (idx1 > idx2) swap(idx1, idx2);
      lcp = N + 1;
      for (int k = (idx1 + 1); k <= (idx2); k++) lcp = min(lcp, LCP[k]);
      if (lcp >= len) {
        cut = p2;
        last = i;
        break;
      }
    }
    if (cut >= 0)
      left = cut;
    else
      break;
  }
  cout << N - left - 1 << "\n";
  for (int i = (left); i <= (N - 2); i++) printf("%d ", Orig[S[i]]);
}