#include <bits/stdc++.h>
using namespace std;
long long n;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<long long> a(n);
  unordered_map<long long, vector<long long> > pos;
  for (long long i = 0; i < n; i++) cin >> a[i], pos[a[i]].push_back(i);
  vector<vector<long long> > pairs(n);
  for (auto v : pos) {
    vector<long long> tmp = v.second;
    for (long long i = 0; i < (long long)tmp.size(); i++) {
      for (long long j = 0; j < i; j++)
        pairs[tmp[i] - tmp[j]].push_back(tmp[j]);
    }
  }
  for (long long i = 0; i < n; i++) sort((pairs[i]).begin(), (pairs[i]).end());
  long long last = 0;
  for (long long len = 1; len < n; len++) {
    long long cur = 0;
    for (long long i = 0; i < (long long)pairs[len].size(); i++) {
      if (pairs[len][i] < last) continue;
      if (i && pairs[len][i] == pairs[len][i - 1] + 1)
        cur++;
      else
        cur = 1;
      if (cur == len) last = pairs[len][i] + 1, cur = 0;
    }
  }
  cout << n - last << endl;
  for (long long i = last; i < n; i++) cout << a[i] << " ";
  return 0;
}
