A binary tree is represented as a series of relationships between each node and the Root node. The relationships are denoted as combinations of 'L' and 'R', such as L, R, LL, LR... and so on, where each node is left (L) to Root or left-right (LL) or right-left (RL) to the Root node and so on.
In this tree, if the sum of digits of the left child node is equal to the sum of digits of the right child node, then their parent is called a Super Node.
Write a program to find all the Super Nodes in a given tree, and print the sum of all those Super nodes.
The first line of input contains N, the number of nodes in the tree. The second line of input contains the Root node. The next N-1 lines of input contain a string S, and an integer X, separated by a single white space, where X is a node in the tree and S is the relation between the Root node and X.
The output contains an integer, which is the sum of all Super Nodes.
Hard