// clang-format off
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#ifndef bhartiya
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> oset;
// not that imp
typedef pair<pii, int> piii;
typedef vector<int> vi;
#define vl vector <long long>
typedef vector<pii> vii;
#define vll vector <vl>
#define vp vector <pii>
#define INF 200000000000000
#define MOD 1000000007
#define EPS 1e-7
const int MAXN= 2e5+5;
#define PI 3.1415926535897932385
// #define PI acos(-1)

#define pb push_back
#define bitc __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar, val) memset(ar, val, sizeof(ar))  // 0x7f for inf, 0x80 for -INF

#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))

#ifdef bhartiya
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; }
ll modpow(ll b, ll e) {
	ll ans=1; for(;e;b=b*b%MOD,e/=2) if(e&1) ans=ans*b%MOD; return ans; }
// clang-format on
ll n,m,a,b;

void solve()
{
    cin>>n;
    map <ll,vl> pos;
    map <ll,ll> hope;
    vl a1(MAXN);
    vp a2;
    fr(i,0,n-1)
    {
        cin>>a1[i];
        pos[a1[i]].pb(i);
    }
    for(auto i:pos){
        sort(i.ss.begin(),i.ss.end());

        if(i.ss.size()%2==0){
            fr(j,0,i.ss.size()-1){
            if(j%2==1)pos[2*i.ff].pb(i.ss[j]);
            }
            i.ss={};
        }

        // else {
        //     fr(j,0,i.ss.size()-2){
        //     if(j%2==1)pos[2*i.ff].pb(i.ss[j]);
        //     }
        //     i.ss={i.ss[i.ss.size()-1]};
        //     hope[i.ff]=i.ss[i.ss.size()-1];
        // }
    }
    // for(auto i:pos){
    //     trace(i);
    //     if(i.ss.size()>0){

    //     }
    // }
    // for(auto i:hope){
    //     a2.pb({i.ss,i.ff});
    // }
    // sort(a2.begin(),a2.end());
    // cout<<a2.size()<<"\n";
    // fr(i,0,a2.size()-1)cout<<a2[i].ss<<" ";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(10);  // cout<<fixed;
#ifdef bhartiya
    // cin.exceptions(cin.failbit);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    end_routine();
}


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<int>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<int>::iterator s1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
		s[a[i]].insert(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%lld%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			s1 = s[num].begin();
		//	cout<<num<<"@@@@@"<<s[num].size()<<endl;
			int len = s[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				int num1;
				if(len % 2 == 0){
					int i = 0;
					for(; s1 != s[num].end(); s1++,i++){
						num1 = *s1;
						//cout<<num1<<"@@@####"<<endl;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					int i = 0;
					for(; s1 != s[num].end() ; s1++,i++){
						num1 = *s1;
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%d\n",b[i]);
			else printf("%d ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
		s[a[i]].insert(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%lld%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			s1 = s[num].begin();
		//	cout<<num<<"@@@@@"<<s[num].size()<<endl;
			int len = s[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					int i = 0;
					for(; s1 != s[num].end(); s1++,i++){
						num1 = *s1;
						//cout<<num1<<"@@@####"<<endl;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					int i = 0;
					for(; s1 != s[num].end() ; s1++,i++){
						num1 = *s1;
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%lld\n",b[i]);
			else printf("%lld ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
//vector<ll>v[MAX_N];
vector<ll>v;

//累~~~~~~~~~~~~~~~~~

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%lld\n",a[i]);
			else printf("%lld ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;

			int len = m[num];
			if(len == 1){
				m.erase(num);
			}
			else{
				v.clear();
				for(int i = 1; i <= n; i++){
					if(v.size() == m[num]) break;
					if(a[i] == num) v.push_back(i);
				}
				ll num1;
				if(len % 2 == 0){
					for(int i = 0; i < len; i++){
						num1 = v[i];
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
						}
						else{
							a[num1] = 0;
						}
					}
					m.erase(num);
				}
				else{
					for(int i = 0; i < len ; i++){
						num1 = v[i];
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
						}
						else{
							a[num1] = 0;
						}
					}
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%lld\n",b[i]);
			else printf("%lld ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%lld%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(1){
			m1 = m.begin();
			ll num = m1->first;
			//cout<<num<<"   ###  "<<num1<<endl;
			int t = 0;
			ll ans = 0;
			for(int i = 1; i <= n; i++){
				if(a[i] == num){
					ans++;
					if(ans % 2 == 0){
						m[a[i]]-=2;
						a[i] = 2 * num;
						m[a[i]]++;
						a[t] = 0;
						ans = 0;
					}
					t = i;
				}
			}
			m.erase(num);
			if(m.size() == 0){
				for(int i = 1; i<= n; i++){
					if(a[i]!=0){
						b[t1++] = a[i];
					}
				}
				break;
			}
		}
		printf("%d\n",t1-1);
		for(int i = 1; i < t1; i++){
			printf("%lld%c",b[i],i == t1?'\n':' ');
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<int,int>m;
int a[MAX_N],b[MAX_N];
map<int,int>::iterator m1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		m[a[i]]++;
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%d%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(1){
			m1 = m.begin();
			int num = m1->first;
			int num1 = m1->second;
			//cout<<num<<"   ###  "<<num1<<endl;
			int t = 0,ans = 0;
			for(int i = 1; i <= n; i++){
				if(a[i] == num){
					ans++;
					if(ans % 2 == 0){
						m[a[i]]-=2;
						a[i] = 2 * num;
						m[a[i]]++;
						a[t] = 0;
						ans = 0;
					}
					t = i;
				}
			}
			m.erase(num);
			if(m.size() == 0){
				for(int i = 1; i<= n; i++){
					if(a[i]!=0){
						b[t1++] = a[i];
					}
				}
				break;
			}
		}
		printf("%d\n",t1-1);
		for(int i = 1; i < t1; i++){
			printf("%d%c",b[i],i == t1?'\n':' ');
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
//vector<ll>v[MAX_N];
vector<ll>v;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%u",&a[i]);
		m[a[i]]++;
		//s[a[i]].insert(i);
		//v[a[i]].push_back(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%lld\n",a[i]);
			else printf("%lld ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			v.clear();
			for(int i = 1; i <= n; i++){
				if(a[i] == num) v.push_back(i);
			}
			int len = v.size();
			//cout<<len<<"####"<<endl;
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					for(int i = 0; i < len; i++){
						num1 = v[i];
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							//v[a[num1]].push_back(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					for(int i = 0; i < len ; i++){
						num1 = v[i];
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							//v[a[num1]].push_back(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%lld\n",b[i]);
			else printf("%lld ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
vector<ll>v[MAX_N];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%u",&a[i]);
		m[a[i]]++;
		//s[a[i]].insert(i);
		v[a[i]].push_back(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%lld\n",a[i]);
			else printf("%lld ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			int len = v[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					for(int i = 0; i < len; i++){
						num1 = v[num][i];
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							v[a[num1]].push_back(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					for(int i = 0; i < len ; i++){
						num1 = v[num][i];
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							v[a[num1]].push_back(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%lld\n",b[i]);
			else printf("%lld ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
//vector<ll>v[MAX_N];
vector<ll>v;

//累~~~~~~~~~~~~~~~~~

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%lld\n",a[i]);
			else printf("%lld ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			v.clear();
			for(int i = 1; i <= n; i++){
				if(v.size() == m[num]) break;
				if(a[i] == num) v.push_back(i);

			}
			int len = v.size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					for(int i = 0; i < len; i++){
						num1 = v[i];
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
						}
						else{
							a[num1] = 0;
						}
					}
					m.erase(num);
				}
				else{
					for(int i = 0; i < len ; i++){
						num1 = v[i];
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
						}
						else{
							a[num1] = 0;
						}
					}
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%lld\n",b[i]);
			else printf("%lld ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
		s[a[i]].insert(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%lld%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			s1 = s[num].begin();
		//	cout<<num<<"@@@@@"<<s[num].size()<<endl;
			int len = s[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					int i = 0;
					for(; s1 != s[num].end(); s1++,i++){
						num1 = *s1;
						//cout<<num1<<"@@@####"<<endl;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					int i = 0;
					for(; s1 != s[num].end() ; s1++,i++){
						num1 = *s1;
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%d\n",b[i]);
			else printf("%d ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 10000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
vector<ll>v[MAX_N];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%u",&a[i]);
		m[a[i]]++;
		//s[a[i]].insert(i);
		v[a[i]].push_back(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%lld\n",a[i]);
			else printf("%lld ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			int len = v[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					for(int i = 0; i < len; i++){
						num1 = v[num][i];
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							v[a[num1]].push_back(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					for(int i = 0; i < len ; i++){
						num1 = v[num][i];
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							v[a[num1]].push_back(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%lld\n",b[i]);
			else printf("%lld ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef unsigned long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%u",&a[i]);
		m[a[i]]++;
		s[a[i]].insert(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%u%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			s1 = s[num].begin();
		//	cout<<num<<"@@@@@"<<s[num].size()<<endl;
			int len = s[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					int i = 0;
					for(; s1 != s[num].end(); s1++,i++){
						num1 = *s1;
						//cout<<num1<<"@@@####"<<endl;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					int i = 0;
					for(; s1 != s[num].end() ; s1++,i++){
						num1 = *s1;
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%u\n",b[i]);
			else printf("%u ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef unsigned long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
vector<ll>v[MAX_N];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%u",&a[i]);
		m[a[i]]++;
		s[a[i]].insert(i);
		//v[a[i]].push_back(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%u\n",a[i]);
			else printf("%u ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			s1 = s[num].begin();
		//	cout<<num<<"@@@@@"<<s[num].size()<<endl;
			int len = s[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					int i = 0;
					for(; s1 != s[num].end(); s1++,i++){
						num1 = *s1;
						//cout<<num1<<"@@@####"<<endl;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					int i = 0;
					for(; s1 != s[num].end() ; s1++,i++){
						num1 = *s1;
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%u\n",b[i]);
			else printf("%u ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
//vector<ll>v[MAX_N];
vector<ll>v;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%lld\n",a[i]);
			else printf("%lld ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			v.clear();
			for(int i = 1; i <= n; i++){
				if(a[i] == num) v.push_back(i);
			}
			int len = v.size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					for(int i = 0; i < len; i++){
						num1 = v[i];
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
						}
						else{
							a[num1] = 0;
						}
					}
					m.erase(num);
				}
				else{
					for(int i = 0; i < len ; i++){
						num1 = v[i];
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
						}
						else{
							a[num1] = 0;
						}
					}
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%lld\n",b[i]);
			else printf("%lld ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=10*x+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void Out(int a)
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}

struct Node{
	ll num;
	int id;
	friend bool operator < (Node a,Node b){
		return a.num == b.num ? a.id > b.id: a.num > b.num;
	}
}now,nex;

struct Node1{
	ll num;
	int id;
	friend bool operator < (Node1 a,Node1 b){
		return a.id > b.id;
	}
}nex1;

priority_queue<Node>q;
priority_queue<Node1>q1;

ll b[MAX_N];

int main(){
	int n,a;
	cin>>n;
	Node node;
	for(int i = 1; i <= n; i++){
		cin>>a;
		node.num = a;
		node.id = i;
		q.push(node);
	}
	while(!q.empty()){
		if(q.size() == 1){
			now = q.top();
			nex1.num = now.num;
			nex1.id = now.id;
			q1.push(nex1);
			q.pop();
			break;
		}
		now = q.top();
		q.pop();
		nex = q.top();
		q.pop();
		//cout<<now.num<<"    @@@  "<<nex.num<<endl;
		if(now.num == nex.num){
			nex.num = 2 * now.num;
			q.push(nex);
			continue;
		}
		if(now.num != nex.num){
			nex1.num = now.num;
			nex1.id = now.id;
			q.push(nex);
			q1.push(nex1);
		}
	}
	int t = 0;
	cout<<q1.size()<<endl;
	while(!q1.empty()){
		nex1 = q1.top();
		if(q.size() == 1) cout<<nex1.num<<endl;
		else cout<<nex1.num<<" ";
		q1.pop();
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<int,int>m;
ll a[MAX_N],b[MAX_N];
map<int,int>::iterator m1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%lld%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(1){
			m1 = m.begin();
			int num = m1->first;
			int num1 = m1->second;
			//cout<<num<<"   ###  "<<num1<<endl;
			int t = 0;
			int ans = 0;
			for(int i = 1; i <= n; i++){
				if(a[i] == num){
					ans++;
					if(ans % 2 == 0){
						m[a[i]]-=2;
						a[i] = 2 * num;
						m[a[i]]++;
						a[t] = 0;
						ans = 0;
					}
					t = i;
				}
			}
			m.erase(num);
			if(m.size() == 0){
				for(int i = 1; i<= n; i++){
					if(a[i]!=0){
						b[t1++] = a[i];
					}
				}
				break;
			}
		}
		printf("%d\n",t1-1);
		for(int i = 1; i < t1; i++){
			printf("%lld%c",b[i],i == t1?'\n':' ');
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<int,int>m;
int a[MAX_N],b[MAX_N];
map<int,int>::iterator m1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		m[a[i]]++;
	}
	if(m.size() == n){
		for(int i = 1; i <= n; i++){
			printf("%d%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(1){
			m1 = m.begin();
			int num = m1->first;
			int num1 = m1->second;
			//cout<<num<<"   ###  "<<num1<<endl;
			int t = 0,ans = 0;
			for(int i = 1; i <= n; i++){
				if(a[i] == num){
					ans++;
					if(ans % 2 == 0){
						m[a[i]]-=2;
						a[i] = 2 * num;
						m[a[i]]++;
						a[t] = 0;
						ans = 0;
					}
					t = i;
				}
			}
			m.erase(num);
			if(m.size() == 0){
				for(int i = 1; i<= n; i++){
					if(a[i]!=0){
						b[t1++] = a[i];
					}
				}
				break;
			}
		}
		printf("%d\n",t1-1);
		for(int i = 1; i < t1; i++){
			printf("%d%c",b[i],i == t1?'\n':' ');
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<int>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<int>::iterator s1;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		m[a[i]]++;
		s[a[i]].insert(i);
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			printf("%lld%c",a[i],i == n?'\n':' ');
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			s1 = s[num].begin();
		//	cout<<num<<"@@@@@"<<s[num].size()<<endl;
			int len = s[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				int num1;
				if(len % 2 == 0){
					int i = 0;
					for(; s1 != s[num].end(); s1++,i++){
						num1 = *s1;
						//cout<<num1<<"@@@####"<<endl;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					int i = 0;
					for(; s1 != s[num].end() ; s1++,i++){
						num1 = *s1;
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			printf("%d%c",b[i],i == k-1?'\n':' ');
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define open  #ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endif
using namespace std;
typedef unsigned long long ll;
const int MAX_N = 1000000+50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll INF_ll = 0x7fffffffffffffff;
ll mod = 1e9+7;

map<ll,ll>m;
set<ll>s[MAX_N];
ll a[MAX_N],b[MAX_N];
map<ll,ll>::iterator m1;
set<ll>::iterator s1;
vector<ll>v[MAX_N];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%u",&a[i]);
		m[a[i]]++;
		//s[a[i]].insert(i);
		v[a[i]]
	}
	if(m.size() == n){
		printf("%d\n",n);
		for(int i = 1; i <= n; i++){
			if(i == n) printf("%u\n",a[i]);
			else printf("%u ",a[i]);
		}
	}
	else{
		int t1 = 1;
		while(m.size() != 0){
			m1 = m.begin();
			ll num = m1->first;
			s1 = s[num].begin();
		//	cout<<num<<"@@@@@"<<s[num].size()<<endl;
			int len = s[num].size();
			if(len == 1){
				m.erase(num);
			}
			else{
				ll num1;
				if(len % 2 == 0){
					int i = 0;
					for(; s1 != s[num].end(); s1++,i++){
						num1 = *s1;
						//cout<<num1<<"@@@####"<<endl;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
				else{
					int i = 0;
					for(; s1 != s[num].end() ; s1++,i++){
						num1 = *s1;
						//cout<<num1<<"EEEEE"<<endl;
						if(i == len - 1) break;
						if((i + 1) % 2 == 0){
							a[num1] = 2 * a[num1];
							m[a[num1]]++;
							s[a[num1]].insert(num1);
						}
						else{
							a[num1] = 0;
						}
					}
					//s.erase(num);
					m.erase(num);
				}
			}
		}
		int k = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] != 0) b[k++] = a[i];
		}
		printf("%d\n",k);
		for(int i = 0; i < k; i++){
			if(i == k-1) printf("%u\n",b[i]);
			else printf("%u ",b[i]);
		}
	}
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;
        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;

    }
    if(ya != -1) ans.pb(mp(yi, ya)), cout<<ya<<endl;

    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for(int i = 0; i < ans.size(); i++)
        printf("%lld ", ans[i].ss);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();

        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
    }
    if(ya != -1) ans.pb(mp(yi, ya));

    sort(ans.begin(), ans.end());
    printf("%d\n%d", ans.size(), ans[0].ss);
    for(int i = 1; i < ans.size(); i++)
        printf(" %d", ans[i].ss);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;
        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
    }
    if(ya != -1) ans.pb(mp(yi, ya));

    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for(int i = 0; i < ans.size(); i++)
        printf("%d ", ans[i].ss);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;
        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;

    }
    if(ya != -1) ans.pb(mp(yi, ya));

    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for(int i = 0; i < ans.size(); i++)
        printf("%lld ", ans[i].ss);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();

        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
    }
    if(ya != -1) ans.pb(mp(yi, ya));

    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for(int i = 0; i < ans.size(); i++)
        printf("%lld ", ans[i].ss);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();

        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
    }
    if(ya != -1) ans.pb(mp(yi, ya));

    sort(ans.begin(), ans.end());
    printf("%d\n%d", ans.size(), ans[0].ss);
    for(int i = 1; i < ans.size(); i++)
        printf(" %d", ans[i].ss);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

vector <ll> v;
priority_queue <ll, vector<ll>, greater<ll> > pq;
map <ll, ll> cnt, f_lst, s_lst;
int arr[150005];

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        if(cnt.find(a) == cnt.end()) pq.push(a);
        cnt[a]++;
        s_lst[a] = f_lst[a];
        f_lst[a] = i;
    }

    ll x, y;
    while(!pq.empty()) {
        x = pq.top();
        pq.pop();
        y = 2*x;

        if(cnt[x] >= 2 && cnt.find(y) == cnt.end()) pq.push(y);

        if(cnt[x] % 2 == 0) {
            cnt[y] += cnt[x]/2;
            arr[f_lst[x]] = 0;

            if(f_lst[x] > f_lst[y]) {
                s_lst[y] = f_lst[y];
                f_lst[y] = f_lst[x];
            }
        }
        else {
            cnt[y] += cnt[x]/2;
            arr[f_lst[x]] = x;

            if(s_lst[x] > f_lst[y]) {
                s_lst[y] = f_lst[y];
                f_lst[y] = s_lst[x];
            }
        }
    }

    for(int i = 1; i <= n; i++)
        if(arr[i] != 0)
            v.pb(arr[i]);

    printf("%d\n", v.size());
    for(int i = 0; i < v.size(); i++)
        cout<<v[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;
        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;

    }
    if(ya != -1) ans.pb(mp(yi, ya));

    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for(int i = 0; i < ans.size(); i++)
        printf("%lld ", ans[i].ss);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf 1e+10
typedef long long ll;
typedef unsigned int ui;
typedef pair<ll, ll> pll;

ll power(ll b, ll p) {
    ll res = 1, x = b;
    while(p) {
        if(p & 1) res = res * x;
        x = x*x, p >>= 1;
    }
    return res;
}

ll bigmod(ll b, ll p, ll m)
{
    ll res = 1%m, x = b%m;
    while(p) {
        if(p & 1) res = (res * x)%m;
        x = (x*x)%m, p >>= 1;
    }
    return res;
}

priority_queue <pll, vector<pll>, greater<pll> > pq;
vector <pll> ans;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n, a;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &a);

        pq.push(mp(a, i));
    }

    ll xa, xi, ya = -1, yi;
    while(!pq.empty()) {
        xa = pq.top().ff, xi = pq.top().ss;
        pq.pop();
        // cout<<ya<<" "<<yi<<" "<<xa<<" "<<xi<<endl;
        if(ya == xa) {
            pq.push(mp(xa*2, xi));
            ya = -1;
        }
        else if(ya != -1) {
            ans.pb(mp(yi, ya));
            yi = xi, ya = xa;
        }
        else if(ya == -1) {
            yi = xi, ya = xa;
        }
    }
    if(ya != -1) ans.pb(mp(yi, ya));

    sort(ans.begin(), ans.end());
    printf("%d\n%d", ans.size(), ans[0].ss);
    for(int i = 1; i < ans.size(); i++)
        printf(" %d", ans[i].ss);
}


#include<complex>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <limits>
#include <climits>
#include <time.h>
#include <cstdio>
#include <numeric>
#define LL long long
#define rei(x) scanf("%d",&x)
#define reii(x,y) scanf("%d%d",&x,&y)
#define reiii(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define rel(x) scanf("%I64d",&x);

#define ref(x) scanf("%lf",&x)
#define rec(x) scanf("%c",&x)
#define res(x) scanf("%s",x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define ms(Arr) memset(Arr,0,sizeof(Arr));
#define CLR(arr,val)  memset(arr,val,sizeof(arr))
#define bit(a , b) (((a)>>(b))&1)
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define fout1 freopen("out1.txt","w",stdout)
#define ftest freopen("in.txt","w",stdout)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
using namespace std;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
const double e = 2.718281828459;
typedef pair<int, int> Pii;
typedef pair<LL, LL> Pll;

LL gcd(LL a, LL b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL gcd1(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL pow_mod(LL a, LL b, LL c)
{
	LL ans = 1;
	a = a % c;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % c;
		b = b / 2;
		a = (a * a) % c;
	}
	return ans;
}

int pow_int(int a, int b)
{
	int ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

LL pow_llong(LL a, LL b)
{
	LL ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

const int dx[9] = { 0, 1, 1, 1, 0,-1,-1,-1, 0 };
const int dy[9] = { 0, 1, 0,-1,-1,-1, 0, 1, 1 };

int Scan()
{
	int res = 0, flag = 0;
	char ch;
	if ((ch = getchar()) == '-')
	{
		flag = 1;
	}
	else if (ch >= '0' && ch <= '9')
	{
		res = ch - '0';
	}
	while ((ch = getchar()) >= '0' && ch <= '9')
	{
		res = res * 10 + (ch - '0');
	}
	return flag ? -res : res;
}

void Out(int a)
{
	if (a < 0)
	{
		putchar('-');
		a = -a;
	}
	if (a >= 10)
	{
		Out(a / 10);
	}
	putchar(a % 10 + '0');
}

LL jc_mod(LL a, LL b, LL mod)
{
	LL ans = 1;
	b = max(b, a - b);
	for (LL i = a; i > b; i--)
	{
		ans *= i;
		ans %= mod;
	}
	return ans;
}

double lg(double a)
{
	return (log(a) / log(10.0));
}

int lowbit(int x)
{
	return x & -x;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//long long：-9223372036854775808~9223372036854775807
//int：-2147483648~2147483647
//double：-1.7*10^-308~1.7*10^308，15~16位有效数字
//long double：-1.2*10^-4932~1.2*10^4932，18~19位有效数字
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline int read()
{
	int f = 1, x = 0; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x*f;
}

/*******************************************************
自定义结构体排序
struct Struct_Name
{
int variable;
bool operator <(const Struct_Name &other)const   //升序排序
{
return variable > other.variable;
}
};
*******************************************************/

//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAXNN 100010
void lisan(int *x, int n) {
	//首先c++调用一个数组直接打这个数组的类型就好了。
	int data[MAXNN];
	f(i, 1, n)data[i] = x[i];
	sort(data + 1, data + 1 + n);//排序是肯定要的。
	int o = unique(data + 1, data + 1 + n) - data - 1;//给data数组[1..n]去重，黑科技
	f(i, 1, n)x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;//找到x[i]在data中的位置再赋值为这个位置，如果不-data就是返回这个值。
}
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int calc(int M)
{
	return 1;
}
int sanfen(int L, int R)
{
	int M, RM;
	while (L + 1 < R)
	{
		M = (L + R) / 2;
		RM = (M + R) / 2;
		if (calc(M) < calc(RM)) //计算最小值,若为最大值则>
			R = RM;
		else
			L = M;
	}
	return L;
}

int CaculateWeekDay(int y, int m, int d)
{
	if (m == 1 || m == 2) {
		m += 12;
		y--;
	}
	int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
	return iWeek;
}

////////////////////////////////////////////////////e nd/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

priority_queue<int,vector<int>,greater<int>> q;
map<int,int> mm;
vector<vector<int>> v;
int a[160000];
int main()
{
	int n;
	rei(n);
	int j = 0;
	f(i, 1, n)
	{
		rei(a[i]);
		if (i == 1 ||	!mm[a[i]] && a[i] != a[1])
		{
			mm[a[i]] = j++;
			vector<int> b;
			b.push_back(i);
			v.push_back(b);
		}
		else
		{
			v[mm[a[i]]].push_back(i);
			if(v[mm[a[i]]].size() == 2)
				q.push(a[i]);
		}
	}
	while (q.size())
	{
		a[v[mm[q.top()]][0]] = -1;
		v[mm[q.top()]].erase(v[mm[q.top()]].begin());
		a[v[mm[q.top()]][0]] <<= 1;
		int flag = 0;
		if (v[mm[q.top()]].size() <= 2)
			flag = 1;
		if (!mm[a[v[mm[q.top()]][0]]])
		{
			mm[a[v[mm[q.top()]][0]]] = j++;
			vector<int> b;
			b.push_back(v[mm[q.top()]][0]);
			v.push_back(b);
		}
		else
		{
			v[mm[a[v[mm[q.top()]][0]]]].push_back(v[mm[q.top()]][0]);
			if (v[mm[a[v[mm[q.top()]][0]]]].size() == 2)
			{
				q.push(a[v[mm[q.top()]][0]]);
				sort(v[mm[a[v[mm[q.top()]][0]]]].begin(), v[mm[a[v[mm[q.top()]][0]]]].end());
			}
		}
		v[mm[q.top()]].erase(v[mm[q.top()]].begin());
		if (flag)
			q.pop();
	}
	int co = 0;
	for (int i = 0; i < v.size(); i++)
		if (v[i].size())
			co++;
	printf("%d\n", co);
	f(i, 1, n)
	{
		if (a[i] > 0)
			printf("%d ", a[i]);
	}
	printf("\n");
	return 0;
}


#include<complex>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <limits>
#include <climits>
#include <time.h>
#include <cstdio>
#include <numeric>
#define LL long long
#define rei(x) scanf("%d",&x)
#define reii(x,y) scanf("%d%d",&x,&y)
#define reiii(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define rel(x) scanf("%I64d",&x);

#define ref(x) scanf("%lf",&x)
#define rec(x) scanf("%c",&x)
#define res(x) scanf("%s",x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define ms(Arr) memset(Arr,0,sizeof(Arr));
#define CLR(arr,val)  memset(arr,val,sizeof(arr))
#define bit(a , b) (((a)>>(b))&1)
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define fout1 freopen("out1.txt","w",stdout)
#define ftest freopen("in.txt","w",stdout)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
using namespace std;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
const double e = 2.718281828459;
typedef pair<int, int> Pii;
typedef pair<LL, LL> Pll;

LL gcd(LL a, LL b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL gcd1(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL pow_mod(LL a, LL b, LL c)
{
	LL ans = 1;
	a = a % c;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % c;
		b = b / 2;
		a = (a * a) % c;
	}
	return ans;
}

int pow_int(int a, int b)
{
	int ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

LL pow_llong(LL a, LL b)
{
	LL ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

const int dx[9] = { 0, 1, 1, 1, 0,-1,-1,-1, 0 };
const int dy[9] = { 0, 1, 0,-1,-1,-1, 0, 1, 1 };

int Scan()
{
	int res = 0, flag = 0;
	char ch;
	if ((ch = getchar()) == '-')
	{
		flag = 1;
	}
	else if (ch >= '0' && ch <= '9')
	{
		res = ch - '0';
	}
	while ((ch = getchar()) >= '0' && ch <= '9')
	{
		res = res * 10 + (ch - '0');
	}
	return flag ? -res : res;
}

void Out(int a)
{
	if (a < 0)
	{
		putchar('-');
		a = -a;
	}
	if (a >= 10)
	{
		Out(a / 10);
	}
	putchar(a % 10 + '0');
}

LL jc_mod(LL a, LL b, LL mod)
{
	LL ans = 1;
	b = max(b, a - b);
	for (LL i = a; i > b; i--)
	{
		ans *= i;
		ans %= mod;
	}
	return ans;
}

double lg(double a)
{
	return (log(a) / log(10.0));
}

int lowbit(int x)
{
	return x & -x;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//long long：-9223372036854775808~9223372036854775807
//int：-2147483648~2147483647
//double：-1.7*10^-308~1.7*10^308，15~16位有效数字
//long double：-1.2*10^-4932~1.2*10^4932，18~19位有效数字
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline int read()
{
	int f = 1, x = 0; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x*f;
}

/*******************************************************
自定义结构体排序
struct Struct_Name
{
int variable;
bool operator <(const Struct_Name &other)const   //升序排序
{
return variable > other.variable;
}
};
*******************************************************/

//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAXNN 100010
void lisan(int *x, int n) {
	//首先c++调用一个数组直接打这个数组的类型就好了。
	int data[MAXNN];
	f(i, 1, n)data[i] = x[i];
	sort(data + 1, data + 1 + n);//排序是肯定要的。
	int o = unique(data + 1, data + 1 + n) - data - 1;//给data数组[1..n]去重，黑科技
	f(i, 1, n)x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;//找到x[i]在data中的位置再赋值为这个位置，如果不-data就是返回这个值。
}
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int calc(int M)
{
	return 1;
}
int sanfen(int L, int R)
{
	int M, RM;
	while (L + 1 < R)
	{
		M = (L + R) / 2;
		RM = (M + R) / 2;
		if (calc(M) < calc(RM)) //计算最小值,若为最大值则>
			R = RM;
		else
			L = M;
	}
	return L;
}

int CaculateWeekDay(int y, int m, int d)
{
	if (m == 1 || m == 2) {
		m += 12;
		y--;
	}
	int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
	return iWeek;
}

////////////////////////////////////////////////////e nd/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int tmain()
{
	//fout;
	printf("150000\n");
	f(i, 1, 150000)
	{
		printf("1000000000\n");
	}
	return 0;
}
priority_queue<LL,vector<LL>,greater<LL>> q;
map<LL,int> mm;
vector<vector<LL>> v;
LL a[160000];
int main()
{
	int n;
	rei(n);
	int j = 0;
	f(i, 1, n)
	{
		rel(a[i]);
		if (i == 1 ||	!mm[a[i]] && a[i] != a[1])
		{
			mm[a[i]] = j++;
			vector<LL> b;
			b.push_back(i);
			v.push_back(b);
		}
		else
		{
			v[mm[a[i]]].push_back(i);
			if(v[mm[a[i]]].size() == 2)
				q.push(a[i]);
		}
	}
	while (q.size())
	{
		int tt = mm[q.top()];
		for (int i = 0; i + 1 < v[tt].size(); i+=2)
		{
			a[v[tt][i]] = -1;
			a[v[tt][i+1]] <<= 1;
			if (mm[q.top() << 1] || q.top() << 1 == a[1])
			{
				v[mm[q.top()<<1]].push_back(v[tt][i + 1]);
				if (v[mm[q.top() << 1]].size() == 2)
					q.push(q.top() << 1);
			}
			else
			{
				mm[q.top() << 1] = j++;
				vector<LL> b;
				b.push_back(v[tt][i + 1]);
				v.push_back(b);
			}
			sort(v[mm[q.top() << 1]].begin(), v[mm[q.top() << 1]].end());
		}
		q.pop();
	}
	int co = 0;
	f(i, 1, n)
	{
		if (a[i] > 0)
			co++;
	}
	printf("%d\n", co);
	f(i, 1, n)
	{
		if (a[i] > 0)
			printf("%I64d ", a[i]);
	}
	printf("\n");
	return 0;
}


#include<complex>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <limits>
#include <climits>
#include <time.h>
#include <cstdio>
#include <numeric>
#define LL long long
#define rei(x) scanf("%d",&x)
#define reii(x,y) scanf("%d%d",&x,&y)
#define reiii(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define rel(x) scanf("%I64d",&x);

#define ref(x) scanf("%lf",&x)
#define rec(x) scanf("%c",&x)
#define res(x) scanf("%s",x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define ms(Arr) memset(Arr,0,sizeof(Arr));
#define CLR(arr,val)  memset(arr,val,sizeof(arr))
#define bit(a , b) (((a)>>(b))&1)
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define fout1 freopen("out1.txt","w",stdout)
#define ftest freopen("in.txt","w",stdout)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
using namespace std;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
const double e = 2.718281828459;
typedef pair<int, int> Pii;
typedef pair<LL, LL> Pll;

LL gcd(LL a, LL b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL gcd1(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL pow_mod(LL a, LL b, LL c)
{
	LL ans = 1;
	a = a % c;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % c;
		b = b / 2;
		a = (a * a) % c;
	}
	return ans;
}

int pow_int(int a, int b)
{
	int ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

LL pow_llong(LL a, LL b)
{
	LL ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

const int dx[9] = { 0, 1, 1, 1, 0,-1,-1,-1, 0 };
const int dy[9] = { 0, 1, 0,-1,-1,-1, 0, 1, 1 };

int Scan()
{
	int res = 0, flag = 0;
	char ch;
	if ((ch = getchar()) == '-')
	{
		flag = 1;
	}
	else if (ch >= '0' && ch <= '9')
	{
		res = ch - '0';
	}
	while ((ch = getchar()) >= '0' && ch <= '9')
	{
		res = res * 10 + (ch - '0');
	}
	return flag ? -res : res;
}

void Out(int a)
{
	if (a < 0)
	{
		putchar('-');
		a = -a;
	}
	if (a >= 10)
	{
		Out(a / 10);
	}
	putchar(a % 10 + '0');
}

LL jc_mod(LL a, LL b, LL mod)
{
	LL ans = 1;
	b = max(b, a - b);
	for (LL i = a; i > b; i--)
	{
		ans *= i;
		ans %= mod;
	}
	return ans;
}

double lg(double a)
{
	return (log(a) / log(10.0));
}

int lowbit(int x)
{
	return x & -x;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//long long：-9223372036854775808~9223372036854775807
//int：-2147483648~2147483647
//double：-1.7*10^-308~1.7*10^308，15~16位有效数字
//long double：-1.2*10^-4932~1.2*10^4932，18~19位有效数字
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline int read()
{
	int f = 1, x = 0; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x*f;
}

/*******************************************************
自定义结构体排序
struct Struct_Name
{
int variable;
bool operator <(const Struct_Name &other)const   //升序排序
{
return variable > other.variable;
}
};
*******************************************************/

//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAXNN 100010
void lisan(int *x, int n) {
	//首先c++调用一个数组直接打这个数组的类型就好了。
	int data[MAXNN];
	f(i, 1, n)data[i] = x[i];
	sort(data + 1, data + 1 + n);//排序是肯定要的。
	int o = unique(data + 1, data + 1 + n) - data - 1;//给data数组[1..n]去重，黑科技
	f(i, 1, n)x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;//找到x[i]在data中的位置再赋值为这个位置，如果不-data就是返回这个值。
}
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int calc(int M)
{
	return 1;
}
int sanfen(int L, int R)
{
	int M, RM;
	while (L + 1 < R)
	{
		M = (L + R) / 2;
		RM = (M + R) / 2;
		if (calc(M) < calc(RM)) //计算最小值,若为最大值则>
			R = RM;
		else
			L = M;
	}
	return L;
}

int CaculateWeekDay(int y, int m, int d)
{
	if (m == 1 || m == 2) {
		m += 12;
		y--;
	}
	int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
	return iWeek;
}

////////////////////////////////////////////////////e nd/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

priority_queue<LL,vector<LL>,greater<LL>> q;
map<LL,int> mm;
vector<vector<LL>> v;
LL a[160000];
int main()
{
	int n;
	rei(n);
	int j = 0;
	f(i, 1, n)
	{
		rel(a[i]);
		if (i == 1 ||	!mm[a[i]] && a[i] != a[1])
		{
			mm[a[i]] = j++;
			vector<LL> b;
			b.push_back(i);
			v.push_back(b);
		}
		else
		{
			v[mm[a[i]]].push_back(i);
			if(v[mm[a[i]]].size() == 2)
				q.push(a[i]);
		}
	}
	while (q.size())
	{
		a[v[mm[q.top()]][0]] = -1;
		v[mm[q.top()]].erase(v[mm[q.top()]].begin());
		a[v[mm[q.top()]][0]] <<= 1;
		int flag = 0;
		if (v[mm[q.top()]].size() <= 2)
			flag = 1;
		if (!mm[a[v[mm[q.top()]][0]]])
		{
			mm[a[v[mm[q.top()]][0]]] = j++;
			vector<LL> b;
			b.push_back(v[mm[q.top()]][0]);
			v.push_back(b);
		}
		else
		{
			int l = 0, r = v[mm[a[v[mm[q.top()]][0]]]].size() - 1;
			while (r > l)
			{
				int mid = (l + r) >> 1;
				if (v[mm[a[v[mm[q.top()]][0]]]][mid] > v[mm[q.top()]][0])
					r = mid;
				else
					l = mid + 1;
			}

			v[mm[a[v[mm[q.top()]][0]]]].insert(v[mm[a[v[mm[q.top()]][0]]]].begin() + l, v[mm[q.top()]][0]);
			if (v[mm[a[v[mm[q.top()]][0]]]].size() == 2)
			{
				q.push(a[v[mm[q.top()]][0]]);
				sort(v[mm[a[v[mm[q.top()]][0]]]].begin(), v[mm[a[v[mm[q.top()]][0]]]].end());
			}
		}
		v[mm[q.top()]].erase(v[mm[q.top()]].begin());
		if (flag)
			q.pop();
	}
	int co = 0;
	for (int i = 0; i < v.size(); i++)
		if (v[i].size())
			co++;
	printf("%d\n", co);
	f(i, 1, n)
	{
		if (a[i] > 0)
			printf("%I64d ", a[i]);
	}
	printf("\n");
	return 0;
}