#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const long long INF = 1e17;
vector<pair<int, long long> > adj[N];
int head[N], tail[N], ww[N], n;
int col[N], sz[N], fa[N];
long long dep[N], rad[2];
inline void dfs(int p, int v, int c, long long d) {
  fa[v] = p;
  col[v] = c;
  dep[v] = d;
  sz[v] = 1;
  for (pair<int, long long> to : adj[v])
    if (to.first != p) {
      dfs(v, to.first, c, d + to.second);
      sz[v] += sz[to.first];
    }
}
inline void dfs2(int p, int v, int c, int cnt, long long sum) {
  rad[c] = min(rad[c], sum);
  for (pair<int, long long> to : adj[v])
    if (to.first != p)
      dfs2(v, to.first, c, cnt,
           sum - 1LL * (2 * sz[to.first] - cnt) * to.second);
}
inline long long solve(int edge) {
  int a = head[edge], b = tail[edge];
  long long cost = ww[edge];
  dfs(b, a, 0, 0);
  dfs(a, b, 1, 0);
  long long res = cost * sz[a] * sz[b], cur;
  for (int i = 1; i <= n; i++)
    if (i != a && i != b) {
      cur = dep[i] - dep[fa[i]];
      res += cur * sz[i] * ((col[i] ? sz[b] : sz[a]) - sz[i]);
    }
  rad[0] = rad[1] = INF;
  long long tmp;
  for (int c = 0; c < 2; c++) {
    tmp = 0;
    for (int j = 1; j <= n; j++)
      if (col[j] == c) tmp += dep[j];
    if (c == 0)
      dfs2(b, a, 0, sz[a], tmp);
    else
      dfs2(a, b, 1, sz[b], tmp);
  }
  res += rad[0] * sz[b];
  res += rad[1] * sz[a];
  return res;
}
int main() {
  scanf("%d", &n);
  int a, b, w;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &a, &b, &w);
    adj[head[i] = a].push_back(pair<int, long long>(b, w));
    adj[tail[i] = b].push_back(pair<int, long long>(a, w));
    ww[i] = w;
  }
  long long ans = INF;
  for (int i = 1; i < n; i++) ans = min(ans, solve(i));
  printf("%I64d\n", ans);
  return 0;
}
