#include <bits/stdc++.h>
using namespace std;
const int mn = 2e5 + 3;
long long arr[mn];
int main() {
  int n;
  cin >> n;
  int sh = 0;
  for (int i = 1; i <= n; i++) {
    long long num;
    cin >> num;
    if (arr[sh] == num) {
      while (num == arr[sh]) {
        sh -= 1;
        num += 1;
      }
    }
    sh++;
    arr[sh] = num;
  }
  cout << sh << endl;
  for (int i = 1; i <= sh; i++) {
    cout << arr[i] << " ";
  }
  return 0;
}
