Bessie is planning the annual Great Cow Gathering and wants to choose the most convenient barn to host it.
Every cow lives in one of $N$ barns, numbered $1$ through $N$. The barns are connected by $N-1$ roads so that you can travel between any two barns. Road $i$ connects barns $A_i$ and $B_i$ and has length $L_i$; the barns therefore form a tree. Barn $i$ is home to $C_i$ cows.
The gathering may be held in any single barn. If it is held in barn $X$, its inconvenience is the total distance every cow must travel to reach $X$: a barn holding $C_i$ cows at distance $d$ from $X$ contributes $C_i \cdot d$. For example, if $3$ cows live in a barn $20$ units away from $X$, they add $3 \times 20 = 60$ to the inconvenience.
Choose the barn that minimizes the total inconvenience, and report that minimum inconvenience.
Constraints