#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, inf = 1e9;
const long double pi = 3.14159265;
long long n, a[maxn];
vector<long long> v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    long long tmp = a[i];
    while (v.size() && v.back() == tmp) {
      v.pop_back();
      tmp++;
    }
    v.push_back(tmp);
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  return 0;
}
