#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int& a : v) cin >> a;
int at = 0;
vector<int> was(n, true);
while (at < n) {
int nxt = at + 1;
while (nxt < n && v[at] + v[nxt] <= v[at]) {
v[at] += v[nxt];
was[nxt] = false;
++nxt;
}
at = nxt;
}
for (int i = 0; i < n; i++) {
if (was[i]) {
cout << v[i] << ' ';
}
}
cout << endl;
}