Sponsored
Use these hints if you're stuck. Try solving on your own first.
If we know the sum of a subtree, the answer is max( (total_sum - subtree_sum) * subtree_sum) in each node.
Solve with full IDE support and test cases