#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long a[200005];   struct poi {     long long val;     int pos;   } tp;   bool operator<(const poi &a, const poi &b) {     return (a.val > b.val) || (a.val == b.val and a.pos > b.pos);   }   priority_queue<poi> q;   int main() {     int n;     int cnt = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       tp.val = a[i];       tp.pos = i;       q.push(tp);     }     while (!q.empty()) {       poi a1 = q.top();       q.pop();       poi b1 = q.top();       q.pop();       while (!q.empty() && a1.val != b1.val) {         a1 = b1;         b1 = q.top();         q.pop();       }       if (a1.val == b1.val and a1.pos != b1.pos) {         a[b1.pos] = b1.val * 2;         b1.val = b1.val * 2;         a[a1.pos] = -1;         cnt++;         if (q.empty()) break;         q.push(b1);       }     }     printf( %d n , n - cnt);     for (int i = 0; i < n; i++) {       if (a[i] != -1) printf( %lld  , a[i]);     }     printf(  n );   }   