You are given a tree consisting of nodes and edges. Each edge has a weight and each node as a value . You can perform the following two operations on the tree any number of times:
- Double a node 's value. In other words, .
- Take an edge and divide (integer division) the edge's weight by the GCD (greatest common divisor) of the value of the nodes connected by the edge. In other words, , where and are the two nodes the edge connects.
After performing the above two operations any number of times, what is the minimum sum of all the edge weights and node values?
The first line will contain the integer .
The next line will contain integers, .
The next lines will each contain three integers, , meaning that nodes and will be connected by an edge of weight . It is guaranteed that the tree will be fully connnected.
Output the minimum sum of all the edge weights and node values after performing the above operations any number of times.
3 3 2 1 1 2 10 2 3 9