// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define fi first

#define se second

#define pb push_back

#define mk make_pair

#define Size(x) ((int)((x).size()))

#define rep(i, l, r) for(int (i) = (l); (i) <= (r); ++(i))

#define per(i, r, l) for(int (i) = (r); (i) >= (l); --(i))

#define chkmax(x, y) (x) = max((x), (y))

#define chkmin(x, y) (x) = min((x), (y))

typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vii;

inline char gc() {

	static char now[1<<16], *S, *T;

	if(S == T) {T = (S = now) + fread(now, 1, 1<<16, stdin); if(S == T) return EOF;}

	return *S++;

}

#define gc getchar

inline int read() {

	int x = 0, f = 1; char c = gc();

	while(c < '0' || c > '9') {(c ^ '-') ? 0 : (f = 0); c = gc();}

	while(c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + (c ^ 48); c = gc();}

	return f ? x : ((~x) + 1);

}

#define N 100010

int n;

vector<pii> con[N];



int siz[N], rt = 0, mx[N];

void getrt(int x, int fa) {

	siz[x] = 1; mx[x] = 0;

	for (pii now : con[x]) {

		int y = now.fi;

		if (y == fa) continue ;

		getrt(y, x);

		mx[x] = max(mx[x], siz[y]);

		siz[x] += siz[y];

	}

	mx[x] = max(mx[x], n - siz[x]);

	if (!rt || mx[rt] > mx[x]) rt = x;

}

ll ans = 0;

void dfs(int x, int fa, ll d) {

	siz[x] = 1;

	for (pii now : con[x]) {

		if (now.fi == fa) continue ;

		dfs(now.fi, x, d + now.se);

		siz[x] += siz[now.fi];

	}

	ans += d;

}

int main() {

	n = read();

	for (int i = 1; i < n; ++ i) {

		int u = read(), v = read(), w = read();

		con[u].pb(mk(v, w));

		con[v].pb(mk(u, w));

	}

	getrt(1, 0);

	dfs(rt, 0, 0);

	int tmp = 0x3f3f3f3f;

	for (pii now : con[rt]) {

		int y = now.fi;

		if (siz[y] == (n + 1) / 2) {

			tmp = now.se;

			break ;

		}

		tmp = min(tmp, now.se);

	}

	printf("%lld\n", 2ll * ans - tmp);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.55482229842476x):
//@winlere

#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<vector>



using namespace std;  typedef long long ll;   

inline int qr(){

      register int ret=0,f=0;

      register char c=getchar();

      while(!isdigit(c)) f|=c==45,c=getchar();

      while(isdigit(c)) ret=ret*10+c-48,c=getchar();

      return f?-ret:ret;

}



const ll inf=1e18;

const int maxn=1e5+5;

vector< vector< pair<int,int> > > e;

vector< pair<int,pair<int,int> > > edge;

typedef pair<int,int> P;

P node[maxn],sav[maxn];

int siz[maxn],n;

int spc[maxn],sum;

int d[maxn];

ll ans;



inline void add(const int&fr,const int&to,const int&w){

      e[fr].push_back({to,w}),e[to].push_back({fr,w});

      edge.push_back({w,{fr,to}});

}



void dfs(const int&now,const int&last){

      d[now]=d[last]+1;

      siz[now]=1;

      for(auto t:e[now])

	    if(t.first^last)

		  dfs(t.first,now),siz[now]+=siz[t.first];

}





inline void calc(){

      for(auto t:edge){

	    int u=t.second.first,v=t.second.second;

	    if(d[u]>d[v])swap(u,v);

	    ans+=2ll*siz[v]*t.first;

      }

}



int rt,val=1e9;

void pre(const int&now){

      siz[now]=1;

      int spc=0;

      for(auto t:e[now])

	    if(!siz[t.first])

		  pre(t.first),siz[now]+=siz[t.first],spc=max(spc,siz[t.first]);

      spc=max(spc,n-siz[now]);

      if(val>spc||(val==spc&&now>rt)) val=spc,rt=now;

}



int main(){

      sum=n=qr();

      e.resize(n+1);

      for(int t=1,t1,t2,t3;t< n;++t)

	    t1=qr(),t2=qr(),t3=qr(),add(t1,t2,t3);

      pre(1);

      for(int t=1;t<=n;++t) siz[t]=0;

      dfs(rt,0);

      calc();

      if(((n&1)^1)&& val==(n>>1) ){

	    for(auto t:e[rt])

		  if(siz[t.first]==(n>>1))

			ans-=0ll+t.second;

	    printf("%lld\n",ans);

      }

      else{

	    ll Min=inf;

	    for(auto t:e[rt])

		  Min=min(Min,0ll+t.second);

	    ans-=Min;

	    printf("%lld\n",ans);

      }

      return 0;

}