#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int64,int64> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()

const int maxn=200000+16;


int n;
vector<ipair> g[maxn];
int64 d[maxn];
int64 c[maxn];
int64 min_d[maxn];
int64 sum_d[maxn];
int64 ret;

void dfs1(int p,int prev)
{
	c[p]=1;
	min_d[p]=d[p];
	sum_d[p]=d[p];
	REP(i,SIZE(g[p])) if (g[p][i].first==prev) { g[p][i]=g[p].back(); g[p].pop_back(); break; }
	for (const auto& e:g[p]) 
	{ 
		int key=e.first;
		d[key]=d[p]+e.second;
		dfs1(key,p);
		c[p]+=c[key]; 
		sum_d[p]+=sum_d[key];
		ckmin(min_d[p],min_d[key]);
	}
}
void dfs2(int p,int64 c0,int64 min_d0,int64 sum_d0)
{
	int max_cnt=c0;
	int max_key=-1;
	int64 sum_d_to_p=sum_d0;
	for (const auto& e:g[p])
	{
		int key=e.first;
		sum_d_to_p+=sum_d[key]-d[p]*c[key];
		if (c[key]>max_cnt) max_cnt=c[key],max_key=key;
	}	
	if (max_cnt*2==n)
	{
		int64 md=((max_key<0)?min_d0:min_d[max_key]);
		ckmax(ret,sum_d_to_p*2-md);
	}
	else if (max_cnt*2<n)
	{
		int64 md=1LL<<62;
		if (c0>0) ckmin(md,min_d0);
		for (const auto& e:g[p]) ckmin(md,min_d[e.first]-d[p]);
		ckmax(ret,sum_d_to_p*2-md);
	}
	if (SIZE(g[p])>0)
	{
		int size=SIZE(g[p]);
		vector<int64> f1(size),f2(size);
		f1[0]=min_d[g[p][0].first];
		for (int i=1;i<size;i++) f1[i]=min(f1[i-1],min_d[g[p][i].first]);
		f2[size-1]=min_d[g[p][size-1].first];
		for (int i=size-2;i>=0;i--) f2[i]=min(f2[i+1],min_d[g[p][i].first]);
		REP(i,size)
		{
			int key=g[p][i].first;
			int64 length=g[p][i].second;
			int64 new_c0=n-c[key];
			int64 new_min_d0=length;
			int64 new_sum_d0=(sum_d0+(sum_d[p]-sum_d[key]-(c[p]-c[key])*d[p]))+new_c0*length;
			dfs2(key,new_c0,new_min_d0,new_sum_d0);
		}
	}
}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	while (cin>>n)
	{
		REP(i,n) g[i].clear();
		REP(i,n-1)
		{
			int a,b,w;
			cin>>a>>b>>w;
			--a;
			--b;
			g[a].emplace_back(b,w);
			g[b].emplace_back(a,w);
		}
		d[0]=0;
		dfs1(0,-1);
		ret=0;
		if (n==2)
			ret=d[1];
		else
			dfs2(0,0,1LL<<62,0);
		cout<<ret<<endl;
#ifndef _MSC_VER
		break;
#endif
	}
	return 0;
}



Measured memory_bytes: 28672