#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 5000;
int n, fir[maxn + 10], tmpN;
int nedge, to[2 * maxn + 10], nex[2 * maxn + 10], dis[2 * maxn + 10];
bool no[2 * maxn + 10];
bool vis[maxn + 10];
long long ans, dp[maxn + 10], num[maxn + 10], allDis[maxn + 10];
int p[2];
inline void add_edge(int x, int y, int w) {
  to[nedge] = y;
  dis[nedge] = w;
  nex[nedge] = fir[x];
  fir[x] = nedge++;
}
void dfs(int x, int fa) {
  num[x] = 0;
  dp[x] = 0;
  for (int i = fir[x]; ~i; i = nex[i])
    if (!no[i]) {
      int y = to[i];
      if (y == fa) continue;
      int w = dis[i];
      vis[y] = 1;
      dfs(y, x);
      num[x] += num[y];
      dp[x] += dp[y] + (long long)num[y] * w;
    }
  num[x]++;
}
void update(int x, int k) {
  if (p[k] < 0 || allDis[x] < allDis[p[k]]) p[k] = x;
}
void dfs2(int x, int fa, int k) {
  for (int i = fir[x]; ~i; i = nex[i])
    if (!no[i]) {
      int y = to[i];
      if (y == fa) continue;
      int w = dis[i];
      allDis[y] =
          allDis[x] - (long long)w * num[y] + (long long)(tmpN - num[y]) * w;
      update(y, k);
      dfs2(y, x, k);
    }
}
void work(int w) {
  int cnt = 0, N[2];
  memset(vis, 0, (n + 1) * sizeof vis[0]);
  memset(p, -1, sizeof p);
  for (int(i) = 1; (i) <= (n); (i)++)
    if (!vis[i]) {
      vis[i] = 1;
      dfs(i, -1);
      N[cnt] = tmpN = num[i];
      allDis[i] = dp[i];
      update(i, cnt);
      dfs2(i, -1, cnt);
      cnt++;
    }
  long long ret =
      N[1] * (allDis[p[0]] + (long long)N[0] * w) + N[0] * allDis[p[1]];
  long long ret2 = 0;
  for (int(i) = 1; (i) <= (n); (i)++) ret2 += allDis[i];
  ret2 /= 2;
  ret += ret2;
  if (ans < 0 || ret < ans) ans = ret;
}
void solve() {
  ans = -1;
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    no[2 * i] = no[2 * i + 1] = 1;
    work(dis[2 * i]);
    no[2 * i] = no[2 * i + 1] = 0;
  }
  cout << ans << endl;
}
int main() {
  std::ios::sync_with_stdio(false);
  int x, y, w;
  while (cin >> n) {
    memset(fir, -1, (n + 1) * sizeof fir[0]);
    nedge = 0;
    for (int(i) = 0; (i) < (n - 1); (i)++) {
      cin >> x >> y >> w;
      add_edge(x, y, w);
      add_edge(y, x, w);
    }
    solve();
  }
  return 0;
}
