#include <bits/stdc++.h>
using namespace std;
const long long inf = 5e3 + 9, MX = 1e18 + 9;
long long n, a[inf], b[inf], c[inf], blocked, sz, mn, ans = MX, sum;
vector<pair<long long, long long> > adj[inf];
long long dpdown[inf], dpup[inf], szdown[inf], szup[inf];
void dfsdown(long long u, long long p) {
  dpdown[u] = 0;
  szdown[u] = 1;
  for (auto o : adj[u]) {
    long long v = o.first, idx = o.second, w = c[o.second];
    if (v == p || blocked == idx) continue;
    dfsdown(v, u);
    szdown[u] += szdown[v];
    dpdown[u] += dpdown[v] + w * szdown[v];
  }
}
void dfsup(long long u, long long p) {
  sz++, mn = min(mn, dpup[u] + dpdown[u]), sum += dpup[u] + dpdown[u];
  szup[u]++;
  for (auto o : adj[u]) {
    long long v = o.first, idx = o.second, w = c[o.second];
    if (v == p || blocked == idx) continue;
    szup[v] = szup[u] + szdown[u] - szdown[v] - 1;
    dpup[v] = dpup[u] + dpdown[u] - ((w * szdown[v]) + dpdown[v]) + szup[v] * w;
    dfsup(v, u);
  }
}
void go(long long u) {
  sz = 0, mn = MX, sum = 0;
  dfsdown(u, 0);
  dfsup(u, 0);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (long long i = 1; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    adj[a[i]].push_back({b[i], i});
    adj[b[i]].push_back({a[i], i});
  }
  for (long long i = 1; i < n; i++) {
    blocked = i;
    memset(dpdown, 0, sizeof(dpdown));
    memset(dpup, 0, sizeof(dpup));
    memset(szdown, 0, sizeof(szdown));
    memset(szup, 0, sizeof(szup));
    long long cur = 0;
    pair<long long, long long> part1, part2;
    go(a[i]);
    part1 = make_pair(sz, mn), cur += sum / 2;
    go(b[i]);
    part2 = make_pair(sz, mn), cur += sum / 2;
    long long s = cur + part1.second * part2.first +
                  part2.second * part1.first +
                  c[i] * (part1.first * part2.first);
    ans = min(ans, s);
  }
  cout << ans << endl;
}
