<commit_before># 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 helper(self,root,stolen):
        if not root:
            return 0
        if stolen:
            return self.helper(root.left,False)+self.helper(root.right,False)
        else:
           return max(root.val+self.helper(root.left,True)+self.helper(root.right,True),self.helper(root.left,False)+self.helper(root.right,False))
            
    def rob(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        """
        1. root stolen
        2. root not stolen
        """
        return max(self.helper(root,False),self.helper(root,True))
        
        <commit_msg>[337. House Robber III][Accepted]committed by Victor<commit_after># 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 helper(self,root,mapping):
        if not root:
            return 0
        if root in mapping:
            return mapping[root]
        
        max_sum=0
        if root.left:
            max_sum+=self.helper(root.left.left,mapping)+self.helper(root.left.right,mapping)
        if root.right:
            max_sum+=self.helper(root.right.left,mapping)+self.helper(root.right.right,mapping)
        
        # two situation get the max
        max_sum=max(max_sum+root.val,self.helper(root.left,mapping)+self.helper(root.right,mapping))
        mapping[root]=max_sum
        return max_sum
        
    def rob(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        """
        1. root stolen
        2. root not stolen
        """
        mapping={}
        return self.helper(root,mapping)
        
{'fraction_non_alphanumeric': 0.11886304909560723, 'fraction_numerical': 0.00516795865633075, 'mean_word_length': 1.9025487256371814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5193906', 'n_tokens_mistral': 578, 'n_tokens_neox': 572, 'n_words': 123}