// {In the Name of Allah, the Most Beneficent, the Most Merciful }
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define mp make_pair
#define pb push_back
#define pf push_front
#define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);
#define no cout<<"NO\n"
#define yes cout<<"YES\n"
#define el "\n"
int freq[27];
int main()
{
/**/IOS/**/
int n;
cin>>n;
vector<ll>x;
ll o;
ll c=0;
for(int i=0;i<n;i++)
{
cin>>o;
x.push_back(o);
}
bool tr=0;
for(int i=0;i<n;i++)
{
//cout<<i<<endl;
//cout<<x[i]<<endl;
if(i>0&&tr==0)
{
c=x[i-1];
}
// cout<<c<<endl;
if(c>x[i]&&i>0){
x[i-1]=c+x[i];
c=x[i-1];
tr=1;
x.erase(x.begin()+i,x.begin()+i+1);
n--;
i--;
}
else
tr=0;
}
for(int i=0;i<x.size();i++)
cout<<x[i]<<" ";
cout<<endl;
}
Copy