#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
int main()
{
int n;cin>>n;
int arr[n];
vector <int> v;
for(int i=0;i<n;i++)cin>>arr[i];
for(int i=0;i<n;i++)
{
int temp=arr[i];
if(temp>=0)v.push_back(temp);
else
{
while(!v.empty()&&temp<0)
{
temp+=v.back();
v.pop_back();
}
v.push_back(temp);
}
}
while(v.back()==0&&v.size()>1)v.pop_back();
for(auto item:v)cout<<item<<" ";
cout<<endl;
}