#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 29;
const double dinf = 1e30;
const long long linf = 1LL << 55;
const int N = 5555;
vector<pair<int, int> > vec[N];
pair<int, int> edge[N];
int n;
long long cnt[N], down[N], up[N];
long long ans;
void dfs(int u, int fa) {
  cnt[u] = down[u] = 0;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i].first;
    if (v == fa) continue;
    dfs(v, u);
    cnt[u] += cnt[v];
    down[u] += down[v] + cnt[v] * vec[u][i].second;
  }
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i].first;
    if (v == fa) continue;
    ans += (cnt[u] - cnt[v]) * (down[v] + cnt[v] * vec[u][i].second);
  }
  ans += down[u];
  cnt[u]++;
}
int visit[N];
int s, t;
void dfs1(int u, int fa, int flag) {
  cnt[u] = 1;
  visit[u] = flag;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i].first;
    if (v == fa || v == s || v == t) continue;
    dfs1(v, u, flag);
    cnt[u] += cnt[v];
    down[u] += down[v] + vec[u][i].second * cnt[v];
  }
}
void dfs2(int u, int fa, long long w, int n) {
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i].first;
    if (v == fa || v == s || v == t) continue;
    up[v] = down[u] + up[u] - down[v] + (n - 2 * cnt[v]) * vec[u][i].second;
    dfs2(v, u, vec[u][i].second, n);
  }
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) vec[i].clear();
    for (int i = 0; i < n - 1; i++) {
      int a, b, len;
      cin >> a >> b >> len;
      edge[i] = make_pair(a, b);
      vec[a].push_back(make_pair(b, len));
      vec[b].push_back(make_pair(a, len));
    }
    ans = 0;
    dfs(1, -1);
    long long tmp = ans;
    for (int i = 0; i < n - 1; i++) {
      memset(visit, 0, sizeof(visit));
      memset(down, 0, sizeof(down));
      memset(up, 0, sizeof(up));
      int u = edge[i].first, v = edge[i].second;
      s = u, t = v;
      dfs1(u, v, 0);
      dfs1(v, u, 1);
      int nu = cnt[u], nv = cnt[v];
      dfs2(u, -1, -1, nu);
      dfs2(v, -1, -1, nv);
      long long val[2] = {linf, linf};
      for (int i = 1; i <= n; i++) {
        val[visit[i]] = min(val[visit[i]], down[i] + up[i]);
      }
      ans = min(ans, tmp - cnt[u] * down[v] - cnt[v] * down[u] +
                         cnt[u] * val[1] + cnt[v] * val[0]);
    }
    cout << ans << endl;
  }
  return 0;
}
