#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 7;
const int M = 26;
const int inf = (int)1e9 + 7;
const long long base = (long long)1e18;
const double pi = acos(-1);
const double ep = 1e-18;
long long d[N], L[N];
int f[N];
vector<pair<int, int> > adj[N];
pair<pair<int, int>, int> ed[N];
pair<int, int> bl;
int st[N];
int cur;
int n;
int sl1;
bool diff(int u, int v) {
  if (u > v) swap(u, v);
  return make_pair(u, v) != bl;
}
void DFS(int u, int last) {
  st[u] = cur;
  f[u] = 1;
  d[u] = 0;
  for (int j = 0; j < adj[u].size(); j++) {
    int v = adj[u][j].first;
    int c = adj[u][j].second;
    if (!diff(u, v)) continue;
    if (v != last) {
      DFS(v, u);
      d[u] += d[v] + (long long)f[v] * c;
      f[u] += f[v];
    }
  }
}
void reDFS(int u, int last) {
  int tol = (st[u] == 0) ? sl1 : n - sl1;
  for (int j = 0; j < adj[u].size(); j++) {
    int v = adj[u][j].first;
    int c = adj[u][j].second;
    if (!diff(u, v)) continue;
    if (v != last) {
      L[v] = L[u] + d[u] - d[v] - (long long)c * f[v] +
             (long long)c * (tol - f[v]);
      reDFS(v, u);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    if (u > v) swap(u, v);
    adj[u].push_back(make_pair(v, c));
    adj[v].push_back(make_pair(u, c));
    ed[i] = make_pair(make_pair(u, v), c);
  }
  long long ans = base;
  for (int i = 1; i < n; i++) {
    bl = ed[i].first;
    int u = ed[i].first.first;
    int v = ed[i].first.second;
    int c = ed[i].second;
    L[u] = L[v] = 0;
    cur = 0;
    DFS(u, 0);
    sl1 = f[u];
    reDFS(u, 0);
    cur = 1;
    DFS(v, 0);
    reDFS(v, 0);
    int ru = u, rv = v;
    long long tol = 0;
    for (int i = 1; i < n + 1; i++) {
      if (st[i] == 0) {
        if (d[i] + L[i] < d[ru] + L[ru]) ru = i;
      } else if (d[i] + L[i] < d[rv] + L[rv])
        rv = i;
      tol += d[i] + L[i];
    }
    tol /= 2;
    ans = min(ans, tol + (d[ru] + L[ru]) * f[v] + (d[rv] + L[rv]) * f[u] +
                       (long long)c * f[u] * f[v]);
  }
  cout << ans;
}
