c++ solution using pair O(N) time
\nclass Solution {\npublic:\n    pair<int,int>find(TreeNode*root,int&sum)\n    {\n        if(root==NULL)\n        {\n            //first sum of subtree\n       
```\nclass Solution {\npublic:\n    pair<int,int>find(TreeNode*root,int&sum)\n    {\n        if(root==NULL)\n        {\n            //first sum of subtree\n            // second size of subtree\n            return {0,0};\n        }\n        auto left=find(root->left,sum);\n        auto right=find(root->right,sum);\n        int sum_of_subtree=root->val+left.first+right.first;\n        int size_of_subtree=1+left.second+right.second;\n        if((sum_of_subtree)/(size_of_subtree)==root->val)\n        {\n            sum++;\n        }\n        return {sum_of_subtree,size_of_subtree};\n    }\n    int averageOfSubtree(TreeNode* root) \n    {\n        int sum=0;\n        find(root,sum);\n        return sum;\n    }\n};\n```
['C', 'C++']