#include<bits/stdc++.h>
using namespace std;
long long a[10100000],b[1010000],k;
unordered_map<long long,long long> li;
int main()
{
int n;
cin>>n;
k=0;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
{
if(li[a[i]]!=0)
{
a[li[a[i]]]=-1;
li[a[i]]=0;
a[i]=2*a[i];
while(li[a[i]]!=0)
{
a[li[a[i]]]=-1;
li[a[i]]=0;
a[i]=2*a[i];
}
li[a[i]]=i;
}
else
li[a[i]]=i;
}
for(int i=1;i<=n;i++)
if(a[i]!=-1)
k++;
cout<<k<<endl;
for(int i=1;i<=n;i++)
if(a[i]!=-1)
cout<<a[i]<<" ";
cout<<endl;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbG9uZyBsb25nIGFbMTAxMDAwMDBdLGJbMTAxMDAwMF0sazsKdW5vcmRlcmVkX21hcDxsb25nIGxvbmcsbG9uZyBsb25nPiBsaTsKaW50IG1haW4oKQp7CiAgICBpbnQgbjsKICAgIGNpbj4+bjsKICAgIGs9MDsKICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKQogICAgICAgICAgICBjaW4+PmFbaV07CgogICAgZm9yKGludCBpPTE7aTw9bjtpKyspCiAgICB7CiAgICAgICAgIGlmKGxpW2FbaV1dIT0wKQogICAgICAgICB7CiAgICAgICAgICAgICAgIGFbbGlbYVtpXV1dPS0xOwogICAgICAgICAgICAgICBsaVthW2ldXT0wOwogICAgICAgICAgICAgICBhW2ldPTIqYVtpXTsKICAgICAgICAgICAgICAgd2hpbGUobGlbYVtpXV0hPTApCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBhW2xpW2FbaV1dXT0tMTsKICAgICAgICAgICAgICAgICAgICBsaVthW2ldXT0wOwogICAgICAgICAgICAgICAgICAgIGFbaV09MiphW2ldOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgIGxpW2FbaV1dPWk7CiAgICAgICAgIH0KICAgICAgICAgZWxzZQogICAgICAgIGxpW2FbaV1dPWk7CiAgICB9CiAgICBmb3IoaW50IGk9MTtpPD1uO2krKykKICAgICAgICBpZihhW2ldIT0tMSkKICAgICAgICBrKys7CiAgICBjb3V0PDxrPDxlbmRsOwogICAgICAgZm9yKGludCBpPTE7aTw9bjtpKyspCiAgICAgICAgICBpZihhW2ldIT0tMSkKICAgICAgICAgICBjb3V0PDxhW2ldPDwiICI7CiAgICAgICAgICAgY291dDw8ZW5kbDsKfQo=