#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(' ')
    const int INF = 0x3f3f3f3f;
    typedef long long LL;
    typedef double DB;
    inline char gchar() {
        char ret = getchar();
        for(; (ret == '\n' || ret == '\r' || ret == ' ') && ret != EOF; ret = getchar());
        return ret; }
    template<class T> inline void fr(T &ret, char c = ' ', int flg = 1) {
        for(c = getchar(); (c < '0' || '9' < c) && c != '-'; c = getchar());
        if (c == '-') { flg = -1; c = getchar(); }
        for(ret = 0; '0' <= c && c <= '9'; c = getchar())
            ret = ret * 10 + c - '0';
        ret = ret * flg; }
    inline int fr() { int t; fr(t); return t; }
    template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
    template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
    template<class T> inline char wr(T a, int b = 10, bool p = 1) {
        return a < 0 ? pc('-'), wr(-a, b, 0) : (a == 0 ? (p ? pc('0') : p) : 
            (wr(a/b, b, 0), pc('0' + a % b)));
    }
    template<class T> inline void wt(T a) { wn(a); }
    template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
    template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
    template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
    template<class T> inline T gcd(T a, T b) {
        return b == 0 ? a : gcd(b, a % b); }
    template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
        for(; i; i >>= 1, b = b * b % _m)
            if(i & 1) r = r * b % _m;
        return r; }
};
using namespace my_header;

const int N = 1e5 + 100;
const int M = N<<1;

struct Edge {
	int e, h[N], t[M], n[M], w[M];
	void init() {
		e = 0; memset(h, -1, sizeof h);
	}
	void add(int u, int v, int c) {
		t[e] = v, n[e] = h[u], w[e] = c, h[u] = e++;
		t[e] = u, n[e] = h[v], w[e] = c, h[v] = e++;
	}
} e;

int n;
LL ans;

int siz[N], ef[N];
void dfs(int u, int f = -1) {
	siz[u] = 1;
	for (int i = e.h[u]; i != -1; i = e.n[i]) {
		int v = e.t[i];
		if (v == f) continue;
		ef[v] = i;
		dfs(v, u);
		siz[u] += siz[v];
	}
	ans += 1LL * e.w[ef[u]] * min(siz[u], n - siz[u]) * 2;
}


int main() {
#ifdef lol
	freopen("d.in", "r", stdin);
	freopen("d.out", "w", stdout);
#endif

	fr(n);
	e.init();
	for (int i = 1; i < n; ++i) {
		int u, v, w;
		fr(u, v, w);
		e.add(u, v, w);
	}
	dfs(1);
	//for (int i = 1; i <= n; ++i)
	//	ws(siz[i]);
	//puts("");
	for (int i = 2; i <= n; ++i) {
		if (siz[i] * 2 == n) {
			wt(ans - e.w[ef[i]]);
			return 0;
		}
	}
	int val = INT_MAX;
	
	//wt(ans);
	for (int i = 1; i <= n; ++i) {
		int maxSiz = n - siz[i], minEdge = i == 1 ? INT_MAX : e.w[ef[i]];
		for (int j = e.h[i]; j != -1; j = e.n[j]) {
			if (e.t[j] != e.t[ef[i] ^ 1]) {
				maxSiz = max(maxSiz, siz[e.t[j]]);
				minEdge = min(minEdge, e.w[j]);
			}
		}
		//wt(maxSiz);
		if (maxSiz * 2 <= n) {
			val = min(val, minEdge);
		}
	}
	wt(ans - val);

	return 0;
}



Measured memory_bytes: 7808