Use pair
\n# Code\n\nclass Solution {\npublic:\n    int cnt = 0;\n\n    pair<int, int> f(TreeNode* root) {\n        if(!root)return {0, 0};\n        auto lsum = f(root->
\n# Code\n```\nclass Solution {\npublic:\n    int cnt = 0;\n\n    pair<int, int> f(TreeNode* root) {\n        if(!root)return {0, 0};\n        auto lsum = f(root->left);\n        auto rsum = f(root->right);\n\n        int sum = (lsum.first + rsum.first + root->val);\n        int c = lsum.second + rsum.second + 1;\n        int avg = sum / c;\n        if(avg == root->val)cnt++;\n        return {sum, c};\n    }\n\n    int averageOfSubtree(TreeNode* root) {\n        f(root);\n        return cnt;\n    }\n};\n```
['C++']