#include <bits/stdc++.h>
using namespace std;
const long long mx = 5005;
pair<pair<long long, long long>, long long> ed[mx];
vector<pair<long long, long long> > ad[mx];
long long su[mx], sd[mx], chd[mx], chu[mx], n, mini, mini2;
void dfs_d(long long v, long long par) {
  chd[v] = 1;
  sd[v] = 0;
  for (auto u : ad[v]) {
    if (u.first != par) {
      dfs_d(u.first, v);
      chd[v] += chd[u.first];
      sd[v] += sd[u.first] + u.second * chd[u.first];
    }
  }
  return;
}
void dfs_u(long long v, long long par) {
  for (auto u : ad[v]) {
    if (u.first != par) {
      chu[u.first] = chd[v] - chd[u.first] + chu[v];
      su[u.first] = sd[v] - (sd[u.first] + u.second * chd[u.first]) + su[v] +
                    (chu[u.first]) * u.second;
      dfs_u(u.first, v);
    }
  }
  mini = min(mini, sd[v] + su[v]);
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long u, v, w, ansn = 1e18, ans;
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    u--, v--;
    ed[i] = {{u, v}, w};
  }
  for (long long i = 0; i < n - 1; i++) {
    ans = 0;
    for (long long j = 0; j < n; j++) ad[j].clear();
    for (long long j = 0; j < n - 1; j++)
      if (j != i) {
        v = ed[j].first.first, u = ed[j].first.second;
        ad[v].push_back({u, ed[j].second});
        ad[u].push_back({v, ed[j].second});
      }
    v = ed[i].first.first, u = ed[i].first.second;
    mini = 1e18;
    dfs_d(v, -1);
    chu[v] = su[v] = 0;
    dfs_u(v, -1);
    mini2 = mini;
    mini = 1e18;
    dfs_d(u, -1);
    chu[u] = su[u] = 0;
    dfs_u(u, -1);
    long long x = chd[u] + chu[u], y = chd[v] + chu[v];
    long long second = mini * y + x * mini2 + x * y * ed[i].second;
    for (long long i = 0; i < n; i++) ans += sd[i] + su[i];
    ansn = min(ansn, second + ans / 2);
  }
  cout << ansn << endl;
  return 0;
}
