You are given a rooted tree with n vertices. In each leaf vertex there's a single integer − the number of apples in this vertex.
The weight of a subtree is the sum of all numbers in this subtree leaves. For instance, the weight of a subtree that corresponds to some leaf is the number written in the leaf.
A tree is balanced if for every vertex v of the tree all its subtrees, corresponding to the children of vertex v, are of equal weight.
Count the minimum number of apples that you need to remove from the tree (specifically, from some of its leaves) in order to make the tree balanced. Notice that you can always achieve the goal by just removing all apples.
Output
Print a single integer − the minimum number of apples to remove in order to make the tree balanced.
Please, do not write the
%lld specifier to read or write 64-bit integers in C++. It is preferred to use the sin, cout streams
cin,
cout or the
%I64d specifier.