#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
const long long inf = 1ll << 60;
vector<pair<int, int> > V[N];
long long res, num[N], dp[N], sum_root, ans, Size_node;
void dfs1(int u, int pre) {
  num[u] = 1;
  dp[u] = 0;
  int len = V[u].size();
  for (int i = 0; i < len; i++) {
    int v = V[u][i].first;
    if (v == pre) continue;
    dfs1(v, u);
    num[u] += num[v];
    long long w = V[u][i].second;
    dp[u] += dp[v] + num[v] * w;
  }
}
void dfs2(int u, int pre) {
  sum_root += dp[u];
  res = min(res, dp[u]);
  int len = V[u].size();
  for (int i = 0; i < len; i++) {
    int v = V[u][i].first;
    if (v == pre) continue;
    long long w = V[u][i].second;
    dp[v] = dp[u] + (Size_node - num[v]) * w - w * num[v];
    dfs2(v, u);
  }
}
void Work(int u, int pre) {
  int len = V[u].size();
  for (int i = 0; i < len; i++) {
    int v = V[u][i].first;
    if (v == pre) continue;
    long long w = V[u][i].second;
    long long C1, R1, S1, C2, R2, S2;
    dfs1(v, u);
    Size_node = C1 = num[v];
    sum_root = 0;
    res = inf;
    dfs2(v, u);
    S1 = sum_root / 2;
    R1 = res;
    dfs1(u, v);
    Size_node = C2 = num[u];
    sum_root = 0;
    res = inf;
    dfs2(u, v);
    S2 = sum_root / 2;
    R2 = res;
    long long t = S1 + S2 + C1 * w * C2 + C2 * R1 + C1 * R2;
    ans = min(ans, t);
    Work(v, u);
  }
}
int main() {
  int n, i;
  while (~scanf("%d", &n)) {
    for (i = 1; i <= n; i++) V[i].clear();
    for (i = 1; i < n; i++) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      V[u].push_back(make_pair(v, w));
      V[v].push_back(make_pair(u, w));
    }
    ans = inf;
    Work(1, 0);
    printf("%I64d\n", ans);
  }
  return 0;
}
