Explain how you would find the maximum sum of a subtree that is a BST in a binary tree.
Write a function that takes the root of a binary tree and returns the maximum sum of any subtree that forms a valid BST. If no valid BST subtree exists, return 0.
def max_sum_bst(root):