#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10, mod = 1e9 + 7, inf = 1e8;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    while (v.size() && v.back() == a) {
      v.pop_back();
      a++;
    }
    v.push_back(a);
  }
  cout << v.size() << "\n";
  for (auto x : v) cout << x << " ";
  cout << "\n";
  return 0;
}
