import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = map(int,read().split()) UVW = zip(m,m,m) graph = [[] for _ in range(N+1)] for u,v,w in UVW: graph[u].append((v,w)) graph[v].append((u,w)) root = 1 parent = [0] * (N+1) length = [0] * (N+1) order = [] stack = [root] while stack: x = stack.pop() order.append(x) for y,d in graph[x]: if y == parent[x]: continue parent[y] = x length[y] = d stack.append(y) size = [1] * (N+1) for v in order[::-1]: p = parent[v] size[p] += size[v] answer = 2 * sum(d * x * (N-x) for d,x in zip(length, size)) print(answer)