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 = 1 << 28;
const long long LINF = 1ll << 61;
int n, lg2[100111];
struct suffix_array {
  int b[100111], a[100111], sa[100111], nsa[100111], rk[100111], nrk[100111];
  int lcp[100111];
  int tab[20][100111];
  void makeb() {
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) b[rk[i]]++;
    for (int i = 1; i <= n; i++) b[i] += b[i - 1];
  }
  pair<int, int> tmp[100111];
  void construct() {
    memset(tab, 0, sizeof(tab));
    memset(lcp, 0, sizeof(lcp));
    for (int i = 0; i < n; i++) tmp[i] = make_pair(a[i], i);
    sort(tmp, tmp + n);
    for (int i = 0; i < n; i++) sa[i] = tmp[i].second;
    rk[sa[0]] = 0;
    for (int i = 1; i < n; i++)
      rk[sa[i]] = rk[sa[i - 1]] + (a[sa[i - 1]] < a[sa[i]]);
    for (int k = 1; k < n; k <<= 1) {
      makeb();
      for (int i = n - 1; i >= 0; i--)
        if (sa[i] >= k) nsa[--b[rk[sa[i] - k]]] = sa[i] - k;
      for (int i = n - 1; i >= 0; i--)
        if (sa[i] >= n - k) nsa[--b[rk[sa[i]]]] = sa[i];
      nrk[nsa[0]] = 0;
      for (int i = 1; i < n; i++)
        nrk[nsa[i]] =
            nrk[nsa[i - 1]] +
            (make_pair(rk[nsa[i - 1]],
                       nsa[i - 1] + k >= n ? -1 : rk[nsa[i - 1] + k]) <
             make_pair(rk[nsa[i]], nsa[i] + k >= n ? -1 : rk[nsa[i] + k]));
      swap(rk, nrk);
      swap(sa, nsa);
    }
    for (int i = 0; i < n; i++) rk[sa[i]] = i;
    int h = 0;
    for (int i = 0; i < n; i++) {
      if (h > 0) h--;
      if (rk[i] == 0) continue;
      int j = sa[rk[i] - 1];
      while (i + h < n && j + h < n && a[i + h] == a[j + h]) h++;
      lcp[rk[i] - 1] = h;
    }
    for (int i = 0; i < n; i++) tab[0][i] = lcp[i];
    for (int i = 1; i < 20; i++) {
      for (int j = 0; j <= n - (1 << i); j++) {
        tab[i][j] = min(tab[i - 1][j], tab[i - 1][j + (1 << (i - 1))]);
      }
    }
  }
  int query(int x, int y) {
    x = rk[x];
    y = rk[y];
    if (x > y) swap(x, y);
    int t = lg2[y - x];
    return min(tab[t][x], tab[t][y - (1 << t)]);
  }
} sa1, sa2;
int a[100111];
int main() {
  lg2[1] = 0;
  for (int i = 2; i <= 100001; i++) lg2[i] = lg2[i >> 1] + 1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    sa1.a[i] = a[i];
    sa2.a[n - i - 1] = a[i];
  }
  sa1.construct();
  sa2.construct();
  int ans = 0;
  for (int i = 1; i <= n / 2; i++) {
    for (int j = 0; j + i < n; j += i) {
      if (j < ans) continue;
      int l1 = sa1.query(j, j + i);
      int l2 = min(j - ans + 1, sa2.query(n - j - 1, n - (j + i) - 1));
      int l = l1 + l2 - 1;
      if (l >= i) {
        ans = j - l2 + i + 1;
      }
    }
  }
  printf("%d\n", n - ans);
  for (int i = ans; i < n; i++) printf("%d ", a[i]);
  return 0;
}