- Time limit: 1.00 s
- Memory limit: 512 MB
A computer network has computers and connections between two computers. Information can be exchanged between every pair of computers using the connections.
Each connection has a certain transfer speed. Let denote the transfer speed between computers and , which is the speed of the slowest connection on the route between and . Your task is to compute the sum of transfer speeds between all pairs of computers.
Input
The first line contains the integer : the number of computers. The computers are numbered .
After this, there are lines, which describe the connections. Each line has three integers , and : there is a connection between computers and with transfer speed .
Output
Print one integer: the sum of transfer speeds.
Constraints
Example
Input:
4 1 2 5 2 3 1 2 4 2
Output:
12
Explanation: The following figure corresponds to the sample input: