#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5, inf = 1e9 + 5;
int n, ans;
struct idejaleb_XD {
  int nxt, pre;
  long long int inside = 0;
} add[maxn];
bool merg(int ii) {
  if (add[ii].inside == add[add[ii].pre].inside) {
    add[add[add[ii].pre].pre].nxt = ii;
    add[ii].pre = add[add[ii].pre].pre;
    add[ii].inside++;
    ans--;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  add[n + 1].pre = n;
  add[0].nxt = 1;
  ans = n;
  for (int i = 1; i <= n; i++) {
    cin >> add[i].inside;
    add[i].nxt = i + 1;
    add[i].pre = i - 1;
  }
  for (int i = 1; i <= n; i++) i -= merg(i);
  cout << ans << endl;
  for (int i = add[0].nxt; add[i].inside != 0; i = add[i].nxt)
    cout << add[i].inside << " ";
  return 0;
}
