#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long mod) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long modInverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long binomial(long long n, long long k) {
  long long res = 1;
  if (k > n - k) k = n - k;
  for (long long i = 0; i < k; ++i) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
const long long mod = 1e9 + 7;
const long long N = 2e5 + 9;
void doper() {}
int32_t main() {
  doper();
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (auto &i : v) cin >> i;
  stack<long long> st;
  long long i = 0;
  long long nextele = v[0];
  while (i < n) {
    long long p;
    if (st.size())
      p = st.top();
    else {
      st.push(nextele);
      i++;
      nextele = v[i];
      continue;
    }
    if (p != nextele) {
      st.push(nextele);
      i++;
      nextele = v[i];
    } else {
      st.pop();
      nextele++;
    }
  }
  vector<long long> ans;
  while (!st.empty()) {
    long long p = st.top();
    st.pop();
    ans.push_back(p);
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size();
  cout << "\n";
  ;
  for (auto &i : ans) cout << i << " ";
  return 0;
}
