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;
long long LIMIT = 1e5 + 5;
long long P1 = 1e5 + 5, P2 = 1e5 + 11;
long long MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
vector<long long> pw1(LIMIT, 0);
vector<long long> pw2(LIMIT, 0);
vector<long long> mpw1(LIMIT, 0);
vector<long long> mpw2(LIMIT, 0);
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modInverse(long long n, long long p) {
  return power(n, p - 2, p) % p;
}
void preprocess() {
  pw1[0] = 1;
  pw2[0] = 1;
  for (long long i = 1; i < LIMIT; i++) {
    pw1[i] = pw1[i - 1] * P1;
    pw1[i] %= MOD1;
    pw2[i] = pw2[i - 1] * P2;
    pw2[i] %= MOD2;
    mpw1[i] = modInverse(pw1[i], MOD1);
    mpw2[i] = modInverse(pw2[i], MOD2);
  }
}
class Hashing {
 public:
  vector<long long> text;
  long long N;
  std::vector<pair<long long, long long>> rollingHash;
  Hashing(vector<long long> st) {
    text = st;
    N = text.size();
    rollingHash.resize(LIMIT);
    preprocess();
  }
  void preprocess() {
    long long Hash1 = 0, Hash2 = 0;
    for (long long i = 0; i < N; i++) {
      long long ind = text[i] + 1;
      Hash1 = (Hash1 + (ind * pw1[i])) % MOD1;
      Hash2 = (Hash2 + (ind * pw2[i])) % MOD2;
      rollingHash[i] = make_pair(Hash1, Hash2);
    }
  }
  pair<long long, long long> getHash(long long i, long long j) {
    if (i == 0) {
      return rollingHash[j];
    } else {
      long long p1 =
          ((rollingHash[j].first - rollingHash[i - 1].first) % MOD1 + MOD1) %
          MOD1;
      long long p2 =
          ((rollingHash[j].second - rollingHash[i - 1].second) % MOD2 + MOD2) %
          MOD2;
      p1 = (p1 * mpw1[i]) % MOD1;
      p2 = (p2 * mpw2[i]) % MOD2;
      return {p1, p2};
    }
  }
};
void normalize(vector<long long>& arr) {
  set<long long> st(arr.begin(), arr.end());
  map<long long, long long> index;
  long long ind = 1;
  for (long long i : st) index[i] = ind++;
  for (long long i = 0; i < (long long)(arr.size()); i++) {
    arr[i] = index[arr[i]];
  }
}
void solve() {
  preprocess();
  long long N;
  cin >> N;
  vector<long long> arr(N);
  normalize(arr);
  for (long long i = 0; i < N; i++) cin >> arr[i];
  Hashing hash(arr);
  long long start = 0;
  map<long long, long long> last;
  for (long long i = 0; i < N; i++) {
    if (last.count(arr[i])) {
      long long diff = i - last[arr[i]];
      long long pref = last[arr[i]] - start + 1;
      if (pref < diff) {
        last[arr[i]] = i;
        continue;
      }
      pair<long long, long long> Hash1 = hash.getHash(last[arr[i]] + 1, i);
      pair<long long, long long> Hash2 =
          hash.getHash(last[arr[i]] - diff + 1, last[arr[i]]);
      if (Hash1 == Hash2) {
        long long end = last[arr[i]] + 1;
        while (start < end) {
          if (last[arr[start]] == start) {
            last.erase(arr[start]);
          }
          start++;
        }
        last[arr[i]] = i;
      } else {
        last[arr[i]] = i;
      }
    } else {
      last[arr[i]] = i;
    }
  }
  cout << N - start << endl;
  for (long long i = start; i < N; i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}