#include <bits/stdc++.h>
using namespace std;
long long convertToNum(string s) {
  long long val = 0;
  for (int i = 0; i < (s.size()); i++) val = val * 10 + s[i] - '0';
  return val;
}
char bu[50];
string convertToString(int a) {
  sprintf(bu, "%d", a);
  return string(bu);
}
long long GCD(long long x, long long y) {
  if (!x) return y;
  if (!y) return x;
  if (x == y) return x;
  if (x < y)
    return GCD(x, y % x);
  else
    return GCD(x % y, y);
}
long long POW(long long x, long long y, long long Base) {
  if (!y) return 1;
  long long u = POW(x, y / 2, Base);
  u = (u * u) % Base;
  if (y & 1)
    return (u * x) % Base;
  else
    return u;
}
void extended_euclid(long long A, long long B, long long &x, long long &y) {
  if (A == 1 && B == 0) {
    x = 1;
    y = 0;
    return;
  }
  if (A < B)
    extended_euclid(B, A, y, x);
  else {
    long long xx, yy;
    extended_euclid(A % B, B, xx, yy);
    x = xx;
    y = yy - (A / B) * xx;
  }
}
int n;
vector<pair<int, int> > a[5006];
int x[5006], y[5006], z[5006];
long long f[5006], nChild[5006];
long long dp[5006];
void DFS_1(int u, int par) {
  f[u] = nChild[u] = 0;
  nChild[u] = 1;
  for (int i = 0; i < (a[u].size()); i++) {
    int v = a[u][i].first;
    if (v == par) continue;
    DFS_1(v, u);
    f[u] += f[v] + nChild[v] * a[u][i].second;
    nChild[u] += nChild[v];
  }
}
long long curMin;
void DFS_2(int u, int par, long long inherit, long long nVisitor) {
  curMin = min(curMin, f[u] + inherit);
  dp[u] = curMin;
  for (int i = 0; i < (a[u].size()); i++) {
    int v = a[u][i].first;
    if (v == par) continue;
    DFS_2(v, u,
          inherit + f[u] - f[v] - nChild[v] * a[u][i].second +
              (nVisitor + nChild[u] - nChild[v]) * a[u][i].second,
          nVisitor + nChild[u] - nChild[v]);
  }
}
long long sum, totalNode;
void DFS_3(int u, int par) {
  for (int i = 0; i < (a[u].size()); i++) {
    int v = a[u][i].first;
    if (v == par) continue;
    sum += nChild[v] * a[u][i].second * (totalNode - nChild[v]);
    DFS_3(v, u);
  }
}
void solve_subprob(int Root, int ParRoot, long long &minInter, long long &minGo,
                   long long &nC) {
  DFS_1(Root, ParRoot);
  curMin = 1000000000000000000LL;
  DFS_2(Root, ParRoot, 0, 0);
  minGo = curMin;
  totalNode = nChild[Root];
  sum = 0;
  DFS_3(Root, ParRoot);
  minInter = sum;
  nC = nChild[Root];
}
int main() {
  scanf("%d", &n);
  int u, v, cost;
  for (int i = (1); i <= (n - 1); i++) {
    scanf("%d%d%d", &u, &v, &cost);
    a[u].push_back(make_pair(v, cost));
    a[v].push_back(make_pair(u, cost));
    x[i] = u;
    y[i] = v;
    z[i] = cost;
  }
  long long res = 1000000000000000000;
  for (int i = (1); i <= (n - 1); i++) {
    long long minInterCost1 = 0, minGoCost1 = 0, nChild1 = 0, minInterCost2 = 0,
              minGoCost2 = 0, nChild2 = 0;
    solve_subprob(x[i], y[i], minInterCost1, minGoCost1, nChild1);
    solve_subprob(y[i], x[i], minInterCost2, minGoCost2, nChild2);
    res = min(res, minInterCost1 + minInterCost2 + minGoCost1 * nChild2 +
                       minGoCost2 * nChild1 + z[i] * nChild1 * nChild2);
  }
  cout << res << endl;
  return 0;
}
