#include using namespace std; struct edge{ int to; int cost; }; vector G[200000]; long dfs(int v,int p, int n, long &ans){ long ret = 0; for(edge e:G[v]){ int to = e.to; int cost = e.cost; if(to == p)continue; long a = dfs(to,v,n,ans); ans += cost*a*(n-a); ret += a; } return ret + 1; } int main(){ int n = 0; cin >> n; for(int i = 0; i < n-1; i++){ int a , b , c ; cin >> a >> b >> c; G[a].push_back({b , c}); G[b].push_back({a , c}); } long ans = 0; dfs(1,-1,n,ans); cout << ans * 2 << endl; }