#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
using namespace std;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-6;
const long long mod = 1000000007;
inline string getstr(string &s, long long l, long long r) {
  string ret = "";
  for (long long i = l; i <= r; i++) ret.push_back(s[i]);
  return ret;
}
long long modpow(long long x, long long y, long long md = mod) {
  if (y == 0) return 1;
  long long ret = modpow(x, y >> 1, md);
  ret = (long long)ret * ret % md;
  if (y & 1) ret = (long long)ret * x % md;
  return ret;
}
long long n, color[5005], sz[5005], par[5005], dep[5005];
vector<pair<long long, long long> > g[5005];
void dfs(long long x, long long p, long long d, long long col) {
  par[x] = p;
  sz[x] = 1;
  color[x] = col;
  dep[x] = d;
  for (long long i = 0; i < g[x].size(); i++) {
    long long to = g[x][i].first, co = g[x][i].second;
    if (to != p) {
      dfs(to, x, d + co, col);
      sz[x] += sz[to];
    }
  }
}
long long Min[2];
bool debug = false;
void dfs2(long long x, long long p, long long size_all, long long delta) {
  Min[color[x]] = min(Min[color[x]], delta);
  for (long long i = 0; i < g[x].size(); i++) {
    long long to = g[x][i].first, co = g[x][i].second;
    if (to != p) {
      dfs2(to, x, size_all, delta - (2 * sz[to] - size_all) * g[x][i].second);
    }
  }
}
long long solve(long long x, long long y, long long v) {
  dfs(x, y, 0, 1);
  dfs(y, x, 0, 0);
  long long ans = v * sz[x] * sz[y];
  for (long long i = 1; i <= n; i++)
    if (i != x && i != y) {
      ans +=
          (dep[i] - dep[par[i]]) * sz[i] * ((color[i] ? sz[x] : sz[y]) - sz[i]);
    }
  memset(Min, 0x3f3f3f3f3f3f3f3f, sizeof Min);
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    if (color[i] == 1) {
      sum += dep[i];
    }
  }
  dfs2(x, y, sz[x], sum);
  sum = 0;
  for (long long i = 1; i <= n; i++) {
    if (color[i] == 0) {
      sum += dep[i];
    }
  }
  dfs2(y, x, sz[y], sum);
  ans += Min[0] * sz[x] + Min[1] * sz[y];
  return ans;
}
signed main() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  long long ans = 1e18;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < g[i].size(); j++) {
      long long x = i, y = g[i][j].first;
      if (x < y) ans = min(ans, solve(x, y, g[i][j].second));
    }
  }
  cout << ans << endl;
  return 0;
}
