#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
const long long INF = 1e17 + 7;
int sz[N], n;
long long dpup[N], dpdown[N], ans = INF;
vector<pair<int, int> > adj[N];
void dfsdown(int u, int par);
void dfsup(int v, int par, long long &MIN, int rootsz);
long long solve(int v, int u, int w);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  for (int v = 1; v <= n; v++)
    for (auto p : adj[v])
      if (p.first >= v) ans = min(ans, solve(v, p.first, p.second));
  cout << ans << '\n';
  return 0;
}
void dfsdown(int u, int par) {
  sz[u] = 1;
  for (auto p : adj[u])
    if (p.first != par) {
      dfsdown(p.first, u);
      sz[u] += sz[p.first];
      dpdown[u] += dpdown[p.first] +
                   (long long)p.second * sz[p.first] * (n - sz[p.first]);
    }
}
void dfsup(int v, int par, long long &MIN, int rootsz) {
  for (auto p : adj[v]) {
    if (p.first != par) {
      dpup[p.first] += dpup[v] + dpdown[v] - dpdown[p.first] -
                       (long long)p.second * sz[p.first] * (n - sz[p.first]) +
                       (long long)p.second * (rootsz - sz[p.first]) *
                           (n - rootsz + sz[p.first]);
      dfsup(p.first, v, MIN, rootsz);
    }
  }
  MIN = min(MIN, dpup[v] + dpdown[v]);
}
long long solve(int v, int u, int w) {
  fill(dpdown, dpdown + N - 5, 0);
  fill(dpup, dpup + N - 5, 0);
  long long MIN1 = INF, MIN2 = INF;
  dfsdown(v, u);
  dfsup(v, u, MIN1, sz[v]);
  dfsdown(u, v);
  dfsup(u, v, MIN2, sz[u]);
  return MIN1 + MIN2 + (long long)w * sz[v] * sz[u];
}
