#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = (int) 1e5 + 123;

int n;
vector<pair<int, int>> g[N];
ll ans;
int down[N], depth[N];

void dfs1(int v, int p = -1) {
    down[v] = 1;
    for (auto &e : g[v]) {
        if (e.first != p) {
            depth[e.first] = depth[v] + 1;
            dfs1(e.first, v);
            down[v] += down[e.first];
        }
    }
}

void run() {
    cin >> n;
    rep(i, 0, n - 1) {
        int u, v, c;
        cin >> u >> v >> c;
        g[u].pb({v, c});
        g[v].pb({u, c});
    }
    
    dfs1(1);
    
    ll sum = 0;
    
    rep(v, 1, n + 1) {
        for (auto &e : g[v]) {
            int u = e.first;
            if (depth[v] > depth[u]) continue;
            
            int x1 = down[u];
            int x2 = n - down[u];
            int x = min(x1, x2);
            sum += x * 2LL * e.second;
        }
    }
    
    rep(v, 1, n + 1) {
        for (auto &e : g[v]) {
            int u = e.first;
            if (depth[v] > depth[u]) continue;
            
            int x1 = down[u];
            int x2 = n - down[u];
            if (x1 == x2) {
                maxi(ans, sum - e.second);
            }
        }
    }
    
    rep(v, 1, n + 1) {
        int mi = INF;
        int ma = 0;
        for (auto &e : g[v]) {
            int u = e.first;
            int cnt;
            if (depth[v] < depth[u]) { 
                cnt = down[u];
            } else {
                cnt = n - down[v];
            }
            mini(mi, e.second);
            maxi(ma, cnt);
        }
        if (2 * ma < n) maxi(ans, sum - mi);
    }
    
    cout << ans << "\n";
}


Measured memory_bytes: 10496