Beads and Wires

No attempts yetTime limit1sMemory limit128 MB

Problem

In the bead-threading game, thread comes in red and blue. Beads are numbered 11 through nn. You start with one bead and may add beads using:

  • Append(w, v): connect new bead ww to existing bead vv with a red thread.
  • Insert(w, u, v): insert new bead ww between beads uu and vv that are connected by red thread. Remove the red thread uu-vv and replace it with blue threads uu-ww and ww-vv.

Every thread has a length. When the game ends, the score is the sum of blue thread lengths.

You are given a final connection state: each thread connects two beads with a length, but colors are unknown. Among all ways to produce this state, output the maximum possible final score.

Input

Line 1: nn (1n2000001 \le n \le 200\,000).

Next n1n-1 lines: aia_i, bib_i, cic_i (1ai<bin1 \le a_i < b_i \le n, 1ci100001 \le c_i \le 10\,000). Beads aia_i and bib_i are connected by a thread of length cic_i.

Output

Print the maximum possible final score.

Hint

In the sample, start at bead 3, connect 5, insert 1 between 3 and 5, then append 2 and 4 to 1 for a score of 60. No larger score exists.