#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define endl '\n'
#define ll long long
#define set(a) fixed << setprecision(a)
int arr[300005],ar[30000005];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
/*int t, x, y, c, b, mx, mn;
cin >> t >> x >> y;
mn = min(x, y);
mx = t * mn;
for(int i = 1; i <= t; i++)
{
c = x*i;
b = y*(t-i);
if(mx < abs(c - b))
{
if(max((x*(i-1)), (y*(t-i+1))) < t * x)
cout << max((x*(i-1)), (y*(t-i+1)));
else cout << t * x;
break;
}
else mx = abs(c-b);
}*/
/*ll l,r,x,y,k,c=0,i,j,n=1000000007;
cin>>l>>r>>x>>y>>k;
i=((r*(r+1)/2)-(l*(l-1)/2));
j=(((r/k-1)*(r/k))/2)-((((l/k)+1)*(l/k))/2);
j*=k;
cout<<j<<endl;
j+=(k-(l%k-1)*(l/k))+((r%k)*(r/k));
j=abs(j);
i=i*x%n;
j=(j%n)*(y%n);
cout<<(i+j)%n;*/
ll i,x,y,j=0;
cin>>x;
y=x;
for(i=0;i<x;i++)
cin>>arr[i];
for( i = 0; i < x;i++)
{
if(arr[i]>arr[i+1]&&i!=x-1)
{
for(j=i+1;j<x;j++)
{
if(arr[i]>arr[j])
{
arr[i]+=arr[j];
ar[i]=arr[i];
y-=1;
}
else
break;
}
i=j-1;
}
else
{
ar[j++]=arr[i];
}
}
for( i = 0; i <= y; i++)
{
if(ar[i]!=0 )
cout<<ar[i]<<' ';
}
}
Copy