#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define FILE_NAME "a"


int n;
vector<vii> g;

bool read() {
	if  (scanf("%d", &n) < 1) {
		return 0;
	}
	g.clear();
	g.resize(n);
	forn(i, n - 1) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		--a;
		--b;
		g[a].pb(mp(b, c));
		g[b].pb(mp(a, c));
	}
	return 1;
}

void dfs_sz(int v, int p, vi& sz) {
	sz[v] = 1;
	for (const auto& e : g[v]) {
		int to, c;
		tie(to, c) = e;
		if  (to == p) {
			continue;
		}
		dfs_sz(to, v, sz);
		sz[v] += sz[to];
	}
}

ll calc_sum(int v, int p, const vi& size) {
	ll ans = 0;
	for (const auto& e : g[v]) {
		int to, c;
		tie(to, c) = e;
		if  (to == p) {
			continue;
		}
		ll cur = calc_sum(to, v, size);
		cur += c * 1ll * size[to];
		ans += cur;
	}
	return ans;
}

ll check(int v) {
	vi size(n);
	dfs_sz(v, -1, size);

	int mx_to = -1;
	for (const auto& e : g[v]) {
		int to, c;
		tie(to, c) = e;
		if  (mx_to == -1 || size[to] > size[mx_to]) {
			mx_to = to;
		}
	}
	assert(mx_to != -1);

	ll sum = 0;
	for (const auto& e : g[v]) {
		int to, c;
		tie(to, c) = e;
		ll cur_sum = calc_sum(to, v, size);
		cur_sum += c * 1ll * size[to];
		sum += cur_sum;
	}	
	sum *= 2;
	
	if  (size[mx_to] * 2 == n) {
		ll ans = sum;
		for (const auto& e : g[v]) {
			int to, c;
			tie(to, c) = e;
			if  (to == mx_to) {
				ans -= c;
				break;
			}
		}
		return ans;
	}

	assert(size[mx_to] * 2 < n);
	
	ll ans = sum;
	int mn = int(1e9);
	for (const auto& e : g[v]) {
		int to, c;
		tie(to, c) = e;
		if  (c < mn) {
			mn = c;
		}
	}
	ans -= mn;

	return ans;
}

ll solve(int v, const vi& size) {
	int mx = 0;
	for (const auto& e : g[v]) {
		int to, c;
		tie(to, c) = e;
		const int cur_sz = size[to] > size[v] ? n - size[v] : size[to];
		mx = max(mx, cur_sz);
	}
	if  (mx * 2 > n) {
		return 0;
	}
	return check(v);
}

ll solve() {
	if  (n == 2) {
		return g[0][0].snd;
	}
	assert(n > 2);

	vi size(n);
	dfs_sz(0, -1, size);

	ll ans = 0;
	forn(v, n) {
		ans = max(ans, solve(v, size));
	}
	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		printf("%lld\n", solve());
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 13184