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 int N = 100005;
vector<int> G[N];
struct node {
  int len, l1;
} st[N << 3];
bool cmp(node a, node b) {
  return a.len < b.len | (a.len == b.len & a.l1 < b.l1);
}
int n, cn[N], base = 1117, b[N], a[N], hush[N], ln, inf = 2e9, m, top, mp[N];
__inline__ __attribute__((always_inline)) int gethush(int l, int r) {
  return hush[r] - hush[l - 1] * cn[r - l + 1];
}
namespace IO {
const int maxm = 1000000;
char buf[maxm], *p1, *p2;
template <typename T>
__inline__ __attribute__((always_inline)) void redi(T &x) {
  static std::streambuf *inbuf = cin.rdbuf();
  x = 0;
  register int f = 0;
  register char ch =
      (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, maxm), p1 == p2)
           ? EOF
           : *p1++);
  while (!std::isdigit(ch)) {
    if (ch == '-') f = 1;
    ch = (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, maxm), p1 == p2)
              ? EOF
              : *p1++);
  }
  if (std::isdigit(ch))
    x = x * 10 + ch - '0',
    ch = (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, maxm), p1 == p2)
              ? EOF
              : *p1++);
  while (std::isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, maxm), p1 == p2)
              ? EOF
              : *p1++);
  }
  x = f ? -x : x;
}
__inline__ __attribute__((always_inline)) void read(char asd[]) {
  static std::streambuf *inbuf = cin.rdbuf();
  char t = (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, maxm), p1 == p2)
                ? EOF
                : *p1++);
  int u = 0;
  while (t == ' ' || t == '\n' || t == '\r')
    t = (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, maxm), p1 == p2)
             ? EOF
             : *p1++);
  while (t != ' ' && t != '\n' && t != EOF && t != '\r')
    asd[u++] = t,
    t = (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, maxm), p1 == p2)
             ? EOF
             : *p1++);
  asd[u] = '\0';
}
template <typename T, typename... Args>
__inline__ __attribute__((always_inline)) void redi(T &a, Args &...args) {
  redi(a);
  redi(args...);
}
char buf1[maxm + 9], a1[20];
int p, po = -1;
__inline__ __attribute__((always_inline)) void flush() {
  fwrite(buf1, 1, po + 1, stdout), po = -1;
}
__inline__ __attribute__((always_inline)) void print(long long x, char c) {
  if (po > maxm) flush();
  if (x < 0) buf1[++po] = 45, x = -x;
  do {
    a1[++p] = x % 10 + 48;
  } while (x /= 10);
  do {
    buf1[++po] = a1[p];
  } while (--p);
  buf1[++po] = c;
}
}  // namespace IO
using IO::flush;
using IO::print;
using IO::read;
using IO::redi;
int main() {
  int i, j, k;
  redi(n);
  for (i = 1; i <= n; i++) redi(a[i]), b[i] = a[i];
  cn[0] = 1;
  for (i = 1; i <= n; i++) cn[i] = cn[i - 1] * base;
  for (i = 1; i <= n; i++) {
    hush[i] = hush[i - 1] * base + a[i];
  }
  sort(b + 1, b + 1 + n);
  ln = unique(b + 1, b + 1 + n) - b - 1;
  for (i = 1; i <= n; i++) {
    int x = lower_bound(b + 1, b + 1 + ln, a[i]) - b;
    mp[x] = a[i];
    a[i] = x;
    m = max(x, m);
  }
  for (i = 1; i <= n; i++) {
    G[a[i]].push_back(i);
  }
  int ans = 1;
  for (i = 1; i <= m; i++) {
    for (j = 0; j < G[i].size(); j++) {
      for (k = j + 1; k < G[i].size(); k++) {
        int x = G[i][j], y = G[i][k], len = y - x;
        int l1 = x, r1 = y - 1, l2 = y, r2 = y + len - 1;
        if (r2 > n) continue;
        if (gethush(l1, r1) == gethush(l2, r2)) {
          st[++top] = (node){len, l1};
        }
      }
    }
  }
  if (top != 0) {
    sort(st + 1, st + top + 1, cmp);
    for (i = 1; i <= top; i++) {
      if (st[i].l1 >= ans) {
        ans = st[i].l1 + st[i].len;
      }
    }
  }
  print(n - ans + 1, '\n');
  for (i = ans; i <= n; i++) {
    print(mp[a[i]], ' ');
  }
  flush();
  return 0;
}