Python3 Solution
\n\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.l
\n```\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n    def averageOfSubtree(self, root: Optional[TreeNode]) -> int:\n        ans=0\n        def traverse(node):\n            if node is None:\n                return (0,0)\n            left=traverse(node.left)\n            right=traverse(node.right)\n            total=left[0]+right[0]+node.val\n            count=left[1]+right[1]+1\n            if total//count==node.val:\n                nonlocal ans\n                ans+=1\n            return (total,count)\n        traverse(root)\n        return ans           \n```
['Python', 'Python3']