#include <bits/stdc++.h>
using namespace std;
int n,sz[100005];
vector<pair<int,int> > v[100005];
long long sum;
int dfs(int node,int p,int c)
{
	sz[node]=1;
	for (auto u:v[node])
	{
		if (u.first!=p)
		sz[node]+=dfs(u.first,node,u.second);
	}
	sum+=2LL*min(sz[node],n-sz[node])*c;
	return sz[node];
}
int find(int node,int p)
{
	for (auto u:v[node])
	{
		if (u.first!=p && sz[u.first]>n/2)
		return find(u.first,node);
	}
	return node;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		v[a].push_back({b,c});
		v[b].push_back({a,c});
	}
	dfs(1,0,0);
	int c=find(1,0),mn=1e9;
	for (auto u:v[c])
	{
		if (sz[u.first]==(n+1)/2)
		{
			mn=0;
			sum-=u.second;
			break;
		}
		mn=min(mn,u.second);
	}
	printf("%lld",sum-mn);
}