#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair <int,int> pii;

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50;
int n,sze[N],mx_son[N],mx; LL ans;
vector <pii> edge[N];
inline void dfs(int x,int f) {
	sze[x]=1; 
	for(auto v:edge[x])
		if(v.first^f) {
			dfs(v.first,x); sze[x]+=sze[v.first];
			ans+=(LL)v.second*min(sze[v.first],n-sze[v.first])*2;
			mx_son[x]=max(mx_son[x],sze[v.first]);
		}
	mx_son[x]=max(mx_son[x],n-sze[x]);
	mx=min(mx,mx_son[x]);
}
int main() {
	n=rd(); mx=n;
	for(int i=1;i<n;i++) {
		int x=rd(), y=rd(), v=rd();
		edge[x].push_back(pii(y,v));
		edge[y].push_back(pii(x,v));
	} 
	dfs(1,0); 
	int mn=2e9;
	if((!(n&1)) && mx==n/2) {
		for(int i=1;i<=n;i++) if(mx_son[i]==n/2)
			for(auto v:edge[i]) if(mx_son[v.first]==n/2) mn=min(mn,v.second);
	} else {
		for(int i=1;i<=n;i++) if(mx_son[i]==mx)
			for(auto v:edge[i]) mn=min(mn,v.second);
	}
	ans-=mn;
	cout<<ans<<'\n';
}