#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  long long val;
  edge(int a, long long b) : to(a), val(b) {}
  edge() {}
};
int n;
int fa[5005];
int disfa[5005];
int num[5005];
long long sum[5005];
vector<edge> g[5005];
void dfs_fa(int x) {
  int y;
  for (int i = 0; i < g[x].size(); ++i) {
    y = g[x][i].to;
    if (fa[y] == y && y != 0) {
      fa[y] = x;
      disfa[y] = g[x][i].val;
      dfs_fa(y);
    }
  }
}
void dfs_sum(int x, long long &Sum, long long val) {
  Sum += val, num[x] = 1;
  for (int i = 0; i < g[x].size(); ++i) {
    int y = g[x][i].to;
    if (fa[y] == x) {
      dfs_sum(y, Sum, val + g[x][i].val);
      num[x] += num[y];
    }
  }
}
void dfs_son(int x, int tot) {
  for (int i = 0; i < g[x].size(); ++i) {
    int y = g[x][i].to;
    if (fa[y] == x) {
      sum[y] = sum[x] + (tot - 2 * num[y]) * g[x][i].val;
      dfs_son(y, tot);
    }
  }
}
void get_min(int x, int &Min) {
  if (sum[Min] > sum[x]) Min = x;
  for (int i = 0; i < g[x].size(); ++i) {
    int y = g[x][i].to;
    if (fa[y] == x) get_min(y, Min);
  }
}
int main() {
  int u, v;
  long long w;
  long long ans = -1;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    fa[i] = i;
    scanf("%d%d%lld", &u, &v, &w);
    u--, v--;
    g[u].push_back(edge(v, w));
    g[v].push_back(edge(u, w));
  }
  fa[0] = disfa[0] = 0;
  dfs_fa(0);
  for (int i = 1; i < n; ++i) {
    int r = fa[i];
    fa[i] = i;
    dfs_sum(0, sum[0], 0), dfs_sum(i, sum[i], 0);
    dfs_son(0, num[0]), dfs_son(i, num[i]);
    int r1 = 0, r2 = i;
    get_min(0, r1), get_min(i, r2);
    long long sum1 = sum[r1], sum2 = sum[r2];
    long long M = (long long)disfa[i] * num[0] * num[i] +
                  (long long)num[0] * sum2 + (long long)num[i] * sum1;
    long long tmp = 0;
    for (int j = 0; j < n; ++j) tmp += sum[j];
    M += tmp / 2;
    if (ans == -1)
      ans = M;
    else
      ans = ans < M ? ans : M;
    memset(sum, 0, sizeof(sum));
    fa[i] = r;
  }
  cout << ans;
  return 0;
}
