#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e2 + 5;
int main()
{
int n;
cin >> n;
vector<long long> v(n);
for(int i = 0 ; i < n ; i++)
{
cin >> v[i];
}
if(n == 1)
{
cout << v[0] ;
return 0;
}
long long last = v.back();
vector<long long> ans;
bool flag = 1;
for(int i = n - 2 ; i >= 1 ; i--)
{
if(v[i] + last < v[i])
{
last+=v[i];
}
else
{
ans.push_back(last);
last = v[i];
}
}
if(v[0] + last < v[0])
ans.push_back(v[0] + last);
else
{
ans.push_back(last);
ans.push_back(v[0]);
}
reverse(ans.begin(),ans.end());
while(ans.size() > 1 and ans.back() == 0)
{
ans.pop_back();
}
for(auto &k : ans)
cout << k << ' ';
}
Copy