#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int MX = 123456;
const int base = 1023456789;
const unsigned long long BS1 = 10000019ULL;
const int INF = (1 << 29);
template <class T>
inline void fastScan(T &x) {
  register char c = getchar();
  int neg = 0;
  x = 0;
  for (; (c < 48 || c > 57) && (c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
int mod[] = {999999937, 999999929};
int BS[] = {31, 37};
int n;
int st;
int f1[N];
int f2[N];
int mn[N];
int len[N];
int inp[N];
int point[N];
int hashing1[N];
int hashing2[N];
map<int, vector<int> > mymap;
int P(int a, int b, int c) {
  int ret = 1;
  while (b > 0) {
    if (b & 1) {
      ret = 1ll * ret * a % c;
    }
    b /= 2;
    a = 1ll * a * a % c;
  }
  return ret;
}
int hashVal1(int l, int r) {
  int up = hashing1[r] - hashing1[l - 1];
  up %= mod[0];
  up += mod[0];
  up %= mod[0];
  int down = P(f1[l - 1], mod[0] - 2, mod[0]) % mod[0];
  up = 1ll * up * down % mod[0];
  return up;
}
int hashVal2(int l, int r) {
  int up = hashing2[r] - hashing2[l - 1];
  up %= mod[1];
  up += mod[1];
  up %= mod[1];
  int down = P(f2[l - 1], mod[1] - 2, mod[1]) % mod[1];
  up = 1ll * up * down % mod[1];
  return up;
}
int Solve(int idx) {
  int dist = N + N;
  int v = inp[idx];
  for (int i = 0; i < mymap[v].size(); i++) {
    int u = mymap[v][i];
    if (u > idx) {
      if (u - idx <= n - u + 1) {
        if (hashVal1(idx, u - 1) == hashVal1(u, u + u - idx - 1)) {
          if (hashVal2(idx, u - 1) == hashVal2(u, u + u - idx - 1)) {
            dist = min(dist, u - idx);
          }
        }
      }
    }
  }
  return dist;
}
int main() {
  fastScan(n);
  for (int i = 1; i <= n; i++) {
    fastScan(inp[i]);
    inp[i]++;
    mymap[inp[i]].push_back(i);
  }
  f1[0] = 1;
  f2[0] = 1;
  for (int i = 1; i <= n; i++) {
    f1[i] = 1ll * f1[i - 1] * BS[0] % mod[0];
    f2[i] = 1ll * f2[i - 1] * BS[1] % mod[1];
  }
  for (int i = 1; i <= n; i++) {
    hashing1[i] = 1ll * inp[i] * f1[i] % mod[0];
    hashing1[i] += hashing1[i - 1];
    hashing1[i] %= mod[0];
    hashing2[i] = 1ll * inp[i] * f2[i] % mod[1];
    hashing2[i] += hashing2[i - 1];
    hashing2[i] %= mod[1];
  }
  len[n + 1] = N + N;
  point[n + 1] = n + 1;
  mn[n + 1] = N;
  for (int i = n; i >= 1; i--) {
    int x = Solve(i);
    len[i] = x;
    mn[i] = min(mn[i + 1], len[i]);
    if (len[i] > mn[i + 1])
      point[i] = point[i + 1];
    else
      point[i] = i;
  }
  st = 1;
  for (int i = 1; i <= n;) {
    if (point[i] == i) {
      st = i + mn[i];
      i = i + mn[i];
    } else {
      i++;
    }
  }
  printf("%d\n", n - st + 1);
  for (int i = st; i <= n; i++) {
    printf("%d%c", inp[i] - 1, (i == n ? '\n' : ' '));
  }
}
