#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5555;
vector<pair<long long, long long> > adj[MAXN];
vector<long long> ver;
long long dp[MAXN], dw[MAXN];
bool mark[MAXN];
long long n;
void dfs2(long long v, long long p = -1) {
  for (auto e : adj[v])
    if (!mark[e.first] && e.first != p) {
      dp[e.first] = dp[v] + (ver.size() - 2 * dw[e.first]) * e.second;
      dfs2(e.first, v);
    }
}
pair<long long, long long> dfs1(long long v, long long p = -1) {
  if (p == -1) ver.clear();
  ver.push_back(v);
  long long sum = 0, cnt = 1;
  for (auto e : adj[v])
    if (!mark[e.first] && e.first != p) {
      pair<long long, long long> nw = dfs1(e.first, v);
      sum += nw.first + nw.second * e.second;
      cnt += nw.second;
    }
  dp[v] = sum;
  dw[v] = cnt;
  if (p == -1) dfs2(v);
  return {sum, cnt};
}
int32_t main() {
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    adj[--v].push_back({--u, w});
    adj[u].push_back({v, w});
  }
  long long ans = 1ll << 60;
  for (long long v = 0; v < n; v++) {
    for (auto uw : adj[v]) {
      long long u = uw.first;
      long long w = uw.second;
      mark[u] = mark[v] = true;
      dfs1(v);
      long long num1 = ver.size(), sum1 = 0, mn1 = 1ll << 60;
      for (long long i : ver) {
        sum1 += dp[i];
        mn1 = min(mn1, dp[i]);
      }
      dfs1(u);
      long long num2 = ver.size(), sum2 = 0, mn2 = 1ll << 60;
      for (long long i : ver) {
        sum2 += dp[i];
        mn2 = min(mn2, dp[i]);
      }
      mark[u] = mark[v] = false;
      long long res =
          num1 * num2 * w + mn1 * num2 + mn2 * num1 + sum1 / 2 + sum2 / 2;
      ans = min(ans, res);
    }
  }
  cout << ans << endl;
}
