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>
struct case1 {
  long v, pos;
} m[100001] = {{0, 0}};
struct case2 {
  long len, pos;
} l[1000001] = {{0, 0}};
long st[19][100001] = {0}, tt[100001] = {0}, N[100001] = {0},
     hash[100001] = {0}, e[100001] = {0}, next[100001] = {0},
     head[100001] = {0}, sa[100001] = {0}, rank[200001] = {0}, t[100001] = {0},
     d[100001] = {0}, stack[100001] = {0}, height[100001], h[100001] = {0};
long totm, n;
void add(long a, long b) {
  e[++totm] = b;
  next[totm] = head[a];
  head[a] = totm;
}
void qs(long x, long y) {
  long i = x, j = y;
  struct case1 t = m[(x + y) >> 1];
  if (x >= y) return;
  m[(x + y) >> 1] = m[x];
  while (i < j) {
    while (i < j && m[j].v > t.v) j--;
    if (i < j) m[i++] = m[j];
    while (i < j && m[i].v < t.v) i++;
    if (i < j) m[j--] = m[i];
  }
  m[i] = t;
  qs(x, i - 1);
  qs(i + 1, y);
}
void qs2(long x, long y) {
  long i = x, j = y;
  struct case2 t = l[(x + y) >> 1];
  if (x >= y) return;
  l[(x + y) >> 1] = l[x];
  while (i < j) {
    while (i < j && (l[j].len > t.len || l[j].len == t.len && l[j].pos > t.pos))
      j--;
    if (i < j) l[i++] = l[j];
    while (i < j && (l[i].len < t.len || l[i].len == t.len && l[i].pos < t.pos))
      i++;
    if (i < j) l[j--] = l[i];
  }
  l[i] = t;
  qs2(x, i - 1);
  qs2(i + 1, y);
}
void ST() {
  long i, j;
  for (i = 1; i <= n; i++) st[0][i] = height[i];
  for (i = 1; (1 << i) <= n; i++)
    for (j = 1; j + (1 << i) - 1 <= n; j++)
      st[i][j] = ((st[i - 1][j]) < (st[i - 1][j + (1 << (i - 1))])
                      ? (st[i - 1][j])
                      : (st[i - 1][j + (1 << (i - 1))]));
}
long que(long x, long y) {
  long len, t;
  if (x > y) {
    t = x;
    x = y;
    y = t;
  }
  x++;
  len = log(y - x + 1) / log(2);
  return ((st[len][x]) < (st[len][y - (1 << len) + 1])
              ? (st[len][x])
              : (st[len][y - (1 << len) + 1]));
}
int main() {
  long i, j, k, pp, a, b, top, ptot, tl = 0, tot = 0, ans = 1;
  scanf("%ld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%ld", &m[i].v);
    tt[i] = m[i].v;
    ;
    m[i].pos = i;
  }
  qs(1, n);
  for (i = 1; i <= n; i++) {
    if (i == 1 || m[i].v > m[i - 1].v) tot++;
    rank[m[i].pos] = tot;
  }
  for (i = n; i >= 1; i--) {
    if (hash[rank[i]]) N[i] = hash[rank[i]];
    hash[rank[i]] = i;
  }
  for (i = 0; (1 << i) < n; i++) {
    totm = 0;
    memset(head, 0, sizeof(head));
    for (j = 1; j <= n; j++) {
      if (j + (1 << i) <= n)
        add(rank[j + (1 << i)], j);
      else
        add(0, j);
    }
    ptot = 0;
    for (j = 0; j <= tot; j++)
      for (k = head[j]; k; k = next[k]) d[++ptot] = e[k];
    totm = 0;
    memset(head, 0, sizeof(head));
    for (j = 1; j <= ptot; j++) add(rank[d[j]], d[j]);
    ptot = 0;
    for (j = 0; j <= tot; j++) {
      top = 0;
      for (k = head[j]; k; k = next[k]) stack[++top] = e[k];
      while (top) {
        d[++ptot] = stack[top];
        top--;
      }
    }
    tot = 0;
    for (j = 1; j <= ptot; j++) {
      if (j == 1 || rank[d[j]] > rank[d[j - 1]] ||
          rank[d[j]] == rank[d[j - 1]] &&
              rank[d[j] + (1 << i)] > rank[d[j - 1] + (1 << i)])
        tot++;
      t[d[j]] = tot;
    }
    for (j = 1; j <= ptot; j++) rank[j] = t[j];
  }
  for (i = 1; i <= n; i++) sa[rank[i]] = i;
  for (i = 1; i <= n; i++) {
    for (h[i] = ((h[i - 1] - 1) > (0) ? (h[i - 1] - 1) : (0));
         tt[i + h[i]] == tt[sa[rank[i] - 1] + h[i]]; h[i]++)
      j = 1;
    height[rank[i]] = h[i];
  }
  ST();
  for (i = 1; i <= n; i++)
    for (j = N[i]; j; j = N[j])
      if (que(rank[i], rank[j]) >= j - i) {
        l[++tl].pos = i;
        l[tl].len = j - i;
      }
  qs2(1, tl);
  for (i = 1; i <= tl; i++)
    if (l[i].pos >= ans) ans = l[i].pos + l[i].len;
  printf("%ld\n", n - ans + 1);
  for (i = 1; i < n - ans + 1; i++) printf("%ld ", tt[ans + i - 1]);
  printf("%ld\n", tt[n]);
  return 0;
}