#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct FixPoint : F{ FixPoint(F&& f):F(forward(f)){} template decltype(auto) operator()(Args&&... args) const{ return F::operator()(*this,forward(args)...); } }; template inline decltype(auto) MFP(F&& f){ return FixPoint{forward(f)}; } //INSERT ABOVE HERE signed main(){ Int n; cin>>n; using P = pair; vector< vector< P > > G(n); for(Int i=1;i>u>>v>>w; u--;v--; G[u].emplace_back(v,w); G[v].emplace_back(u,w); } Int ans=0; vector sz(n,0); MFP([&](auto dfs,Int v,Int p)->void{ sz[v]=1; for(auto e:G[v]){ Int u,c; tie(u,c)=e; if(u==p) continue; dfs(u,v); sz[v]+=sz[u]; ans+=(n-sz[u])*sz[u]*c*2; } })(0,-1); cout<