#include <bits/stdc++.h>
using namespace std;
const int N = 101000;
struct co {
  int px, py, t;
};
co z[10 * N];
int n, x[N], el[N][11], nrel[N], poz[N], d[N][11], nrz;
set<int> conv;
map<int, int> con, rec;
bool cmp(co a, co b) {
  if (a.py - a.px == b.py - b.px) return a.px < b.px;
  return a.py - a.px < b.py - b.px;
}
int main() {
  int i, j;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    scanf("%d", &x[i]);
    conv.insert(x[i]);
  }
  int nr = 0;
  for (set<int>::iterator it = conv.begin(); it != conv.end(); ++it) {
    ++nr;
    con[*it] = nr;
    rec[nr] = *it;
  }
  for (i = 1; i <= n; ++i) {
    x[i] = con[x[i]];
    el[x[i]][++nrel[x[i]]] = i;
    poz[i] = nrel[x[i]];
  }
  for (i = n - 1; i; --i) {
    for (j = poz[i] + 1; j <= nrel[x[i]]; ++j) {
      d[i][j] = 1;
      if (x[i + 1] == x[el[x[i]][j] + 1])
        d[i][j] = d[i + 1][poz[el[x[i]][j] + 1]] + 1;
      if (i + d[i][j] >= el[x[i]][j]) {
        ++nrz;
        z[nrz].px = i;
        z[nrz].t = min(d[i][j], el[x[i]][j] - i);
        z[nrz].py = i + 2 * z[nrz].t - 1;
      }
    }
  }
  sort(z + 1, z + nrz + 1, cmp);
  int pozs = 1;
  for (i = 1; i <= nrz; ++i) {
    if (z[i].px >= pozs) {
      pozs = z[i].px + z[i].t;
    }
  }
  cout << n - pozs + 1 << "\n";
  for (i = pozs; i <= n; ++i) cout << rec[x[i]] << " ";
  return 0;
}
