#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 7;
set<pair<long long, long long> > ad[N];
vector<pair<pair<long long, long long>, long long> > ads;
long long n, res, sz[N], dp1[N], szrt;
void dfs(long long v, long long d) {
  sz[v] = 1;
  for (auto p : ad[v]) {
    long long u = p.first;
    long long w = p.second;
    if (u == d) continue;
    dfs(u, v);
    sz[v] += sz[u];
    dp1[v] += dp1[u] + sz[u] * w;
  }
}
long long findmn(long long v, long long d) {
  long long ans = dp1[v];
  for (auto p : ad[v]) {
    long long u = p.first;
    long long w = p.second;
    if (u == d) continue;
    dp1[u] = dp1[v] - sz[u] * w + (szrt - sz[u]) * w;
    ans = min(findmn(u, v), ans);
  }
  return ans;
}
long long findsm(long long v, long long d) {
  long long ans = dp1[v];
  for (auto p : ad[v]) {
    long long u = p.first;
    long long w = p.second;
    if (u == d) continue;
    ans += findsm(u, v);
  }
  return ans;
}
int32_t main() {
  res = 1e18;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    ad[v].insert({u, w});
    ad[u].insert({v, w});
    ads.push_back({{v, u}, w});
  }
  for (auto p : ads) {
    long long v = p.first.first;
    long long u = p.first.second;
    long long w = p.second;
    ad[v].erase({u, w});
    ad[u].erase({v, w});
    memset(sz, 0, sizeof sz);
    memset(dp1, 0, sizeof dp1);
    vector<long long> szcom, mncom, smcom;
    for (long long i = 1; i <= n; i++) {
      if (sz[i]) continue;
      dfs(i, 0);
      szrt = sz[i];
      szcom.push_back(sz[i]);
      mncom.push_back(findmn(i, 0));
      smcom.push_back(findsm(i, 0) / 2);
    }
    res = min(res, smcom[0] + smcom[1] + szcom[0] * szcom[1] * w +
                       szcom[0] * mncom[1] + szcom[1] * mncom[0]);
    ad[v].insert({u, w});
    ad[u].insert({v, w});
  }
  cout << res;
  return 0;
}
