#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;

void dfs(int v, int par, VVI &g, VI &sub, VI &in, VI &out, int &t) {
    sub[v] = 1;
    in[v] = ++t;
    
    for (int u : g[v]) if (u != par) {
        dfs(u, v, g, sub, in, out, t);
        sub[v] += sub[u];
    }
    
    out[v] = t;
}

struct ITree {
    typedef ll val_t;

    vector <val_t> T;
    int p = 1;

    ITree(int n) {
        while (p < n) p *= 2;
        T.resize(2*p-1,0);
    }

    int par(int x) { return (x - 1) / 2; }

    void add(int l, int r, val_t v) {
        l += p-1; r += p-1;

        T[l] += v;
        if (l < r) T[r] += v;

        while (par(l) != par(r)) {
            if (l%2 == 1) T[l+1] += v;
            if (r%2 == 0) T[r-1] += v;

            l = par(l);
            r = par(r);
        }
    }

    val_t query(int l) {
        l += p-1;

        val_t ans = T[l];

        while (l) {
            l = par(l);
            ans += T[l];
        }

        return ans;
    }
};

/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    VVI g(n);
    
    struct edge { int u, v, c; };
    vector <edge> edges;
    
    FOR(i,1,n-1) {
        int u, v, c;
        cin >> u >> v >> c; u--; v--;
        
        g[u].pb(v);
        g[v].pb(u);
        
        edges.pb({u, v, c});
    }
    
    VI sub(n), in(n), out(n);
    int t = -1;
    
    dfs(0, -1, g, sub, in, out, t);
    
    ll ans = 0;
    ITree tree(n);
    
    int uSpec = edges[0].u, vSpec = edges[0].v;
    if (sub[uSpec] > sub[vSpec]) swap(uSpec, vSpec);
    
    int costSpec = 0;
    
    for (auto e : edges) {
        int u = e.u, v = e.v;
        if (sub[u] > sub[v]) swap(u, v);
        
        int x = sub[u];
        int y = n - x;
    
        int amount = 2 * min(x, y);
        ans += (ll) amount * e.c;
        
        if (x == y) {
            uSpec = u;
            vSpec = v;
            
            costSpec = -e.c;
            tree.add(0, n-1, e.c);
        }
        
        if (x < y) {
            tree.add(in[u], out[u], e.c);
        } else if (x > y) {
            tree.add(0, n-1, e.c);
            tree.add(in[u], out[u], -e.c);
        }
    }
    
    
    VL values[2];
    FOR(i,0,n-1) {
        ll val = tree.query(in[i]);
        bool below = in[i] >= in[uSpec] && out[i] <= out[uSpec];
        
        values[below].pb(val);
    }
    
    FOR(i,0,1) {
        sort(values[i].begin(), values[i].end());
    }
    
    ll minCost = values[0][0] + values[1][0] + costSpec;
    
    FOR(i,0,1) if (SIZE(values[i]) >= 2) {
        minCost = min(minCost, values[i][0] + values[i][1]);
    }
    
    cout << ans - minCost;

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 22068