#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define all(v) v.begin(), v.end()
#define pb push_back
#define sz(x) (int)(x).size()
const int N = 3e5 + 5;
void solve() {
int n;
scanf("%d", &n);
vl a(n + 1), del(n + 1);
for(ll &x : a)
scanf("%lld", &x);
for(int i = 0; i < n - 1; ++i) {
if(del[i])
continue;
int r = i + 1;
ll sum = a[r];
while(r < n && a[i] + sum <= a[i]) {
del[r] = 1;
++r;
a[i] += sum;
sum = a[r];
}
}
for(int i = 0; i < n; ++i){
if(!del[i])
printf("%lld ", a[i]);
}
}
int main() {
int t = 1;
// scanf("%d",&t);
while(t--)
solve();
}
Copy