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>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5;
int n, a[N], b[N], lst;
vector<int> g[N];
bool done[N];
void compress() {
  map<int, int> com;
  int id = 0;
  for (int i = 0; i < n; i++) com[a[i]] = 1;
  for (auto &i : com) i.second = id++;
  for (int i = 0; i < n; i++) a[i] = com[a[i]];
}
const int b1 = 37, b2 = 31;
const int mod = 1e9 + 7;
int pw1[N], inv1[N];
int pw2[N], inv2[N];
int pref1[N], pref2[N];
int fp(int x, int y) {
  if (!y) return 1;
  int res = fp(x, y / 2);
  res = (1ll * res * res) % mod;
  if (y & 1) res = (1ll * res * x) % mod;
  return res;
}
void pre() {
  pw1[0] = inv1[0] = 1;
  pw2[0] = inv2[0] = 1;
  int minv1 = fp(b1, mod - 2);
  int minv2 = fp(b2, mod - 2);
  for (int i = 1; i < N; i++) {
    pw1[i] = (1ll * b1 * pw1[i - 1]) % mod;
    pw2[i] = (1ll * b2 * pw2[i - 1]) % mod;
    inv1[i] = (1ll * minv1 * inv1[i - 1]) % mod;
    inv2[i] = (1ll * minv2 * inv2[i - 1]) % mod;
  }
}
pair<int, int> get(int l, int r) {
  int ans1 = pref1[r], ans2 = pref2[r];
  if (l) {
    ans1 = (ans1 - pref1[l - 1] + mod) % mod;
    ans2 = (ans2 - pref2[l - 1] + mod) % mod;
  }
  ans1 = (1ll * ans1 * inv1[l]) % mod;
  ans2 = (1ll * ans2 * inv2[l]) % mod;
  return {ans1, ans2};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i];
  compress();
  pre();
  for (int i = 0; i < n; i++) {
    int c = a[i] + 1;
    pref1[i] = (1ll * c * pw1[i]) % mod;
    pref2[i] = (1ll * c * pw2[i]) % mod;
    if (i) {
      pref1[i] = (pref1[i] + pref1[i - 1]) % mod;
      pref2[i] = (pref2[i] + pref2[i - 1]) % mod;
    }
  }
  for (int i = 0; i < n; i++) g[a[i]].push_back(i);
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    if (done[a[i]]) continue;
    done[a[i]] = true;
    for (int j = 0; j < g[a[i]].size(); j++)
      for (int k = j + 1; k < g[a[i]].size(); k++)
        if (g[a[i]][k] + (g[a[i]][k] - g[a[i]][j]) <= n)
          v.push_back({g[a[i]][k] - g[a[i]][j], g[a[i]][j]});
  }
  sort(v.begin(), v.end());
  for (auto &i : v)
    if (i.second >= lst &&
        get(i.second, i.second + i.first - 1) ==
            get(i.second + i.first, 2 * i.first + i.second - 1))
      lst = i.first + i.second;
  cout << n - lst << '\n';
  for (int i = lst; i < n; i++) cout << b[i] << " ";
  return 0;
}