#include<iostream>
using namespace std;
class node{
public:
int data;
node*right;
node*left;
node(int d){
data=d;
left=NULL;
right=NULL;
}
};
node* buildTree(int*arr,int s,int e){
if(s>e)
return NULL;
int mid=(s+e)/2;
node*root=new node(arr[mid]);
root->left=buildTree(arr,s,mid-1);
root->right=buildTree(arr,mid+1,e);
return root;
}
void printt(node* root){
if(root==NULL)
return;
cout<< root->data <<" ";
printt(root->left);
printt(root->right);
return;
}
int main() {
int n,sum=0;
cin>>n;
int arr[n],ar2[n];
for(int i=0;i<n;i++){
cin>>arr[i];
sum=sum+arr[i];
// ar2[i]=sum;
// cout<<ar2[i]<<" ";
}
int next_sum=0;
for(int i=0;i<n;i++){
if(i!=0)
next_sum=next_sum+arr[i-1];
ar2[i]= sum-next_sum;
if(i==0)
ar2[i]=350;
// cout<<ar2[i]<<" ";
}
cout<<endl;
node*f=buildTree(ar2,0,n-1);
printt(f);
return 0;
}
/* approach = taking input array ie = 20 30 40 50 60 70 80 then finding its ttl sum ie 350
loop 2 --> then making an array of the actual data of the respective nodes which should be in the outputt
instead of the given integers
eg = if a binary tree is formed then the node 20 should be replaced by the sum of greater num than
and equal to 20 ie --> 350 then for 30 it will be ; 350 -(the sum previous terms int the array )
ie 30 -->350-20 = 330 ; then for 40 --> 350 - (20+30)=300 and so on
then stored it in an array -->[350 , 330 , 300 , 260 ,210 , 150 ,80 ]
then finally made the bst of the array above , THEN Y DOES IT GIVE ALL THE TEST CASES WRONG ??? HELP */