#include <bits/stdc++.h>
using namespace std;
int N, n, cont[5000];
long long total, extra, best;
vector<pair<int, int> > adj[5000];
long long dfs(int v, int p, long long dist) {
  long long ret = dist;
  cont[v] = 1;
  n++;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    long long w = adj[v][i].second;
    if (u != p) {
      ret += dfs(u, v, dist + w);
      cont[v] += cont[u];
    }
  }
  return ret;
}
void find(int v, int p, long long sum) {
  best = min(best, sum);
  total += sum;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    long long w = adj[v][i].second;
    if (u != p) find(u, v, sum + w * (n - 2 * cont[u]));
  }
}
void look_tree(int v, int p) {
  n = 0;
  best = dfs(v, p, 0);
  find(v, p, best);
  extra += best * (N - n);
}
int main() {
  int i, a[5000], b[5000];
  long long w[5000], ans = 1000000000000000000ll;
  cin >> N;
  for (i = 0; i < N - 1; i++) {
    cin >> a[i] >> b[i] >> w[i];
    a[i]--;
    b[i]--;
    adj[a[i]].push_back(pair<int, int>(b[i], w[i]));
    adj[b[i]].push_back(pair<int, int>(a[i], w[i]));
  }
  for (i = 0; i < N - 1; i++) {
    total = extra = 0;
    look_tree(a[i], b[i]);
    look_tree(b[i], a[i]);
    extra += w[i] * n * (N - n);
    ans = min(ans, total / 2 + extra);
  }
  cout << ans << endl;
  return 0;
}
