#include<bits/stdc++.h>
using namespace std;
map<long long, set<long long> > m;
int main()
{
    // set<long long> s;
    // s.remove(5);
    int n;
    cin>>n;
    long long ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        m[ar[i]].insert(i);
    }
    int s=0;
    set<long long> q;
    for(long long i=0;i<n;i++)
    {
        if(m[ar[i]].size() >= 2)
        {
            q.insert(i);
        }
    }
    // //cout<<"here";
    while(!q.empty())
    {
        //cout<<"X: "<<i<<endl;
        int i = *q.begin();
        q.erase(q.begin());
        if(m[ar[i]].size() >=2 && i == *m[ar[i]].begin())
        {
            set<long long>::iterator it = m[ar[i]].begin();
            long long pos = *(it);
            it++;
            long long pos2 = *(it);
            m[ar[i]].erase(m[ar[i]].begin());
            m[ar[i]].erase(it);

            ar[pos2]*=2;
            m[ar[pos2]].insert(pos2);

            if(m[ar[pos2]].size() >= 2)
            {
                q.insert(*(m[ar[pos2]].begin()));
            }
            if(m[ar[pos]].size() >=2 )
            {
                q.insert(*(m[ar[pos]].begin()));
            }
            ar[pos] = -1;
            //cout<<"Pos: "<<pos<<endl;
            // m[ar[i]].erase(m[ar[i]].begin());
            //cout<<ar[i]<<endl;
            // long long t=pos;
            // pos = *(m[ar[t]].begin());
            // if(m[ar[i]].size()>=2)
            // {
            //     q.push(i);
            // }

            // ar[t]=-1;
            //cout<<"Next: "<<pos<<endl;
            // ar[pos]*=2;
            // m[ar[pos]].insert(pos);
            // if(m[ar[i]].size()>=2)
            // {
            //     q.push(i);
            // }
            // m[ar[pos]/2].erase(m[ar[pos]/2].begin());
            // if(m[ar[pos]/2].size()>=2)
            // {
            //     q.push(pos);
            // }
        }
    }
    int c=0;
    for(int i=0;i<n;i++)
    {
        if(ar[i]!=-1)
        {
            c++;
            // cout<<ar[i]<<" ";
        }
    }
    cout<<c<<endl;
    for(int i=0;i<n;i++)
    {
        if(ar[i]!=-1)
        {
            cout<<ar[i]<<" ";
        }
    }
}


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[3000001]  , assign ;
set < int > :: iterator sit,it1,it ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < ll , ll > mapp,revmap ;
vector < ll > v ;
int n,m,q,k ;
ll a[N] ;
int main()
{
int i , j , t ;

sc(n) ;
int cnt=1;
for(i=1;i<=n;i++)
{
	scanf("%lld",&a[i]) ;
	ll tmp=1LL;
	for(j=0;j<=20;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1LL ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[1000001]  , assign ;
set < int > :: iterator sit,it1,it ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < int , int > mapp,revmap ;
vector < ll > v ;
int n,m,q,k ;
int a[N] ;
int main()
{
int i , j , t ;

sc(n) ;
int cnt=1;
for(i=1;i<=n;i++)
{
	scanf("%d",&a[i]) ;
	ll tmp=1LL;
	for(j=0;j<=20;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1 ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;

vector < ll > v ;
vector < int > vi ;

int n,m,q,k ;
int a[N] ;
map < ll , ll >  mapp ;
map < ll , ll > :: iterator it ;
int main()
{
int i , j , t ;
sc(n) ;
for(i=1;i<=n;i++)
scanf("%lld",&a[i]) ;

for(i=1;i<=n;)
{
	if(mapp.find(a[i]) == mapp.end())
	{
		mapp[a[i]]=i ;
		i++ ;
	}
	else
	{
		it = mapp.find(a[i]) ;
		int ind = it->second;
		ll ele = it->first;
	//	printf("ind = %d\n",ind) ;
		a[ind]=-1 ;
		mapp.erase(it) ;
		a[i]=2LL*ele ;
	}
}

for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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

return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[1000000]  ;
set < int > :: iterator it1 ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < ll , int > mapp,freq ;
map < int , ll > revmap ;
vector < ll > v ;
int n,m,q,k ;
ll a[N] ;
int gett(int x)
{
	int cntt = 0 ;
	while(x)
	{
		cntt++ ;
		x/=2;
	}
return 2*cntt ;
}
int main()
{
int i , j , t ;

sc(n) ;
for(i=1;i<=n;i++)
{
	scanf("%lld",&a[i]) ;
	freq[a[i]]++ ;
}
int cnt=1;
for(i=1;i<=n;i++)
{
	ll tmp=1LL;
	int lc = gett(freq[lc]) ;
	for(j=0;j<=lc;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1LL ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[18*100000]  ;
set < int > :: iterator it1 ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < ll , int > mapp,freq ;
map < int , ll > revmap ;
vector < ll > v ;
int n,m,q,k ;
ll a[N] ;
int gett(int x)
{
	int cntt = 0 ;
	while(x)
	{
		cntt++ ;
		x/=2;
	}
return 4*cntt ;
}
int main()
{
int i , j , t ;

sc(n) ;
for(i=1;i<=n;i++)
{
	scanf("%lld",&a[i]) ;
	freq[a[i]]++ ;
}
int cnt=1;
for(i=1;i<=n;i++)
{
	ll tmp=1LL;
	int lc = gett(freq[lc]) ;
	for(j=0;j<=18;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1LL ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[1000000]  ;
set < int > :: iterator it1 ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < ll , int > mapp,freq ;
map < int , ll > revmap ;
vector < ll > v ;
int n,m,q,k ;
ll a[N] ;
int gett(int x)
{
	int cntt = 0 ;
	while(x)
	{
		cntt++ ;
		x/=2;
	}
return 4*cntt ;
}
int main()
{
int i , j , t ;

sc(n) ;
for(i=1;i<=n;i++)
{
	scanf("%lld",&a[i]) ;
	freq[a[i]]++ ;
}
int cnt=1;
for(i=1;i<=n;i++)
{
	ll tmp=1LL;
	int lc = gett(freq[lc]) ;
	for(j=0;j<=lc;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1LL ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;

vector < ll > v ;
vector < int > vi ;

int n,m,q,k ;
ll a[N] ;
map < ll , int >  mapp ;
map < ll , int > :: iterator it ;
int main()
{
int i , j , t ;
sc(n) ;
for(i=1;i<=n;i++)
scanf("%lld",&a[i]) ;

for(i=1;i<=n;)
{
	if(mapp.find(a[i]) == mapp.end())
	{
		mapp[a[i]]=i ;
		i++ ;
	}
	else
	{
		it = mapp.find(a[i]) ;
		int ind = it->second;
		ll ele = it->first;
	//	printf("ind = %d\n",ind) ;
		a[ind]=-1 ;
		mapp.erase(it) ;
		a[i]=2LL*ele ;
	}
}

for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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

return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[1000000]  ;
set < int > :: iterator it1 ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < ll , int > mapp,freq ;
map < int , ll > revmap ;
vector < ll > v ;
int n,m,q,k ;
ll a[N] ;
int gett(int x)
{
	int cntt = 0 ;
	while(x)
	{
		cntt++ ;
		x/=2;
	}
return cntt+3 ;
}
int main()
{
int i , j , t ;

sc(n) ;
for(i=1;i<=n;i++)
{
	scanf("%lld",&a[i]) ;
	freq[a[i]]++ ;
}
int cnt=1;
for(i=1;i<=n;i++)
{
	ll tmp=1LL;
	int lc = gett(freq[lc]) ;
	for(j=0;j<=lc;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1LL ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[19*100000]  , assign ;
set < int > :: iterator sit,it1,it ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < ll , ll > mapp,revmap ;
vector < ll > v ;
int n,m,q,k ;
ll a[N] ;
int main()
{
int i , j , t ;

sc(n) ;
int cnt=1;
for(i=1;i<=n;i++)
{
	scanf("%lld",&a[i]) ;
	ll tmp=1LL;
	for(j=0;j<=18;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1LL ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define mp make_pair
#define infile() freopen("large.in","r",stdin);
#define output() freopen("output.txt","w",stdout);
#define ll long long
#define sc(t); scanf("%d",&t);
#define scl(t); scanf("%lld",&t);
#define sc2(n,m); scanf("%d%d",&n,&m);
#define scl2(n,m); scanf("%lld%lld",&n,&m);
#define debug(); printf("tushar\n");
#define N 200005
#define mod 1000000007
#define printi(n) printf("%d",n);
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
set < int > s[1000001]  , assign ;
set < int > :: iterator sit,it1,it ;
set  < ll > rec ;
set < ll > :: iterator recit ;
map < int , int > mapp,revmap ;
vector < ll > v ;
int n,m,q,k ;
ll a[N] ;
int main()
{
int i , j , t ;

sc(n) ;
int cnt=1;
for(i=1;i<=n;i++)
{
	scanf("%lld",&a[i]) ;
	ll tmp=1LL;
	for(j=0;j<=25;j++)
	{
		ll tmp2 = a[i]*tmp ;
		//if(tmp2 == 2)
		//printf("yaha to fuch ho rha hai\n") ;
		rec.insert(tmp2) ;
		tmp*=2LL ;
	}
}

for(recit = rec.begin() ; recit != rec.end() ; recit++ )
{
	ll num = (*recit) ;
	mapp[num] = cnt ;
	revmap[cnt] = num ;
	cnt++ ;
}

for(i=1;i<=n;i++)
{
	s[mapp[a[i]]].insert(i) ;
}
for(i=1;i<=cnt;i++)
{
	ll numwas = revmap[i] ;
	while(1)
	{
		if(s[i].size() <= 1)
		break;
	//	printf("i = %d numwas= %lld sz = %d\n",i,numwas,s[i].size()) ;
		it1 = s[i].begin() ;
		int ind1 = (*it1) ;
		s[i].erase(it1) ;
		it1 = s[i].begin() ;
		int ind2 = (*it1) ;
		s[i].erase(it1);
		a[ind1] = -1LL ;
		a[ind2] = 2LL*numwas ;
	//	printf("num2 = %lld ind2 = %d\n",2LL*numwas,ind2) ;
		s[mapp[2LL*numwas]].insert(ind2) ;
	}
}

//printf("revmap2 = %d s[2]sz = %d\n",mapp[2],s[mapp[2]].size()) ;
for(i=1;i<=n;i++){
	if(a[i] != -1)
	v.pb(a[i]) ;
}

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


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 3e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }
template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }

map<ll, set<int> > m;
ll pre[maxn];
ll a[maxn];

void special(ll cnt)
{
	cout<<cnt<<ln;
	for(int i = 1; i <= cnt; i++) cout<<a[i]<<" ";
//	map<ll, set<int> >::iterator it = m.begin();
//	while(it != m.end()){
//		cout<<it->fr<<" ";
//		it++;
//	}
	exit(0);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, n;
    cin>>n;
    ll cnt = 0;
    for(i = 1; i <= n; i++){
		ll x; cin>>x; a[i] = x;
		m[x].insert(i);
		if(m[x].size() == 1) cnt++;
    }

    if(cnt == n) special(cnt);

    map<ll, set<int> >::iterator it = m.begin();
    while(it != m.end()){
		set<int> &pos = it->sc;
		ll x = it->fr;

		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			ll p2 = *pos.begin(); pos.erase(p2);
//			ll right = p2;
			pre[p1+1] -= 1;
			m[2*x].insert(p2);
		}
		it++;
    }

    for(i = 1; i <= n; i++) pre[i] += pre[i-1];
	cnt = 0;
    it = m.begin();
    while(it != m.end()){
        set<int> &pos = it->sc;
        while(pos.size()){
			ll index = *pos.begin(); pos.erase(index);
			index = index + pre[index];
			pre[index] = it->fr;
			cnt++;
        }
        it++;
    }

    i = 1;
    cout<<cnt<<ln;
    while(pre[i] > 0){
		cout<<pre[i]<<" ";
		i++;
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 3e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }
template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }

map<ll, set<int> > m;
ll pre[maxn];
ll a[maxn];

void special(ll cnt)
{
	cout<<cnt<<ln;
	for(int i = 1; i <= cnt; i++) cout<<a[i]<<" ";
//	map<ll, set<int> >::iterator it = m.begin();
//	while(it != m.end()){
//		cout<<it->fr<<" ";
//		it++;
//	}
	exit(0);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, n;
    cin>>n;
    ll cnt = 0;
    for(i = 1; i <= n; i++){
		ll x; cin>>x; a[i] = x;
		m[x].insert(i);
		if(m[x].size() == 1) cnt++;
    }

    if(cnt == n) special(cnt);

    map<ll, set<int> >::iterator it = m.begin();
    while(it != m.end()){
		set<int> &pos = it->sc;
		ll x = it->fr;

		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			ll p2 = *pos.begin(); pos.erase(p2);
//			ll right = p2;
			pre[p1+1] -= 1;
			m[2*x].insert(p2);
		}
		it++;
    }

    for(i = 1; i <= n; i++) pre[i] += pre[i-1];
	cnt = 0;
    it = m.begin();
    while(it != m.end()){
        set<int> &pos = it->sc;
        while(pos.size()){
			ll index = *pos.begin(); pos.erase(index);
			index = index + pre[index];
			pre[index] = it->fr;
			cnt++;
        }
        it++;
    }

    i = 1;
    cout<<cnt<<ln;
    while(pre[i] >= 0){
		cout<<pre[i]<<" ";
		i++;
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 3e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }
template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }

map<ll, set<int> > m;
ll pre[maxn];
ll a[maxn];

void special(ll cnt)
{
	cout<<cnt<<ln;
	for(int i = 1; i <= cnt; i++) cout<<a[i]<<" ";
//	map<ll, set<int> >::iterator it = m.begin();
//	while(it != m.end()){
//		cout<<it->fr<<" ";
//		it++;
//	}
	exit(0);
}

void f(ll n)
{
	map<ll, set<int> > :: iterator it = m.begin();
	while(it != m.end()){
		ll x = it->fr;
		set<int> &pos = it->sc;
		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			a[p1] = 0;
			ll p2 = *pos.begin(); pos.erase(p2);
			a[p2] = 2*x;
			m[2*x].insert(p2);
		}
		it++;
	}

	ll cnt = 0;
	for(int i = 1; i <= n; i++)
		if(a[i]) cnt++;

	cout<<cnt<<ln;
	for(int i = 1; i <= n; i++){
		if(a[i]) cout<<a[i]<<" ";
	}

	exit(0);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, n;
    cin>>n;
    ll cnt = 0;
    for(i = 1; i <= n; i++){
		ll x; cin>>x; a[i] = x;
		m[x].insert(i);
		if(m[x].size() == 1) cnt++;
    }

    if(cnt == n) special(cnt);
    //	f(n);

    map<ll, set<int> >::iterator it = m.begin();
    while(it != m.end()){
		set<int> &pos = it->sc;
		ll x = it->fr;

		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			ll p2 = *pos.begin(); pos.erase(p2);
//			ll right = p2;
			pre[p1+1] -= 1;
			m[2*x].insert(p2);
		}
		it++;
    }

    for(i = 1; i <= n; i++) pre[i] += pre[i-1];
	cnt = 0;
    it = m.begin();
    while(it != m.end()){
        set<int> &pos = it->sc;
        while(pos.size()){
			ll index = *pos.begin(); pos.erase(index);
			index = index + pre[index];
			pre[index] = it->fr;
			cnt++;
        }
        it++;
    }

    i = 1;
    cout<<cnt<<ln;
    while(pre[i] > 0){
		cout<<pre[i]<<" ";
		i++;
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }
template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }

map<ll, set<int> > m;
ll pre[maxn];
ll a[maxn];

void special(ll cnt)
{
	cout<<cnt<<ln;
	for(int i = 1; i <= cnt; i++) cout<<a[i]<<" ";
//	map<ll, set<int> >::iterator it = m.begin();
//	while(it != m.end()){
//		cout<<it->fr<<" ";
//		it++;
//	}
	exit(0);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, n;
    cin>>n;
    ll cnt = 0;
    for(i = 1; i <= n; i++){
		ll x; cin>>x; a[i] = x;
		m[x].insert(i);
		if(m[x].size() == 1) cnt++;
    }

    if(cnt == n) special(cnt);

    map<ll, set<int> >::iterator it = m.begin();
    while(it != m.end()){
		set<int> &pos = it->sc;
		ll x = it->fr;

		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			ll p2 = *pos.begin(); pos.erase(p2);
//			ll right = p2;
			pre[p1+1] -= 1;
			m[2*x].insert(p2);
		}
		it++;
    }

    for(i = 1; i <= n; i++) pre[i] += pre[i-1];
	cnt = 0;
    it = m.begin();
    while(it != m.end()){
        set<int> &pos = it->sc;
        while(pos.size()){
			ll index = *pos.begin(); pos.erase(index);
			index = index + pre[index];
			pre[index] = it->fr;
			cnt++;
        }
        it++;
    }

    i = 1;
    cout<<cnt<<ln;
    while(pre[i] >= 0){
		cout<<pre[i]<<" ";
		i++;
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }
template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }

map<ll, set<int> > m;
ll pre[maxn];
//	ll ans[maxn];

void special(ll cnt)
{
	cout<<cnt<<ln;
	map<ll, set<int> >::iterator it = m.begin();
	while(it != m.end()){
		cout<<it->fr<<" ";
		it++;
	}
	exit(0);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, n;
    cin>>n;
    ll cnt = 0;
    for(i = 1; i <= n; i++){
		ll x; cin>>x;
		m[x].insert(i);
		if(m[x].size() == 1) cnt++;
    }

    special(cnt);

    map<ll, set<int> >::iterator it = m.begin();
    while(it != m.end()){
		set<int> &pos = it->sc;
		ll x = it->fr;

		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			ll p2 = *pos.begin(); pos.erase(p2);
//			ll right = p2;
			pre[p1+1] -= 1;
			m[2*x].insert(p2);
		}
		it++;
    }

    for(i = 1; i <= n; i++) pre[i] += pre[i-1];
	cnt = 0;
    it = m.begin();
    while(it != m.end()){
        set<int> &pos = it->sc;
        while(pos.size()){
			ll index = *pos.begin(); pos.erase(index);
			index = index + pre[index];
			pre[index] = it->fr;
			cnt++;
        }
        it++;
    }

    i = 1;
    cout<<cnt<<ln;
    while(pre[i] >= 0){
		cout<<pre[i]<<" ";
		i++;
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 150000+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }
template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }

map<ll, set<int> > m;
ll pre[maxn];
ll a[maxn];

void special(ll cnt)
{
	cout<<cnt<<ln;
	for(int i = 1; i <= cnt; i++) cout<<a[i]<<" ";
//	map<ll, set<int> >::iterator it = m.begin();
//	while(it != m.end()){
//		cout<<it->fr<<" ";
//		it++;
//	}
	exit(0);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, n;
    cin>>n;
    ll cnt = 0;
    for(i = 1; i <= n; i++){
		ll x; cin>>x; a[i] = x;
		m[x].insert(i);
		if(m[x].size() == 1) cnt++;
    }

    if(cnt == n) special(cnt);

    map<ll, set<int> >::iterator it = m.begin();
    while(it != m.end()){
		set<int> &pos = it->sc;
		ll x = it->fr;

		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			ll p2 = *pos.begin(); pos.erase(p2);
//			ll right = p2;
			pre[p1+1] -= 1;
			m[2*x].insert(p2);
		}
		it++;
    }

    for(i = 1; i <= n; i++) pre[i] += pre[i-1];
	cnt = 0;
    it = m.begin();
    while(it != m.end()){
        set<int> &pos = it->sc;
        while(pos.size()){
			ll index = *pos.begin(); pos.erase(index);
			index = index + pre[index];
			pre[index] = it->fr;
			cnt++;
        }
        it++;
    }

    i = 1;
    cout<<cnt<<ln;
    while(pre[i] >= 0){
		cout<<pre[i]<<" ";
		i++;
    }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 3e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }
template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }

map<ll, set<int> > m;
ll pre[maxn];
ll a[maxn];

void special(ll cnt)
{
	cout<<cnt<<ln;
	for(int i = 1; i <= cnt; i++) cout<<a[i]<<" ";
//	map<ll, set<int> >::iterator it = m.begin();
//	while(it != m.end()){
//		cout<<it->fr<<" ";
//		it++;
//	}
	exit(0);
}

void f(ll n)
{
	map<ll, set<int> > :: iterator it = m.begin();
	while(it != m.end()){
		ll x = it->fr;
		set<int> &pos = it->sc;
		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			a[p1] = 0;
			ll p2 = *pos.begin(); pos.erase(p2);
			a[p2] = 2*x;
			m[2*x].insert(p2);
		}
		it++;
	}

	ll cnt = 0;
	for(int i = 1; i <= n; i++)
		if(a[i]) cnt++;

	cout<<cnt<<ln;
	for(int i = 1; i <= n; i++){
		if(a[i]) cout<<a[i]<<" ";
	}

	exit(0);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, n;
    cin>>n;
    ll cnt = 0;
    for(i = 1; i <= n; i++){
		ll x; cin>>x; a[i] = x;
		m[x].insert(i);
		if(m[x].size() == 1) cnt++;
    }

    if(cnt == n) special(cnt);
    f(n);

    map<ll, set<int> >::iterator it = m.begin();
    while(it != m.end()){
		set<int> &pos = it->sc;
		ll x = it->fr;

		while(pos.size() > 1){
			ll p1 = *pos.begin(); pos.erase(p1);
			ll p2 = *pos.begin(); pos.erase(p2);
//			ll right = p2;
			pre[p1+1] -= 1;
			m[2*x].insert(p2);
		}
		it++;
    }

    for(i = 1; i <= n; i++) pre[i] += pre[i-1];
	cnt = 0;
    it = m.begin();
    while(it != m.end()){
        set<int> &pos = it->sc;
        while(pos.size()){
			ll index = *pos.begin(); pos.erase(index);
			index = index + pre[index];
			pre[index] = it->fr;
			cnt++;
        }
        it++;
    }

    i = 1;
    cout<<cnt<<ln;
    while(pre[i] > 0){
		cout<<pre[i]<<" ";
		i++;
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
set<ll> pos[N];
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i;
      pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";
       c[a[pt]]++;
       if(c[a[pt]]==1) pos[a[pt]].insert(0),pos[a[pt]].insert(n+1),pre[pt]=0,h[pt]=n+1;
       pos[a[t.se]].erase(t.se); pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
        h[pt]=p1; pre[p1]=pt;
        h[p2]=pt; pre[pt]=p2;
       if(c[a[pt]]>=3)
       {
           int pp=*pos[a[pt]].upper_bound(0);
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
          int pp=*pos[a[pt]].upper_bound(0);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
set<ll> pos[N];
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i; pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {//cout<<pre[i]<<endl;
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";
       c[a[pt]]++;
       if(c[a[pt]]==1)pos[a[pt]].insert(0),pos[a[pt]].insert(n+1);
       pos[a[t.se]].erase(t.se); pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       if(p1<=n) pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
       if(p1<=n) h[pt]=p1; pre[p1]=pt;
       if(p2>=1) h[p2]=pt; pre[pt]=p2;
       if(c[a[pt]]==3)
       {
           int pp=*pos[a[pt]].upper_bound(0);
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
          int pp=*pos[a[pt]].upper_bound(0);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
set<ll> pos[N];
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i;
      pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";
       c[a[pt]]++;
       if(c[a[pt]]==1) pos[a[pt]].insert(0),pos[a[pt]].insert(n+1),pre[pt]=0,h[pt]=n+1;
       pos[a[t.se]].erase(t.se); pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
        h[pt]=p1; pre[p1]=pt;
        h[p2]=pt; pre[pt]=p2;
       int pp=*pos[a[pt]].upper_bound(0);
       if(c[a[pt]]>=3)
       {
           if(s.find(mkp(a[pt],pp))!=s.end())
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
           pp=min(pt,pp);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
map<ll,set<ll> > pos;
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i;
      pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";
       c[a[pt]]++;
       if(c[a[pt]]==1) pos[a[pt]].insert(0),pos[a[pt]].insert(n+1),pre[pt]=0,h[pt]=n+1;
       pos[a[t.se]].erase(t.se); pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
        h[pt]=p1; pre[p1]=pt;
        h[p2]=pt; pre[pt]=p2;
       int pp=*pos[a[pt]].upper_bound(0);
       if(c[a[pt]]>=3)
       {
           if(s.find(mkp(a[pt],pp))!=s.end())
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
           pp=min(pt,pp);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
set<ll> pos[N];
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i;
      pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";
       c[a[pt]]++;
       if(c[a[pt]]==1) pos[a[pt]].insert(0),pos[a[pt]].insert(n+1),pre[pt]=0,h[pt]=n+1;
       pos[a[t.se]].erase(t.se); if(pt<=n) pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
        h[pt]=p1; pre[p1]=pt;
        h[p2]=pt; pre[pt]=p2;
       int pp=*pos[a[pt]].upper_bound(0);
       if(c[a[pt]]>=3)
       {
           if(s.find(mkp(a[pt],pp))!=s.end())
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
          int pp=min(pt,pp);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int>  m;
bool vis[N];
int a[N];
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       ll x;  cin>>x;
       while(m[x])
       {
           int t=m[x];
           vis[t]=1,m[x]=0;
           x*=2;
       }
       a[i]=x;
       m[x]=i;
   }
   int cc=0;
   for(int i=1;i<=n;i++) if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
set<ll> pos[N];
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i; pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";
       c[a[pt]]++;
       if(c[a[pt]]==1) pos[a[pt]].insert(0),pos[a[pt]].insert(n+1),pre[pt]=0,h[pt]=n+1;
       pos[a[t.se]].erase(t.se); pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       if(p1<=n) pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
       if(p1<=n) h[pt]=p1; pre[p1]=pt;
       if(p2>=1) h[p2]=pt; pre[pt]=p2;
       if(c[a[pt]]==3)
       {
           int pp=*pos[a[pt]].upper_bound(0);
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
          int pp=*pos[a[pt]].upper_bound(0);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
set<ll> pos[N];
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i;
      pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";

       c[a[pt]]++;
       if(c[a[pt]]==1) pos[a[pt]].insert(0),pos[a[pt]].insert(n+1),pre[pt]=0,h[pt]=n+1;
       pos[a[t.se]].erase(t.se); pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
        h[pt]=p1; pre[p1]=pt;
        h[p2]=pt; pre[pt]=p2;
       int pp=*pos[a[pt]].upper_bound(0);
       if(c[a[pt]]>=3)
       {
           if(s.find(mkp(a[pt],pp))!=s.end())
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
           pp=min(pt,pp);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(0),pos[a[pt]].insert(n+1);
       pos[a[t.se]].insert(0),pos[a[t.se]].insert(n+1);
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include<bits/stdc++.h>
#define ll  long long
#define int long long
#define inf (1LL<<61)
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=1e6+10;
const ll mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
using namespace std;

map<ll,int> m,pre,c,h,p;
ll a[N];
bool vis[N];
set<pa> s;
set<ll> pos[N];
set<ll> :: iterator u;
main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); srand(time(0));
   int n;  cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       pre[i]=m[a[i]]; m[a[i]]=i;
       c[a[i]]++;
   }
   for(int i=n;i>=1;i--)
   {
       if(p[a[i]]==0) h[i]=n+1; else   h[i]=p[a[i]];
      p[a[i]]=i;
      pos[a[i]].insert(i); pos[a[i]].insert(0); pos[a[i]].insert(n+1);
   }
   for(int i=1;i<=n;i++)
   {
       if(pre[i]==0&&c[a[i]]>1)
       {
           s.insert(mkp(a[i],i));
       }
   }
   while(s.size())
   {
       set<pa> :: iterator it=s.begin();  pa t=*it;    s.erase(t);
       //for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl;
       c[a[t.se]]-=2;
       int pt=h[t.se]; a[pt]*=2; vis[t.se]=1; // cout<<pt<<" "<<a[pt]<<" 55555555\n";

       c[a[pt]]++;
       if(c[a[pt]]==1) pos[a[pt]].insert(0),pos[a[pt]].insert(n+1),pre[pt]=0,h[pt]=n+1;
       if(pos[a[t.se]].find(t.se)!=pos[a[t.se]].end())
       pos[a[t.se]].erase(t.se);
       if(pos[a[t.se]].find(pt)!=pos[a[t.se]].end())
       pos[a[t.se]].erase(pt);
       int p1=*pos[a[t.se]].lower_bound(pt);
       pre[p1]=0;
       if(c[a[t.se]]>=2)
       {
           s.insert(mkp(a[t.se],p1));
       }
       u=pos[a[pt]].lower_bound(pt);
       p1=*u; u--;
       int p2=*u;
        h[pt]=p1; pre[p1]=pt;
        h[p2]=pt; pre[pt]=p2;
       int pp=*pos[a[pt]].upper_bound(0);
       if(c[a[pt]]>=3)
       {
           if(s.find(mkp(a[pt],pp))!=s.end())
           s.erase(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(pt);
       if(c[a[pt]]>=2)
       {
           pp=min(pt,pp);
          //cout<<pp<<" "<<a[pt]<<"  32333"<<endl;
           s.insert(mkp(a[pt],pp));
       }
       pos[a[pt]].insert(0),pos[a[pt]].insert(n+1);
       pos[a[t.se]].insert(0),pos[a[t.se]].insert(n+1);
   }
   int cc=0;
   for(int i=1;i<=n;i++)  if(vis[i]==0) cc++;
   cout<<cc<<endl;
   for(int i=1;i<=n;i++) if(vis[i]==0) cout<<a[i]<<" ";
return 0;
}
/*

*/


#include <bits/stdc++.h>

using namespace std;

int n, a[200005], ans[200005];
map < int, bool > used;
map < int, set < int > > g;
int main(){
  scanf ("%d", &n);
  set < int > st;
  for (int i = 1; i <= n; ++i)
  {
    scanf ("%d", &a[i]);
    g[a[i]].insert(i);
    if (int(g[a[i]].size() >= 2)) st.insert(a[i]);
  }
  while (!st.empty())
  {
    int x = *st.begin();
    st.erase(st.begin());
    int flag = 0;
    if (int(g[x].size()) & 1) flag = 1;
    while (int(g[x].size()) != flag)
    {
      g[x].erase(g[x].begin());
      g[x * 2].insert(*g[x].begin());
      g[x].erase(g[x].begin());
    }
    if (int(g[x].size()) == 1) ans[*g[x].begin()] = x, used[x] = 1;
    if (int(g[x * 2].size()) >= 2) st.insert(x * 2);
    else ans[*g[x * 2].begin()] = x * 2, used[x * 2] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (g[a[i]].size() == 1 && !used[a[i]]) ans[i] = a[i];
    if (ans[i] > 0) ++cnt;
  }
  printf ("%d\n", cnt);
  for (int i = 1; i <= n; ++i)
  {
    if (ans[i] > 0) printf ("%d ", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
long long a[200005], ans[200005];
map < long long, int > used;
map < long long, set < long long > > g;
int main(){
  scanf ("%d", &n);
  set < long long > st;
  for (int i = 1; i <= n; ++i)
  {
    scanf ("%lld", &a[i]);
    used[a[i]] = 0;
    g[a[i]].insert(i);
    if (int(g[a[i]].size() >= 2)) st.insert(a[i]);
  }
  while (!st.empty())
  {
    long long x = *st.begin();
    st.erase(st.begin());
    int flag = 0;
    if (int(g[x].size()) & 1) flag = 1;
    while (int(g[x].size()) != flag)
    {
      g[x].erase(g[x].begin());
      g[x * 2].insert(*g[x].begin());
      g[x].erase(g[x].begin());
    }
    if (int(g[x].size()) == 1) ans[*g[x].begin()] = x, used[x] = 1;
    if (int(g[x * 2].size()) >= 2) st.insert(x * 2);
    else ans[*g[x * 2].begin()] = x * 2, used[x * 2] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (g[a[i]].size() == 1 && used[a[i]] == 0) ans[i] = a[i];
    if (ans[i] > 0) ++cnt;
  }
  printf ("%d\n", cnt);
  for (int i = 1; i <= n; ++i)
  {
    if (ans[i] > 0) printf ("%lld ", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
long long a[200005], ans[200005];
map < int, bool > used;
map < long long, set < long long > > g;
int main(){
  scanf ("%d", &n);
  set < long long > st;
  for (int i = 1; i <= n; ++i)
  {
    scanf ("%lld", &a[i]);
    g[a[i]].insert(i);
    if (int(g[a[i]].size() >= 2)) st.insert(a[i]);
  }
  while (!st.empty())
  {
    int x = *st.begin();
    st.erase(st.begin());
    int flag = 0;
    if (int(g[x].size()) & 1) flag = 1;
    while (int(g[x].size()) != flag)
    {
      g[x].erase(g[x].begin());
      g[x * 2].insert(*g[x].begin());
      g[x].erase(g[x].begin());
    }
    if (int(g[x].size()) == 1) ans[*g[x].begin()] = x, used[x] = 1;
    if (int(g[x * 2].size()) >= 2) st.insert(x * 2);
    else ans[*g[x * 2].begin()] = x * 2, used[x * 2] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (g[a[i]].size() == 1 && !used[a[i]]) ans[i] = a[i];
    if (ans[i] > 0) ++cnt;
  }
  printf ("%d\n", cnt);
  for (int i = 1; i <= n; ++i)
  {
    if (ans[i] > 0) printf ("%lld ", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, a[200005];
map < int, int > cnt, used;
int main(){
  scanf ("%d", &n);
  for (int i = 1; i <= n; ++i) scanf ("%d", a + i), cnt[a[i]]++;
  set < int > st;
  for (int i = 1; i <= n; ++i) if (cnt[a[i]] > 1) st.insert(a[i]);
  vector < int > ans;
  while (!st.empty())
  {
    int x = *st.begin();
    st.erase(st.begin());
    if (cnt[x] & 1)
    {
      cnt[x]--;
      ans.push_back(x);
      used[x] = 1;
    }
    cnt[x * 2] += (cnt[x] / 2);
    if (cnt[x * 2] == 1) ans.push_back(x * 2), used[x * 2] = 1;
    else  st.insert(x * 2);
  }
  for (int i = 1; i <= n; ++i) if (cnt[a[i]] == 1 && !used[a[i]]) ans.push_back(a[i]);
  printf ("%d\n", int(ans.size()));
  for (int to : ans) printf ("%d ", to);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
long long a[200005], ans[200005];
map < int, bool > used;
map < long long, set < int > > g;
int main(){
  scanf ("%d", &n);
  set < long long > st;
  for (int i = 1; i <= n; ++i)
  {
    scanf ("%lld", &a[i]);
    g[a[i]].insert(i);
    if (int(g[a[i]].size() >= 2)) st.insert(a[i]);
  }
  while (!st.empty())
  {
    int x = *st.begin();
    st.erase(st.begin());
    int flag = 0;
    if (int(g[x].size()) & 1) flag = 1;
    while (int(g[x].size()) != flag)
    {
      g[x].erase(g[x].begin());
      g[x * 2].insert(*g[x].begin());
      g[x].erase(g[x].begin());
    }
    if (int(g[x].size()) == 1) ans[*g[x].begin()] = x, used[x] = 1;
    if (int(g[x * 2].size()) >= 2) st.insert(x * 2);
    else ans[*g[x * 2].begin()] = x * 2, used[x * 2] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (g[a[i]].size() == 1 && !used[a[i]]) ans[i] = a[i];
    if (ans[i] > 0) ++cnt;
  }
  printf ("%d\n", cnt);
  for (int i = 1; i <= n; ++i)
  {
    if (ans[i] > 0) printf ("%lld ", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
long long a[200005], ans[200005];
map < int, bool > used;
map < long long, set < long long > > g;
int main(){
  scanf ("%d", &n);
  set < long long > st;
  for (int i = 1; i <= n; ++i)
  {
    scanf ("%lld", &a[i]);
    g[a[i]].insert(i);
    if (int(g[a[i]].size() >= 2)) st.insert(a[i]);
  }
  while (!st.empty())
  {
    long long x = *st.begin();
    st.erase(st.begin());
    int flag = 0;
    if (int(g[x].size()) & 1) flag = 1;
    while (int(g[x].size()) != flag)
    {
      g[x].erase(g[x].begin());
      g[x * 2].insert(*g[x].begin());
      g[x].erase(g[x].begin());
    }
    if (int(g[x].size()) == 1) ans[*g[x].begin()] = x, used[x] = 1;
    if (int(g[x * 2].size()) >= 2) st.insert(x * 2);
    else ans[*g[x * 2].begin()] = x * 2, used[x * 2] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (g[a[i]].size() == 1 && !used[a[i]]) ans[i] = a[i];
    if (ans[i] > 0) ++cnt;
  }
  printf ("%d\n", cnt);
  for (int i = 1; i <= n; ++i)
  {
    if (ans[i] > 0) printf ("%lld ", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%i",&n);
    set<pair<long long,int> > s;
    set<pair<long long,int> >::iterator it;
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%i",&a);
        s.insert(make_pair((long long)a,i));
    }
    pair<long long,int> t1,t2,t;
    long long niz[2*n+2];
    for(int i=0;i<2*n+2;i++)
    {
        niz[i]=-1;
    }
    while(s.size()>1)
    {
        it=s.begin();
        t1=*it;
        s.erase(it);
        it=s.begin();
        t2=*it;
        if(t1.first==t2.first)
        {
            s.erase(it);
            t=make_pair(t1.first*2,t2.second);
            s.insert(t);
        }
        else
        {
            niz[t1.second]=t1.first;
        }
    }
    if(s.size()==1)
    {
        it=s.begin();
        t1=*it;
        niz[t1.second]=t1.first;
    }
    int co=0;
    for(int i=0;i<2*n+2;i++)
    {
        if(niz[i]>-1)
        {
            co++;
        }
    }
    printf("%i\n",co);
    for(int i=0;i<2*n+2;i++)
    {
        if(niz[i]>-1)
        {
            printf("%lld ",niz[i]);
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%i",&n);
    int niz[n],niz1[n];
    for(int i=0;i<n;i++)
    {
        scanf("%i",&niz[i]);
        niz1[i]=niz[i];
    }
    sort(niz1,niz1+n);
    map<long long,int> mapa;
    int broj=1;
    for(int i=0;i<n;i++)
    {
        mapa[(long long)niz1[i]]=broj;
        while(niz1[i+1]==niz1[i])
        {
            i++;
        }
        broj++;
    }
    set<pair<int,long long> > data[2*n+2];
    for(int i=0;i<n;i++)
    {
        data[mapa[(long long)niz[i]]].insert(make_pair(i,(long long)niz[i]));
    }
    for(int i=1;i<broj;i++)
    {
        while(data[i].size()>1)
        {
            data[i].erase(data[i].begin());
            pair<int,long long> p=*data[i].begin();
            data[i].erase(data[i].begin());
            p.second*=(long long)2;
            if(mapa[p.second]>0)
            {
                data[mapa[p.second]].insert(p);
            }
            else
            {
                mapa[p.second]=broj;
                data[broj].insert(p);
                broj++;
            }
        }
    }
    long long resenje[2*n+2];
    for(int i=0;i<2*n+2;i++)
    {
        resenje[i]=-1;
    }
    for(int i=1;i<broj;i++)
    {
        set<pair<int,long long> >::iterator it=data[i].begin();
        for(unsigned int j=0;j<data[i].size();j++)
        {
            pair<int,long long> p=*it;
            resenje[p.first]=(long long)p.second;
            it++;
        }
    }
    int broj2=0;
    for(int i=0;i<2*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            broj2++;
        }
    }
    printf("%i\n",broj2);
    for(int i=0;i<2*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            printf("%lld ",resenje[i]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%i",&n);
    int niz[n],niz1[n];
    for(int i=0;i<n;i++)
    {
        scanf("%i",&niz[i]);
        niz1[i]=niz[i];
    }
    sort(niz1,niz1+n);
    map<int,int> mapa;
    int broj=1;
    for(int i=0;i<n;i++)
    {
        mapa[niz1[i]]=broj;
        while(niz1[i+1]==niz1[i])
        {
            i++;
        }
        broj++;
    }
    set<pair<int,int> > data[2*n+2];
    for(int i=0;i<n;i++)
    {
        data[mapa[niz[i]]].insert(make_pair(i,niz[i]));
    }
    for(int i=1;i<broj;i++)
    {
        while(data[i].size()>1)
        {
            data[i].erase(data[i].begin());
            pair<int,int> p=*data[i].begin();
            data[i].erase(data[i].begin());
            p.second*=2;
            if(mapa[p.second]>0)
            {
                data[mapa[p.second]].insert(p);
            }
            else
            {
                mapa[p.second]=broj;
                data[broj].insert(p);
                broj++;
            }
        }
    }
    int resenje[2*n+2];
    for(int i=0;i<2*n+2;i++)
    {
        resenje[i]=-1;
    }
    for(int i=1;i<broj;i++)
    {
        set<pair<int,int> >::iterator it=data[i].begin();
        for(unsigned int j=0;j<data[i].size();j++)
        {
            pair<int,int> p=*it;
            resenje[p.first]=p.second;
            it++;
        }
    }
    for(int i=0;i<2*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            printf("%i ",resenje[i]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%i",&n);
    int niz[n],niz1[n];
    for(int i=0;i<n;i++)
    {
        scanf("%i",&niz[i]);
        niz1[i]=niz[i];
    }
    sort(niz1,niz1+n);
    map<int,int> mapa;
    int broj=1;
    for(int i=0;i<n;i++)
    {
        mapa[niz1[i]]=broj;
        while(niz1[i+1]==niz1[i])
        {
            i++;
        }
        broj++;
    }
    set<pair<int,int> > data[2*n+2];
    for(int i=0;i<n;i++)
    {
        data[mapa[niz[i]]].insert(make_pair(i,niz[i]));
    }
    for(int i=1;i<broj;i++)
    {
        while(data[i].size()>1)
        {
            data[i].erase(data[i].begin());
            pair<int,int> p=*data[i].begin();
            data[i].erase(data[i].begin());
            p.second*=2;
            if(mapa[p.second]>0)
            {
                data[mapa[p.second]].insert(p);
            }
            else
            {
                mapa[p.second]=broj;
                data[broj].insert(p);
                broj++;
            }
        }
    }
    int resenje[2*n+2];
    for(int i=0;i<2*n+2;i++)
    {
        resenje[i]=-1;
    }
    for(int i=1;i<broj;i++)
    {
        set<pair<int,int> >::iterator it=data[i].begin();
        for(unsigned int j=0;j<data[i].size();j++)
        {
            pair<int,int> p=*it;
            resenje[p.first]=p.second;
            it++;
        }
    }
    int broj2=0;
    for(int i=0;i<2*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            broj2++;
        }
    }
    printf("%i\n",broj2);
    for(int i=0;i<2*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            printf("%i ",resenje[i]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%i",&n);
    int niz[n],niz1[n];
    for(int i=0;i<n;i++)
    {
        scanf("%i",&niz[i]);
        niz1[i]=niz[i];
    }
    sort(niz1,niz1+n);
    map<long long,int> mapa;
    int broj=1;
    for(int i=0;i<n;i++)
    {
        mapa[(long long)niz1[i]]=broj;
        while(niz1[i+1]==niz1[i])
        {
            i++;
        }
        broj++;
    }
    set<pair<int,long long> > data[2*n+2];
    for(int i=0;i<n;i++)
    {
        data[mapa[(long long)niz[i]]].insert(make_pair(i,(long long)niz[i]));
    }
    for(int i=1;i<broj;i++)
    {
        while(data[i].size()>1)
        {
            data[i].erase(data[i].begin());
            pair<int,long long> p=*data[i].begin();
            data[i].erase(data[i].begin());
            p.second*=(long long)2;
            if(mapa[p.second]>0)
            {
                data[mapa[p.second]].insert(p);
            }
            else
            {
                mapa[p.second]=broj;
                data[broj].insert(p);
                broj++;
            }
        }
    }
    long long resenje[3*n+2];
    for(int i=0;i<3*n+2;i++)
    {
        resenje[i]=-1;
    }
    for(int i=1;i<broj;i++)
    {
        set<pair<int,long long> >::iterator it=data[i].begin();
        for(unsigned int j=0;j<data[i].size();j++)
        {
            pair<int,long long> p=*it;
            resenje[p.first]=(long long)p.second;
            it++;
        }
    }
    int broj2=0;
    for(int i=0;i<3*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            broj2++;
        }
    }
    printf("%i\n",broj2);
    for(int i=0;i<3*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            printf("%lld ",resenje[i]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%i",&n);
    int niz[n],niz1[n];
    for(int i=0;i<n;i++)
    {
        scanf("%i",&niz[i]);
        niz1[i]=niz[i];
    }
    sort(niz1,niz1+n);
    map<long long,int> mapa;
    int broj=1;
    for(int i=0;i<n;i++)
    {
        mapa[niz1[i]]=broj;
        while(niz1[i+1]==niz1[i])
        {
            i++;
        }
        broj++;
    }
    set<pair<int,long long> > data[2*n+2];
    for(int i=0;i<n;i++)
    {
        data[mapa[niz[i]]].insert(make_pair(i,niz[i]));
    }
    for(int i=1;i<broj;i++)
    {
        while(data[i].size()>1)
        {
            data[i].erase(data[i].begin());
            pair<int,long long> p=*data[i].begin();
            data[i].erase(data[i].begin());
            p.second*=(long long)2;
            if(mapa[p.second]>0)
            {
                data[mapa[p.second]].insert(p);
            }
            else
            {
                mapa[p.second]=broj;
                data[broj].insert(p);
                broj++;
            }
        }
    }
    long long resenje[2*n+2];
    for(int i=0;i<2*n+2;i++)
    {
        resenje[i]=-1;
    }
    for(int i=1;i<broj;i++)
    {
        set<pair<int,long long> >::iterator it=data[i].begin();
        for(unsigned int j=0;j<data[i].size();j++)
        {
            pair<int,long long> p=*it;
            resenje[p.first]=p.second;
            it++;
        }
    }
    int broj2=0;
    for(int i=0;i<2*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            broj2++;
        }
    }
    printf("%i\n",broj2);
    for(int i=0;i<2*n+2;i++)
    {
        if(resenje[i]>-1)
        {
            printf("%lld ",resenje[i]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%i",&n);
    set<pair<long long,int> > s;
    set<pair<long long,int> >::iterator it;
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%i",&a);
        s.insert(make_pair((long long)a,i));
    }
    pair<long long,int> t1,t2,t;
    int niz[2*n+2];
    for(int i=0;i<2*n+2;i++)
    {
        niz[i]=-1;
    }
    while(s.size()>1)
    {
        it=s.begin();
        t1=*it;
        s.erase(it);
        it=s.begin();
        t2=*it;
        if(t1.first==t2.first)
        {
            s.erase(it);
            t=make_pair(t1.first*2,t2.second);
            s.insert(t);
        }
        else
        {
            niz[t1.second]=t1.first;
        }
    }
    if(s.size()==1)
    {
        it=s.begin();
        t1=*it;
        niz[t1.second]=t1.first;
    }
    int co=0;
    for(int i=0;i<2*n+2;i++)
    {
        if(niz[i]>-1)
        {
            co++;
        }
    }
    printf("%i\n",co);
    for(int i=0;i<2*n+2;i++)
    {
        if(niz[i]>-1)
        {
            printf("%i ",niz[i]);
        }
    }

    return 0;
}


// 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();
}


// 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();
}


// 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();
}


// 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());
        m=i.ss.size();
        if(m%2==0){

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

        else {
            fr(j,0,m-2){
            if(j%2==1)pos[2*i.ff].pb(i.ss[j]);
            }
            i.ss={i.ss[m-1]};
            hope[i.ff]=i.ss[m-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();
}


// 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();
}