Binary Search Tree

https://hack.codingblocks.com/practice/p/355/143
For this question how I can manuplate this Sum replacement code.
to get the answer,I tried in many ways but I failed to do so

int replaceSum(node*root){
if(root==NULL){
return 0;
}
if(root->left==NULL && root->right==NULL){
return root->data;
}
//Recursive Part
int leftSum = replaceSum(root->left);
int rightSum = replaceSum(root->right);

int temp = root->data;
root->data = leftSum + rightSum;
return temp + root->data;

}

In this question u don’t have to replace each node by the sum of its child nodes instead u have to replace each node by sum of all nodes which are greater than it.