#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n + 1], i;
  map<long long int, list<long long int>> mp;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]].push_back(i);
  }
  a[n] = -1;
  long long int t = 0;
  for (i = 0; i < n; i++) {
    list<long long int> &r = mp[a[i]];
    r.pop_front();
    for (auto tt : r) {
      long long int x = i, y = tt;
      do x++, y++;
      while (x < tt && a[x] == a[y]);
      if (x == tt) {
        i = tt - 1;
        t = tt;
      }
    }
  }
  cout << n - t << "\n";
  while (t < n) cout << a[t++] << " ";
  return 0;
}
