#include <bits/stdc++.h>
const int NS = 5010;
const int INF = 1000000007;
const long long MAX = (long long)1 << 62;
struct gragh {
  int to, w, next;
} e[NS << 1];
struct Edge {
  int u, v, w, nl, nr;
} p[NS];
long long pl, pr, res, ans;
int n, a, b, c, nl, nr, top;
long long pth[5], s[5];
int head[NS], h[5], vex[5];
void add(int parent, int son, int value) {
  e[top].next = head[parent];
  e[top].to = son, e[top].w = value;
  head[parent] = top++;
}
int Max(int a1, int a2) { return a1 > a2 ? a1 : a2; }
long long Min(long long a1, long long a2) { return a1 < a2 ? a1 : a2; }
int dfs_LRN(int rt, int fa) {
  int sum = 1, t, to, pos;
  for (int i = head[rt]; i != -1; i = e[i].next) {
    pos = i >> 1;
    to = e[i].to;
    if (to != fa) {
      t = dfs_LRN(to, rt);
      sum += t;
      if (p[pos].u != to) t = n - t;
      p[pos].nl = t, p[pos].nr = n - t;
    }
  }
  return sum;
}
int dfs_pair(int rt, int fa, int g, int f) {
  int to, t, n1, n2, sum = 1, maxs = 0;
  for (int i = head[rt]; i != -1; i = e[i].next) {
    to = e[i].to;
    if (to != fa) {
      t = dfs_pair(to, rt, g, f);
      maxs = Max(maxs, t);
      sum += t;
      n1 = t, n2 = g - t;
      pth[f] += (long long)n1 * n2 * e[i].w;
    }
  }
  maxs = Max(maxs, g - sum);
  if (maxs < vex[f]) vex[f] = maxs, h[f] = rt;
  return sum;
}
int dfs_path(int rt, int fa, int g, int f) {
  int t, to, sum = 1;
  for (int i = head[rt]; i != -1; i = e[i].next) {
    to = e[i].to;
    if (to != fa && to != g) {
      t = dfs_path(to, rt, g, f);
      s[f] += (long long)t * e[i].w;
      sum += t;
    }
  }
  return sum;
}
int main() {
  while (~scanf("%d", &n)) {
    top = 0, res = MAX;
    memset(head, -1, sizeof(head));
    for (int i = 0; i < n - 1; i++) {
      scanf("%d%d%d", &a, &b, &c);
      add(a, b, c), add(b, a, c);
      p[i].u = a, p[i].v = b, p[i].w = c;
    }
    dfs_LRN(1, -1);
    for (int i = 0; i < n - 1; i++) {
      a = p[i].u, b = p[i].v, c = p[i].w;
      nl = p[i].nl, nr = p[i].nr;
      vex[1] = vex[2] = INF;
      s[1] = s[2] = pth[1] = pth[2] = 0;
      dfs_pair(a, b, nl, 1);
      dfs_pair(b, a, nr, 2);
      dfs_path(h[1], -1, b, 1);
      dfs_path(h[2], -1, a, 2);
      ans = pth[1] + pth[2] + (long long)nl * nr * c + s[1] * nr + s[2] * nl;
      res = Min(res, ans);
    }
    printf("%I64d\n", res);
  }
  return 0;
}
