#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > G[5500];
long long weight[5500];
pair<int, int> edges[5500];
bool vis[5002];
bool cut[5002][5002];
int child[5500];
long long dsum[5500];
int n, total;
long long S, minD;
int dfs(int I, long long w) {
  S += w;
  int s = 0;
  vis[I] = true;
  int sz = G[I].size();
  for (int i = 0; i < sz; i++) {
    int v = G[I][i].first;
    long long wt = G[I][i].second;
    if (!vis[v] && !cut[I][v]) s += dfs(v, w + wt);
  }
  child[I] = s;
  return s + 1;
}
void propagate(int I, long long d) {
  dsum[I] = d;
  minD = min(minD, d);
  int sz = G[I].size();
  for (int i = 0; i < sz; i++) {
    int v = G[I][i].first;
    long long wt = G[I][i].second;
    long long n1 = child[v];
    long long n2 = total - n1 - 2;
    long long k = d - n1 * wt + n2 * wt;
    if (dsum[v] == 0 && !cut[I][v]) propagate(v, k);
  }
}
int main() {
  int x, y, w;
  memset(cut, 0, sizeof cut);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y >> w;
    G[x].push_back(pair<int, int>(y, w));
    G[y].push_back(pair<int, int>(x, w));
    edges[i] = pair<int, int>(x, y);
    weight[i] = w;
  }
  long long final = 1000000009;
  final *= final;
  for (int i = 0; i < n - 1; i++) {
    x = edges[i].first;
    y = edges[i].second;
    cut[x][y] = cut[y][x] = 1;
    memset(vis, 0, sizeof vis);
    memset(dsum, 0, sizeof dsum);
    S = 0;
    total = dfs(x, 0);
    long long N1 = total;
    minD = S;
    propagate(x, S);
    long long d1 = minD;
    S = 0;
    total = dfs(y, 0);
    long long N2 = total;
    minD = S;
    propagate(y, S);
    long long d2 = minD;
    long long ans = 0;
    for (int j = 1; j <= n; j++) ans += dsum[j];
    ans = ans / 2;
    ans += N1 * N2 * weight[i] + N1 * d2 + N2 * d1;
    final = min(final, ans);
    cut[x][y] = cut[y][x] = 0;
  }
  cout << final << endl;
  return 0;
}
