#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#define _FORTIFY_SOURCE 2
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define loop(i,a,b) for(lli i=0;i<n;i++)
int main()
{lli n,index1,index2,num,f,el,c;
cin>>n;
vector<lli>v;
map<lli,set<lli>>mp;
loop(i,0,n)
{cin>>num;
v.pb(num);
mp[num].insert(i);
}
set<lli>s;
loop(i,0,n)
{s.insert(v[i]);
}
f=0;
while(f==0)
{f=1;
for(auto itr=s.begin();itr!=s.end();++itr)
{if(mp[*itr].size()>=2)
{f=0;
el=*itr;
break;
}
}
if(f==1)
{break;
}
auto it1=mp[el].begin();
mp[el].erase(it1);
index1=*it1;
auto it2=++it1;
mp[el].erase(it2);
index2=*it2;
v[index1]=-1;
v[index2]=2*el;
s.insert(2*el);
mp[2*el].insert(index2);
}
c=0;
for(auto itr=v.begin();itr!=v.end();++itr)
{if(*itr!=-1)
{c++;
}
}
cout<<c<<"\n";
for(auto itr=v.begin();itr!=v.end();++itr)
{if(*itr!=-1)
{cout<<*itr<<" ";
}
}
return 0;
}
I2RlZmluZSBfR0xJQkNYWF9ERUJVRyAxCiNkZWZpbmUgX0dMSUJDWFhfREVCVUdfUEVEQU5USUMgMQojZGVmaW5lIF9GT1JUSUZZX1NPVVJDRSAyCgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4gCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGxpIGxvbmcgbG9uZyBpbnQgCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbG9vcChpLGEsYikgZm9yKGxsaSBpPTA7aTxuO2krKykKaW50IG1haW4oKQp7bGxpIG4saW5kZXgxLGluZGV4MixudW0sZixlbCxjOwpjaW4+Pm47CnZlY3RvcjxsbGk+djsKbWFwPGxsaSxzZXQ8bGxpPj5tcDsKbG9vcChpLDAsbikKe2Npbj4+bnVtOwp2LnBiKG51bSk7Cm1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