from collections import deque n = int(input()) e = [[] for i in range(n)] for _ in range(n-1): u,v,w = map(int,input().split()) u,v = u-1,v-1 e[u].append([v,w]) e[v].append([u,w]) ans = 0 par = [-1]*n vis = [0]*n vis[0] = 1 q = deque([0]) topo = [] while q: now = q.pop() topo.append(now) for nex,_ in e[now]: if vis[nex]: continue vis[nex] = 1 par[nex] = now q.append(nex) size = [1]*n for now in topo[::-1]: for nex,w in e[now]: if nex == par[now]: continue ans += size[nex]*(n-size[nex])*w size[now] += size[nex] print(ans*2)