import sys input = sys.stdin.readline n = int(input()) g = [[] for _ in range(n)] d = {} for i in range(n-1): u, v, w = map(int, input().split()) u, v = u-1, v-1 d[(u, v)] = w d[(v, u)] = w g[u].append(v) g[v].append(u) s = [] visit = [-1]*n s.append(0) order = [] par = [-1]*n while s: v = s.pop() order.append(v) for u in g[v]: if u == par[v]: continue par[u] = v s.append(u) ans = 0 c = [1]*n order.reverse() for v in order: if par[v] != -1: ans += (n-c[v])*c[v]*d[(v, par[v])] c[par[v]] += c[v] print(ans*2)