#include <bits/stdc++.h>
using namespace std;
int N;
int A[100010];
vector<int> dis[100010];
int main() {
  while (1 == scanf("%d", &N)) {
    for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
    map<int, vector<int> > pos;
    for (int i = 0; i < N; ++i) dis[i].clear();
    for (int i = N - 1; i >= 0; --i) {
      if (pos.count(A[i])) {
        const vector<int> &p = pos[A[i]];
        for (int j = 0; j < p.size(); ++j) dis[p[j] - i].push_back(i);
      }
      pos[A[i]].push_back(i);
    }
    int crr = 0;
    for (int d = 1; d < N; ++d) {
      reverse(dis[d].begin(), dis[d].end());
      int prv = -1, cnt = 0;
      for (int i = 0; i < dis[d].size(); ++i) {
        if (dis[d][i] < crr) continue;
        if (dis[d][i] == prv + 1)
          ++cnt;
        else
          cnt = 1;
        if (cnt == d) {
          crr = dis[d][i] + 1;
          prv = -1;
          cnt = 0;
        }
        prv = dis[d][i];
      }
    }
    printf("%d\n", N - crr);
    for (int i = crr; i < N; ++i) printf("%d%c", A[i], i == N - 1 ? '\n' : ' ');
  }
  return 0;
}
