def inpl(): return list(map(int, input().split())) N = int(input()) size = [1]*N depth = [-1]*N G = [[] for _ in range(N)] E = [] for _ in range(N-1): a, b, w = inpl() a, b = a-1, b-1 G[a].append(b) G[b].append(a) E.append([a, b, w]) depth[0] = 0 Q = [0] Q2 = [] while Q: p = Q.pop() for q in G[p]: if depth[q] != -1: continue depth[q] = depth[p] + 1 Q.append(q) Q2.append([p, q]) while Q2: a, b = Q2.pop() size[a] += size[b] ans = 0 for a, b, w in E: if depth[a] < depth[b]: a, b = b, a ans += w * size[a] * (N-size[a]) print(ans*2)