#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define vll vector<vector<ll> >
#define vi vector<int>(n)
#define vl vector<ll>
#define deb(x) cout<<x<<"\n";
#define disp(x) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int M=100005;
const int INF=2;
const double EPS=1e-9;
const long double PI=acos(-1);
#define endl '/n'
struct stableSum {
int cnt=0;
vector<double>v,pref{0};
void operator+=(double a){
assert(a>=0);
int s=++cnt;
while(s%2==0){
a+=v.back();
v.pop_back(),pref.pop_back();
s/=2;
}
v.push_back(a);
pref.push_back(pref.back() + a);
}
double val() {return pref.back();}
};
int cmp(int a,int b){
return a>b;
}
ll po(ll x,ll y){
x%=MOD;
ll ret=1;
while(y>0){
if(y&1){
ret=(ret*x)%MOD;
}
y=y>>1ll;
x=(x*x)%MOD;
}
return ret%MOD;
}
string tostring(ll x){
string ret="";
while(x){
ret+=char(x%10+'0');
x/=10;
}
reverse(ret.begin(),ret.end());
return ret;
}
void solve(int T){
int n;
cin>>n;
vector<ll>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
vector<int>ans;
int cur=0;
for(int i=0;i<n;i++){
if(a[i]>0){
if(cur>0){
ans.pb(cur);
}
cur=a[i];
}
else if(a[i]<0){
if(cur!=0){
cur+=a[i];
}
else {
ans.pb(a[i]);
cur=0;
}
}
}
if(cur!=0)ans.pb(cur);
int i=ans.size()-1;
while(ans[i]==0){
i--;
}
for(int j=0;j<=i;j++){
cout<<ans[j]<<" ";
}
}
int main(){
//freopen("test_input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fastio
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
solve(i);
//if(i<T)cout<<"\n";
}
return 0;
}
/*
*/
Copy