#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)	
#define REP(i,b) FOR(i,0,b)
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
using pi=pair<int,int>;

void chmin(int&a,int b){
	a=a<b?a:b;
}
void chmax(int&a,int b){
	a=a>b?a:b;
}

const int Nmax=114514;
const int inf=LLONG_MAX/3;
int n;
vi g[Nmax],w[Nmax];
int FindCentroid(int v,int p){
	int res=1,s=0;
	for(auto to:g[v])if(to!=p){
		int fc=FindCentroid(to,v);
		if(fc<=0)return fc;
		chmax(s,fc);
		res+=fc;
	}
	chmax(s,n-res);
	if(s*2<=n)return -v;
	return res;
}
int ans;
int dfs(int v,int p,int c){
	int res=1;
	REP(i,g[v].size())if(g[v][i]!=p)
		res+=dfs(g[v][i],v,w[v][i]);
	ans+=c*res*2;
	return res;
}

signed main(){
	n=read();
	REP(_,n-1){
		int a=read()-1,b=read()-1,c=read();
		g[a].PB(b);
		w[a].PB(c);
		g[b].PB(a);
		w[b].PB(c);
	}
	int root=-FindCentroid(0,-1);
	vi s;
	REP(i,g[root].size())
		s.PB(dfs(g[root][i],root,w[root][i]));
	REP(i,s.size())
		if(s[i]*2==n){
			cout<<ans-w[root][i]<<endl;
			return 0;
		}
	int p=inf;
	REP(i,s.size())
		chmin(p,w[root][i]);
	cout<<ans-p<<endl;
}
