#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
vector<pair<int, int> > a[N];
long long s[N], c[N], sv[N], ss[N], ssum[N];
int u[N], ucs, fx, fy;
void go(int x, int from = -1) {
  u[x] = ucs;
  c[x] = 1;
  s[x] = 0;
  for (__typeof((a[x]).begin()) it = (a[x]).begin(); it != (a[x]).end(); it++) {
    if (it->first != from) {
      if (min(x, it->first) == fx && max(x, it->first) == fy) continue;
      go(it->first, x);
      c[x] += c[it->first];
      s[x] += (it->second) * c[it->first] + s[it->first];
    }
  }
}
long long ans = (1LL << 60);
void go2(int x, int from = -1, long long S = 0, long long C = 0) {
  u[x] = ucs;
  s[x] += S;
  sv[x] = s[x];
  ss[x] = s[x];
  for (__typeof((a[x]).begin()) it = (a[x]).begin(); it != (a[x]).end(); it++) {
    if (it->first != from) {
      if (min(x, it->first) == fx && max(x, it->first) == fy) continue;
      go2(it->first, x,
          s[x] - s[it->first] - (it->second) * (c[it->first]) +
              (it->second) * (C + c[x] - c[it->first]),
          C + c[x] - c[it->first]);
      sv[x] = min(sv[x], sv[it->first]);
      ss[x] += ss[it->first];
    }
  }
}
int e[N][3];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    if (x > y) swap(x, y);
    a[x].push_back(make_pair(y, w));
    a[y].push_back(make_pair(x, w));
    e[i][0] = x;
    e[i][1] = y;
    e[i][2] = w;
  }
  for (int i = 1; i < n; i++) {
    fx = e[i][0];
    fy = e[i][1];
    int h[2] = {}, hn = 0;
    ++ucs;
    for (int x = 1; x <= n; x++)
      if (u[x] != ucs) {
        h[hn++] = x;
        go(x);
      }
    go2(h[0]);
    go2(h[1]);
    long long R = c[h[1]] * sv[h[0]] + e[i][2] * c[h[0]] * c[h[1]] +
                  c[h[0]] * sv[h[1]] + ss[h[0]] / 2 + ss[h[1]] / 2;
    ans = min(ans, R);
  }
  printf("%I64d\n", ans);
  return 0;
}
