#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
const long long INF = 1e18 + 7;
int n, sz[N];
long long dpup[N], dpdown[N];
vector<pair<int, int> > adj[N];
void downdfs(int u, int par) {
  sz[u] = 1;
  for (auto p : adj[u])
    if (p.first != par) {
      downdfs(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 updfs(int v, int par, long long &m, int a) {
  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 * (a - sz[p.first]) * (n - a + sz[p.first]);
      updfs(p.first, v, m, a);
    }
  m = min(m, dpup[v] + dpdown[v]);
}
long long solve(int v, int u, int w) {
  for (int i = 1; i <= n; i++) dpdown[i] = dpup[i] = 0;
  long long MIN1 = INF, MIN2 = INF;
  downdfs(v, u);
  updfs(v, u, MIN1, sz[v]);
  downdfs(u, v);
  updfs(u, v, MIN2, sz[u]);
  return MIN1 + MIN2 + (long long)w * sz[v] * sz[u];
}
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(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  long long ans = INF;
  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;
}
