# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def __init__(self):
self.total=0
def convertBST(self, root):
if root is not None:
self.convertBST(root.right)
self.total+=root.val
root.val=self.total
self.convertBST(root.left)
return root