#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  map<int, int> m;
  int n;
  scanf("%d", &n);
  int a[n + 5];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (m[a[i]] == 0) {
      m[a[i]] = 1;
    } else {
      v.push_back(a[i - 1]);
      m.clear();
      m[a[i]] = 1;
    }
  }
  v.push_back(a[n - 1]);
  int len = v.size();
  printf("%d\n", len);
  for (int i = 0; i < len; i++) {
    printf("%d ", v[i]);
  }
  printf("\n");
  return 0;
}
