#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int arr[maxn], n;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  int p = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[p];
    while (p && arr[p] == arr[p - 1]) {
      arr[p - 1]++;
      p--;
    }
    p++;
  }
  cout << p << '\n';
  for (int i = 0; i < p; i++) cout << arr[i] << ' ';
  return 0;
}
