#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5) + 10;
const int K = 11;
const int MOD = int(1e9) + 7;
const int INF = int(2e9) + 5;
const long long INF64 = 1e18;
int a[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  stack<int> s;
  for (int r = 1; r <= n; r++) {
    int x = a[r];
    while (!s.empty() && s.top() == x) {
      s.pop();
      x++;
    }
    s.push(x);
  }
  vector<int> ans;
  while (!s.empty()) {
    ans.push_back(s.top());
    s.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size() << '\n';
  for (auto x : ans) cout << x << " ";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
