#include <bits/stdc++.h>
template <typename T>
struct ValueComp {
  bool operator()(const T& a, const T& b) { return a > b; }
};
int main(void) {
  int n;
  long long int v;
  scanf("%d\n", &n);
  std::unordered_map<long long int,
                     std::priority_queue<int, std::vector<int>, ValueComp<int>>>
      elemMap;
  std::priority_queue<long long int, std::vector<long long int>,
                      ValueComp<long long int>>
      valueQueue;
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &v);
    if (elemMap.count(v) == 0) valueQueue.push(v);
    elemMap[v].push(i);
  }
  std::vector<long long int> finalArray(n, 0L);
  int finalElements = 0;
  while (not valueQueue.empty()) {
    const long long int currValue = valueQueue.top();
    if (elemMap[currValue].size() == 1) {
      finalArray[elemMap[currValue].top()] = currValue;
      ++finalElements;
      elemMap[currValue].pop();
      valueQueue.pop();
    } else {
      elemMap[currValue].pop();
      const int newIndex = elemMap[currValue].top();
      elemMap[currValue].pop();
      if (elemMap[currValue].empty()) valueQueue.pop();
      long long int newValue = currValue << 1;
      if (elemMap.count(newValue) == 0) valueQueue.push(newValue);
      elemMap[newValue].push(newIndex);
    }
    if (elemMap[currValue].empty()) elemMap.erase(currValue);
  }
  printf("%d\n", finalElements);
  for (const long long int& i : finalArray)
    if (i != 0L) printf("%I64d ", i);
  printf("\n");
  return 0;
}
