#include
using namespace std;
struct node{
int data;
node* left;
node* right;
};
int sum=0;
node* buildbst(node *root,int data){
if(root==NULL){
root =new node;
root->data=data;
root->left=NULL;
root->right=NULL;
return root;
}
if(data<=root->data){
root->left=buildbst(root->left,data);
}
if(data>root->data){
root->right=buildbst(root->right,data);
}
return root;
}
void modify(node *&root,int &sum){
if(root==NULL){
return;
}
modify(root->right,sum);
sum=root->data+sum;
root->data=sum;
modify(root->left,sum);
}
void PrintPreorder(node* node)
{
if (node == NULL)
return;
cout << node->data << " ";
PrintPreorder(node->left);
PrintPreorder(node->right);
}
int main() {
node *root=NULL;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
root=buildbst(root,a[i]);}
int sum=0;
modify(root,sum);
PrintPreorder(root);
return 0;
}