#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 5;   long long int a[maxN], b[maxN];   int n;   void solve() {     cin >> n;     set<pair<long long int, int>> s;     int count = n;     for (int i = 0; i < n; i++) {       b[i] = 1;       cin >> a[i];       s.insert({a[i], i});     }     while (!s.empty()) {       auto it1 = *(s.begin());       s.erase(s.begin());       if (s.empty()) break;       auto it2 = *(s.begin());       if (it1.first == it2.first) {         count--;         s.erase(s.begin());         s.insert({2 * it2.first, it2.second});         a[it2.second] = 2 * it2.first;         b[it1.second] = 0;       }     }     cout << count << endl;     for (int i = 0; i < n; i++) {       if (b[i]) cout << a[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     int t = 1;     while (t--) {       solve();     }     return 0;   }   