#include <bits/stdc++.h>
using namespace std;
vector<int> a[5005], w[5005];
int n;
long long ans = 1000000000000000000LL;
long long best[2], pairwise[2];
long long tot[2];
int siz[5005];
long long downdis[5005], totdis[5005];
void dfs(int u, int pre) {
  downdis[u] = 0;
  siz[u] = 1;
  for (int i = 0; i < a[u].size(); i++) {
    int v = a[u][i];
    int d = w[u][i];
    if (v == pre) continue;
    dfs(v, u);
    downdis[u] += downdis[v] + (long long)d * siz[v];
    siz[u] += siz[v];
  }
}
void visit(int u, int pre, int id) {
  for (int i = 0; i < a[u].size(); i++) {
    int v = a[u][i];
    int d = w[u][i];
    if (v == pre) continue;
    pairwise[id] += (long long)d * siz[v] * (tot[id] - siz[v]);
    totdis[v] = totdis[u] + (long long)d * (tot[id] - siz[v] - siz[v]);
    best[id] = min(best[id], totdis[v]);
    visit(v, u, id);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, l;
    cin >> u >> v >> l;
    u--, v--;
    a[u].push_back(v);
    a[v].push_back(u);
    w[u].push_back(l);
    w[v].push_back(l);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i].size(); j++) {
      int v = a[i][j];
      if (i > v) continue;
      dfs(i, v);
      dfs(v, i);
      totdis[i] = downdis[i];
      best[0] = totdis[i];
      tot[0] = siz[i];
      totdis[v] = downdis[v];
      best[1] = totdis[v];
      tot[1] = siz[v];
      pairwise[0] = pairwise[1] = 0;
      visit(i, v, 0);
      visit(v, i, 1);
      ans =
          min(ans, pairwise[0] + pairwise[1] + best[0] * siz[v] +
                       best[1] * siz[i] + (long long)w[i][j] * siz[i] * siz[v]);
    }
  }
  cout << ans << endl;
  return 0;
}
