#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, M = 5e9 + 10, mod = 1e9 + 7, inf = 1e18;
long long n, a[N], i;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    long long x = a[i];
    while (!v.empty() && v.back() == x) {
      v.pop_back();
      x++;
    }
    v.push_back(x);
  }
  cout << v.size() << "\n";
  for (i = 0; i < v.size(); i++) cout << v[i] << " ";
}
