#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void solve() {
  long long int n;
  cin >> n;
  long long int arr[n];
  map<long long int, vector<long long int>> hash;
  for (long long int i = 0; i < n; ++i) {
    cin >> arr[i];
    hash[arr[i]].push_back(i);
  }
  for (auto i : hash) {
    sort(i.second.begin(), i.second.end());
    long long int m = i.second.size();
    if (m & 1) {
      arr[i.second[m - 1]] = i.first;
      m--;
    }
    for (long long int j = 0; j < m; ++j) {
      arr[i.second[j]] = -1;
      if (j % 2) hash[2 * i.first].push_back(i.second[j]);
    }
  }
  vector<long long int> ans;
  for (long long int i = 0; i < n; ++i)
    if (arr[i] != -1) ans.push_back(arr[i]);
  cout << ans.size() << "\n";
  for (auto i : ans) cout << i << " ";
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) solve();
  return 0;
}
