You are given a binary tree with N nodes numbered from 1 to N. For each node i, let A_i denote the value of node i. Let S_Anc(i) be the sum of values of all the nodes whose ancestors are node i inclusive and rooted at node 1. Let F(i) = |S_Anc(i) - S_Subtree(i)|. S_Subtree(i) is the sum of values of all the nodes on the simple path between node i and node N. If there is no child on some side, then it would be denoted by -1.
Calculate the sum of F(v) for all v from 1 to N.
Assumptions


The sum of F(v) for all v from 1 to N.