CSES - Transfer Speeds Sum
  • Time limit: 1.00 s
  • Memory limit: 512 MB

A computer network has nn computers and n1n-1 connections between two computers. Information can be exchanged between every pair of computers using the connections.

Each connection has a certain transfer speed. Let d(a,b)d(a,b) denote the transfer speed between computers aa and bb, which is the speed of the slowest connection on the route between aa and bb. Your task is to compute the sum of transfer speeds between all pairs of computers.

Input

The first line contains the integer nn: the number of computers. The computers are numbered 1,2,,n1,2,\dots,n.

After this, there are n1n-1 lines, which describe the connections. Each line has three integers aa, bb and xx: there is a connection between computers aa and bb with transfer speed xx.

Output

Print one integer: the sum of transfer speeds.

Constraints

  • 1n21051 \le n \le 2 \cdot 10^5
  • 1x1061 \le x \le 10^6

Example

Input:

4
1 2 5
2 3 1
2 4 2

Output:

12

Explanation: The following figure corresponds to the sample input:

Here d(1,2)=5d(1,2)=5, d(1,3)=1d(1,3)=1, d(1,4)=2d(1,4)=2, d(2,3)=1d(2,3)=1, d(2,4)=2d(2,4)=2, and d(3,4)=1d(3,4)=1, so the sum of transfer speeds is 1212.