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;
int n, m;
int i, j, k, l;
const int N = 1e5 + 5;
int len[N * 2], link[N * 2];
map<int, int> to[N * 2];
int fin[N * 2];
set<int> ins[N * 2];
int d;
bool cmp_sa(int i, int j) { return len[i] < len[j]; };
int a[N];
int t[N * 2];
int rep[N];
int main() {
  scanf("%d", &n);
  link[0] = -1;
  l = 0;
  d = 1;
  for (i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[i] = x;
    int c = d++;
    len[c] = len[l] + 1;
    fin[c] = i;
    for (; l >= 0 && to[l][x] == 0; l = link[l]) to[l][x] = c;
    if (l >= 0) {
      int p = to[l][x];
      if (len[p] == len[l] + 1)
        link[c] = p;
      else {
        int q = d++;
        len[q] = len[l] + 1;
        link[q] = link[p];
        to[q] = to[p];
        fin[q] = fin[p];
        for (; l >= 0 && to[l].count(x) && to[l][x] == p; l = link[p])
          to[l][x] = q;
        link[c] = link[p] = q;
      }
    }
    l = c;
  }
  for (i = 0; i < d; ++i) {
    t[i] = i;
    ins[i].insert(fin[i]);
  }
  sort(t, t + d, cmp_sa);
  memset(rep, 63, sizeof(rep));
  for (k = d - 1; k; --k) {
    i = t[k];
    j = link[i];
    if (ins[i].size() > ins[j].size()) ins[i].swap(ins[j]);
    for (typeof((ins[i]).begin()) it = (ins[i]).begin(); it != (ins[i]).end();
         it++) {
      int y = *it;
      ins[j].insert(y);
      if (*ins[j].begin() != y) {
        int x = *(--ins[j].find(y));
        if (y - x <= len[j])
          rep[x + 1] = ((rep[x + 1]) < (y - x) ? (rep[x + 1]) : (y - x));
      }
      if (*ins[j].rbegin() != y) {
        int x = *(++ins[j].find(y));
        if (x - y <= len[j])
          rep[y + 1] = ((rep[y + 1]) < (x - y) ? (rep[y + 1]) : (x - y));
      }
    }
    ins[i].clear();
  }
  set<pair<int, pair<int, int> > > q1;
  set<pair<pair<int, int>, int> > q2;
  for (i = 0; i < n; ++i)
    if (rep[i] < 1e9) {
      q1.insert(make_pair(rep[i], make_pair(i - rep[i], i + rep[i] - 1)));
      q2.insert(make_pair(make_pair(i - rep[i], i + rep[i] - 1), rep[i]));
    }
  k = 0;
  for (; q1.size();) {
    pair<int, pair<int, int> > pp = *q1.begin();
    l = pp.first;
    i = pp.second.first;
    j = pp.second.second;
    k = i + l;
    while (q2.size() && q2.begin()->first.first < k) {
      pair<pair<int, int>, int> qq = *q2.begin();
      q2.erase(qq);
      q1.erase(make_pair(qq.second, qq.first));
    }
  }
  printf("%d\n", n - k);
  for (i = k; i < n; ++i) printf("%d ", a[i]);
  printf("\n");
  return 0;
}