#include <bits/stdc++.h>
using namespace std;

int N;
long long sum = 0;
vector< pair<int, int> > adjlist[100005];
vector<int> centroids;

int dfs(int x, int p, int pw) {
	int ans = 1;
	int mx = 0;
	for (int i = 0; i < adjlist[x].size(); i++) {
		if (adjlist[x][i].first != p) {
			int val = dfs(adjlist[x][i].first, x, adjlist[x][i].second);
			mx = max(mx, val);
			ans += val;
		}
	}
	mx = max(mx, N - ans);
	if (mx * 2 <= N) centroids.push_back(x);
	sum += (long long)min(ans, N - ans) * pw * 2;
	return ans;
}
map< pair<int, int>, int> W;

int main() {
	scanf("%d", &N);
	int minedge = 1000000000;
	for (int i = 0; i < N-1; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);a--;b--;
		adjlist[a].push_back(make_pair(b, c));
		W[make_pair(a, b)] = W[make_pair(b, a)] = c;
		adjlist[b].push_back(make_pair(a, c));
	}
	dfs(0, -1, 0);
	if (centroids.size() == 1) {
		for (int i = 0; i < centroids.size(); i++) {
			for (int j = 0; j < adjlist[centroids[i]].size(); j++) minedge = min(minedge, adjlist[centroids[i]][j].second);
		}
	} else {
		minedge = W[make_pair(centroids[0], centroids[1])];
	}
	
	printf("%lld\n", sum - minedge);
}
