#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  bool mask[n];
  for (int i = 0; i < n; ++i) mask[i] = true;
  map<long long, int> m;
  for (int i = 0; i < n; ++i) {
    if (m[arr[i]] > 0) {
      mask[m[arr[i]] - 1] = false;
      m[arr[i]] = 0;
      arr[i] *= 2;
      --i;
    } else
      m[arr[i]] = i + 1;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) ans += mask[i];
  cout << ans << "\n";
  for (int i = 0; i < n; ++i) {
    if (mask[i]) {
      cout << arr[i] << " ";
    }
  }
}
