#include <bits/stdc++.h>
using namespace std;
long long Up[5005], Down[5005];
vector<pair<int, int> > a[5005];
int cnt[5005], n;
void DFS1(int u, int pre) {
  cnt[u] = 1;
  for (pair<int, int> p : a[u]) {
    if (p.first == pre) continue;
    DFS1(p.first, u);
    cnt[u] += cnt[p.first];
    Down[u] +=
        Down[p.first] + (long long)p.second * cnt[p.first] * (n - cnt[p.first]);
  }
}
void DFS2(int u, int pre, long long &Mi, int cou) {
  for (pair<int, int> p : a[u]) {
    if (p.first == pre) continue;
    Up[p.first] +=
        Up[u] + Down[u] - Down[p.first] -
        (long long)p.second * cnt[p.first] * (n - cnt[p.first]) +
        (long long)p.second * (cou - cnt[p.first]) * (n - cou + cnt[p.first]);
    DFS2(p.first, u, Mi, cou);
  }
  Mi = min(Mi, Up[u] + Down[u]);
}
long long Slove(int x, int y, int val) {
  for (int i = 1; i <= n; i++) Down[i] = Up[i] = 0;
  long long Mi1 = 1e18, Mi2 = 1e18;
  DFS1(x, y);
  DFS2(x, y, Mi1, cnt[x]);
  DFS1(y, x);
  DFS2(y, x, Mi2, cnt[y]);
  return Mi1 + Mi2 + (long long)val * cnt[x] * cnt[y];
}
int main() {
  cin >> n;
  int u, v, Val;
  for (int i = 1; i < n; i++) {
    cin >> u >> v >> Val;
    a[u].push_back(make_pair(v, Val));
    a[v].push_back(make_pair(u, Val));
  }
  long long ans = 1e18;
  for (int i = 1; i <= n; i++)
    for (pair<int, int> p : a[i]) {
      if (p.first < i) continue;
      ans = min(ans, Slove(i, p.first, p.second));
    }
  cout << ans;
}
