#include using namespace std; long long N; vector>> edge; vector dist; void dfs(int from, int prev = -1){ for(int i = 0; i < edge[from].size(); ++i){ int to = edge[from][i].first; if(to==prev) continue; dist[to] = dist[from] + edge[from][i].second; dfs(to,from); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; edge.resize(N); dist.resize(N); for(int i = 0; i < N-1; ++i){ int u,v; long long w; cin >> u >> v >> w; u--,v--; edge[u].push_back({v,w}); edge[v].push_back({u,w}); } long long ans = 0; for(int i = 0; i < N; ++i){ for(int j = 0; j < N; ++j) dist[j] = 0; dfs(i,-1); ans += accumulate(dist.begin(),dist.end(),0LL); } cout << ans << endl; return 0; }