#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sz(s) (int)(s.size())
#define endl "\n"
#define PI acos(-1)
#define all(a) a.begin(), a.end()
void Open() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif !ONLINEJUDGE
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int dx[]{ 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[]{ 0, 0, 1, -1, 1, -1, 1, -1 };
const int OO = 0x3f3f3f3f;
int main()
{
// Open();
int n;
cin >> n;
vector < int > v(n);
for (auto& e : v)cin >> e;
vector < ll > ans;
ans.push_back(v[0]);
for (int i = 1; i < n; i++) {
ans.push_back(v[i]);
while (sz(ans) > 1 && ans[sz(ans)-1] + ans[sz(ans)-2] < ans[sz(ans) - 2]) {
ans[sz(ans) - 2] += ans[sz(ans) - 1];
ans.pop_back();
}
}
while (sz(ans) && ans.back() == 0)ans.pop_back();
for (auto e : ans)cout << e << " ";
}
Copy