#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long in[5010], out[5010], sumv[5010];
int first[5010], son[5010];
struct edge {
  int next, from, to, v;
} e[5010 * 2];
int n, sz;
long long mind;
void dfs_in(int now, int fa) {
  int ee = first[now];
  in[now] = 0;
  son[now] = 1;
  while (ee != -1) {
    int u = e[ee].to;
    if (u != fa) {
      dfs_in(u, now);
      son[now] += son[u];
      in[now] += in[u] + (long long)e[ee].v * son[u];
    }
    ee = e[ee].next;
  }
}
void dfs_out(int now, int fa, int m) {
  int ee = first[now];
  long long sum = in[now];
  sumv[now] = 0;
  ee = first[now];
  while (ee != -1) {
    int u = e[ee].to;
    if (u != fa) {
      out[u] = out[now] + sum - (long long)e[ee].v * son[u] - in[u] +
               (long long)e[ee].v * (m - son[u]);
      dfs_out(u, now, m);
      sumv[now] += sumv[u];
      sumv[now] += (in[u] + (long long)e[ee].v * son[u]) *
                   (long long)(son[now] - son[u]);
    }
    ee = e[ee].next;
  }
  mind = (mind) < (out[now] + in[now]) ? (mind) : (out[now] + in[now]);
}
void newedge(int f, int t, int v) {
  e[sz].next = first[f];
  e[sz].v = v;
  e[sz].to = t;
  e[sz].from = f;
  first[f] = sz++;
}
int main() {
  scanf("%d", &n);
  sz = 0;
  memset(first, -1, sizeof first);
  for (int i = 1; i < n; ++i) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    newedge(x, y, w);
    newedge(y, x, w);
  }
  long long ans = INF;
  for (int i = 0; i < sz; i += 2) {
    int u = e[i].from, v = e[i].to;
    mind = INF;
    out[u] = 0;
    dfs_in(u, v);
    dfs_out(u, v, son[u]);
    long long temp = sumv[u] + mind * (n - son[u]);
    mind = INF;
    out[v] = 0;
    dfs_in(v, u);
    dfs_out(v, u, son[v]);
    temp += sumv[v] + mind * (n - son[v]);
    temp += 1LL * son[v] * (n - son[v]) * e[i].v;
    ans = (temp) < (ans) ? (temp) : (ans);
  }
  printf("%I64d\n", ans);
  return 0;
}
