#include <bits/stdc++.h>
using namespace std;
const int maxn = 200002;
long long a[maxn];
int n;
void enter() {
  cin >> n;
  for (int i = (1), _b = (n + 1); i < _b; ++i) cin >> a[i];
}
int seg[4 * maxn];
void update(int l, int r, int st, int q) {
  if (l == r)
    seg[st] = 0;
  else {
    int mid = (l + r) >> 1;
    if (mid >= q)
      update(l, mid, st * 2, q);
    else
      update(mid + 1, r, st * 2 + 1, q);
    seg[st] = seg[st * 2] + seg[st * 2 + 1];
  }
}
void init(int l, int r, int st) {
  if (l == r)
    seg[st] = 1;
  else {
    int mid = (l + r) >> 1;
    init(l, mid, st * 2);
    init(mid + 1, r, st * 2 + 1);
    seg[st] = seg[st * 2] + seg[st * 2 + 1];
  }
}
int _get(int u, int v, int l, int r, int st) {
  if (u <= l && r <= v)
    return seg[st];
  else if (r < u || l > v)
    return 0;
  else {
    int mid = (l + r) >> 1;
    return _get(u, v, l, mid, st * 2) + _get(u, v, mid + 1, r, st * 2 + 1);
  }
}
map<long long, int> pos;
void solve() {
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    if (pos[a[i]] != 0 && _get(pos[a[i]], i, 1, n, 1) == 2) {
      long long num = a[i];
      int ps = i;
      while (pos[num] != 0 && _get(pos[num], ps, 1, n, 1) == 2) {
        update(1, n, 1, ps);
        ps = pos[num];
        pos[num] = 0;
        num++;
        a[ps] = num;
      }
      pos[num] = ps;
    } else
      pos[a[i]] = i;
  }
  vector<long long> p;
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    if (_get(i, i, 1, n, 1) == 1) p.push_back(a[i]);
  }
  cout << p.size() << "\n";
  for (auto i : p) cout << i << " ";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  enter();
  init(1, n, 1);
  solve();
}
