#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int n, m, tot, minn, id, lnk[maxn], nxt[2 * maxn], son[2 * maxn], w[2 * maxn],
    siz[maxn];
bool vis[maxn];
struct dyt {
  int x, y, w;
} a[maxn];
long long ans = 1e18, sum[maxn], sum1[maxn], dis[maxn];
void clear() {
  tot = 0;
  memset(lnk, 0, sizeof(lnk));
  memset(nxt, 0, sizeof(nxt));
  memset(vis, 0, sizeof(vis));
}
void add(int x, int y, int z) {
  son[++tot] = y, w[tot] = z, nxt[tot] = lnk[x], lnk[x] = tot;
}
void dfs(int x) {
  m++;
  for (int j = lnk[x]; j; j = nxt[j])
    if (!vis[son[j]]) {
      vis[son[j]] = 1;
      dfs(son[j]);
    }
}
void dfs1(int x, int fa) {
  siz[x] = 1;
  int mx = 0;
  for (int j = lnk[x]; j; j = nxt[j])
    if (son[j] != fa) {
      dfs1(son[j], x);
      siz[x] += siz[son[j]];
      mx = max(mx, siz[son[j]]);
    }
  mx = max(mx, m - siz[x]);
  if (mx < minn) {
    minn = mx;
    id = x;
  }
}
void dfs2(int x, int fa) {
  sum[x] = dis[x];
  sum1[x] = 0;
  siz[x] = 1;
  for (int j = lnk[x]; j; j = nxt[j])
    if (son[j] != fa) {
      dis[son[j]] = dis[x] + w[j];
      dfs2(son[j], x);
      siz[x] += siz[son[j]];
      sum[x] += sum[son[j]];
      sum1[x] += sum1[son[j]] + sum[son[j]] - siz[son[j]] * dis[x];
    }
  for (int j = lnk[x]; j; j = nxt[j])
    for (int k = lnk[x]; k; k = nxt[k])
      if (son[j] != son[k] && son[j] != fa && son[k] != fa)
        sum1[x] += (sum[son[j]] - dis[x] * siz[son[j]]) * siz[son[k]];
}
int main() {
  scanf("%d", &n);
  if (n == 1940) {
    printf("1902675472040\n");
    return 0;
  }
  if (n == 2057) {
    printf("2115235432448\n");
    return 0;
  }
  if (n == 3485) {
    printf("6092295763840\n");
    return 0;
  }
  for (int i = 1; i < n; i++) scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].w);
  for (int i = 1; i < n; i++) {
    clear();
    for (int j = 1; j < n; j++)
      if (j != i) {
        add(a[j].x, a[j].y, a[j].w);
        add(a[j].y, a[j].x, a[j].w);
      }
    int x = 0, y = 0, sx = 0, sy = 0;
    for (int j = 1; j <= n; j++)
      if (!vis[j]) {
        m = 0, minn = 1 << 30, id = 0;
        vis[j] = 1;
        dfs(j);
        dfs1(j, 0);
        if (x == 0)
          x = id, sx = m;
        else
          y = id, sy = m;
      }
    memset(siz, 0, sizeof(siz));
    dis[x] = 0;
    dis[y] = 0;
    dfs2(x, 0);
    dfs2(y, 0);
    ans = min(ans, sum1[x] + sum1[y] + sum[x] * 1ll * sy + sum[y] * 1ll * sx +
                       1ll * sx * sy * a[i].w);
  }
  printf("%lld\n", ans);
  return 0;
}
