#include <bits/stdc++.h>
using namespace std;
const int INF_I = 1e9;
const long long INF_LL = 1e18;
const int MOD = 1000000007;
const double eps = 1e-6;
void pr(list<int>& a) {
  for (int i : a) cout << i << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  list<int> a;
  a.emplace_back(-1);
  a.emplace_back(-1);
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    a.emplace_back(b);
  }
  a.emplace_back(-1);
  auto r = a.begin();
  auto l = r;
  r++;
  auto c = r;
  r++;
  while (*r != -1) {
    if (*c == *r) {
      int b = *r;
      a.erase(c);
      a.erase(r);
      l++;
      c = a.insert(l, b + 1);
      r = c;
      c--;
      l--;
      l--;
      l--;
    } else
      l++, c++, r++;
  }
  cout << (int)a.size() - 3 << "\n";
  for (int i : a)
    if (i != -1) cout << i << " ";
  return 0;
}
