It is a well-known fact that alpacas love numbers. The reason behind this fascination is uncertain, but that shouldn't be your concern at the moment. You've stumbled upon a herd of alpacas living in
Let us define
You look up and find yourself face to face with the queen alpaca and she's angry. She orders you to tell her the minimum value of
Constraints
Subtask 1 [10%]
Subtask 2 [20%]
Subtask 3 [70%]
No additional constraints.
Input Specification
The first line of input will contain the integer
The next
Output Specification
Output the minimal possible value of
Note that 64-bit integers may be required.
Sample Input 1
5
5 3 97
4 2 21
1 2 49
3 2 4
Sample Output 1
2
Explanation for Sample Output 1
An optimal solution is not changing any lengths.
In the original graph, there are
of length . of length . of length . of length . of length . of length .
Furthermore, there are
of length . of length . of length . of length .
Thus, the answer is
Sample Input 2
6
6 1 100
2 1 86
4 3 12
3 2 40
5 2 44
Sample Output 2
1
Comments
getting turned into an alpaca doesn't sound so bad :)