#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int n;
int ans[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i + 1]) {
      ans[++cnt] = a[i] + 1;
      while (ans[cnt] == ans[cnt - 1] && cnt - 1) ans[cnt - 1]++, cnt--;
      a[i + 1] = ans[cnt];
      cnt--;
    } else
      ans[++cnt] = a[i];
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) cout << ans[i] << " ";
}
