#include <bits/stdc++.h>
using namespace std;
int sum,x;
typedef struct node{
int w;
struct node *left,*right;
}node;
node *Build()
{
cin >> x;
if(x == -1) return NULL;
node *root = (node *)malloc(sizeof (node));
root -> w = x;
root -> left = Build();
root -> right = Build();
return root;
}
void dfs(node *root)
{
if(root == NULL) return ;
dfs(root -> right);
sum += root -> w;
root -> w = sum;
dfs(root -> left);
}
void print(node *root)
{
if(root == NULL) {
cout << -1 << " ";
return ;
}
cout << root -> w << " ";
print(root -> left);
print(root -> right);
}
int main()
{
node *root = Build();
dfs(root);
print(root);
}