#include <bits/stdc++.h>
using namespace std;
class myComparator {
 public:
  int operator()(pair<long long, int> &a, pair<long long, int> &b) {
    if (a.first == b.first) {
      return a.second > b.second;
    }
    return a.first > b.first;
  }
};
class Comp2 {
 public:
  int operator()(pair<long long, int> &a, pair<long long, int> &b) {
    return a.second > b.second;
  }
};
int main() {
  auto cmp = [](pair<long long, int> a, pair<long long, int> b) {
    return a.first > b.first;
  };
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 myComparator>
      pq;
  int n;
  cin >> n;
  long long in;
  for (int i = 0; i < n; i++) {
    cin >> in;
    pq.push({in, i});
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int> >, Comp2>
      print;
  while (!pq.empty()) {
    pair<long long, int> a;
    pair<long long, int> b;
    a = pq.top();
    pq.pop();
    if (!pq.empty()) {
      b = pq.top();
      if (a.first == b.first) {
        pq.pop();
        pq.push({b.first << 1, b.second});
      } else {
        print.push(a);
      }
    } else {
      print.push(a);
    }
  }
  cout << print.size() << endl;
  while (!print.empty()) {
    cout << print.top().first << ' ';
    print.pop();
  }
  cout << endl;
}
