#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i2 = pair<int, int>;
const int N = 2e5 + 9;
int A[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i];
  stack<int> L, R;
  for (int i = n; i >= 1; i--) R.push(A[i]);
  while (!R.empty()) {
    if (L.empty()) {
      L.push(R.top());
      R.pop();
    } else if (L.top() == R.top()) {
      int x = L.top();
      L.pop();
      R.pop();
      R.push(x + 1);
    } else {
      L.push(R.top());
      R.pop();
    }
  }
  int k = L.size();
  for (int i = k; i >= 1; i--) {
    A[i] = L.top();
    L.pop();
  }
  cout << k << "\n";
  for (int i = 1; i <= k; i++) cout << A[i] << " ";
  return 0;
}
