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 iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
const int N = 1e5 + 100;
const long long base1 = 131ll;
const long long base2 = 137ll;
const long long mod1 = 1e9 + 7;
const long long mod2 = 998244353ll;
const int lgN = 20;
const int hN = 1 << lgN - 1;
int n;
int a[N];
map<int, int> M;
int RM[N];
int r[N];
vector<int> pos[N];
int tot;
namespace seg {
pair<int, int> num[1 << lgN];
void build() {
  for (int i = ((1 << lgN) - 1); i >= (0); i--) {
    if (i >= hN)
      num[i] =
          make_pair((1 <= i - hN && i - hN <= n) ? r[i - hN] : iinf, i - hN);
    else
      num[i] = min(num[i << 1], num[(i << 1) | 1]);
  }
  return;
}
inline pair<int, int> query(int s, int t) {
  s |= hN;
  t |= hN;
  pair<int, int> ret = make_pair(iinf, -1);
  for (s--, t++; s ^ t ^ 1; s >>= 1, t >>= 1) {
    if (~s & 1) ret = min(ret, num[s ^ 1]);
    if (t & 1) ret = min(ret, num[t ^ 1]);
  }
  return ret;
}
}  // namespace seg
long long hsh1[N], hsh2[N], pow1[N], pow2[N];
pair<long long, long long> get(int l, int r) {
  long long ret1 =
      ((hsh1[r] - hsh1[l - 1] * pow1[r - l + 1]) % mod1 + mod1) % mod1;
  long long ret2 =
      ((hsh2[r] - hsh2[l - 1] * pow2[r - l + 1]) % mod2 + mod2) % mod2;
  return make_pair(ret1, ret2);
}
bool check(int i, int j) {
  int len = j - i;
  if (j + len - 1 > n) return 0;
  return get(i, j - 1) == get(j, j + len - 1);
}
int main() {
  scf(n);
  for (int i = (1); i <= (n); i++) scf(a[i]), M[a[i]];
  for (auto it = M.begin(); it != M.end(); it++)
    tot++, it->second = tot, RM[tot] = it->first;
  for (int i = (1); i <= (n); i++) a[i] = M[a[i]], pos[a[i]].push_back(i);
  pow1[0] = pow2[0] = 1ll;
  for (int i = (1); i <= (n); i++) {
    pow1[i] = pow1[i - 1] * base1 % mod1;
    hsh1[i] = (hsh1[i - 1] * base1 + a[i]) % mod1;
    pow2[i] = pow2[i - 1] * base2 % mod2;
    hsh2[i] = (hsh2[i - 1] * base2 + a[i]) % mod2;
  }
  for (int i = (1); i <= (tot); i++) {
    for (int j = 0; j < ((int)pos[i].size()); j++) {
      r[pos[i][j]] = iinf;
      for (int k = (j + 1); k <= ((int)pos[i].size() - 1); k++) {
        if (check(pos[i][j], pos[i][k])) {
          r[pos[i][j]] = pos[i][k] - pos[i][j];
          break;
        }
      }
    }
  }
  for (int i = (1); i <= (n); i++) cerr << r[i] << ' ';
  cerr << endl;
  seg::build();
  int lb = 1;
  for (;;) {
    pair<int, int> tmp = seg::query(lb, n);
    if (tmp.first >= iinf) break;
    lb = tmp.first + tmp.second;
  }
  printf("%d\n", n - lb + 1);
  for (int i = (lb); i <= (n); i++) {
    printf("%d%c", RM[a[i]], i == n ? '\n' : ' ');
  }
  return 0;
}