Statement
There are traffic lights and wires. The lights are numbered , and the wires connect them as a tree.
Each light has state or . Every wire must be inspected exactly once, and the inspection order may be chosen freely.
Inspecting a wire with endpoints performs the following actions in order:
- If the states of lights and differ immediately before the inspection, pay this wire's cost.
- Then flip both states. State becomes , and state becomes .
Find the minimum total cost paid while inspecting every wire.
Input
The input is given in the following format:
Each case is given in the following format:
is the initial state of light .
Output
For each test case, print the minimum total cost of inspecting every wire exactly once.
Constraints
- .
- .
- ().
- , ().
- ().
- The given wires form a tree.
- The sum of over all test cases does not exceed .
Subtasks
Samples
Input
1
7
0010010
1 2 6
1 3 14
3 4 6
4 5 10
3 6 5
3 7 13
Output
5
Inspecting the wires in the order pays cost only on wire .