#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
const long long INF = (1LL << 60);
vector<pair<int, long long> > graph[N];
int color[N], sz[N], parent[N], n, a, b, w;
long long depth[N], rad[2];
void dfs1(int u, int p, int c, long long d) {
  color[u] = c;
  parent[u] = p;
  depth[u] = d;
  sz[u] = 1;
  for (pair<int, long long> it : graph[u]) {
    int v = it.first;
    if (v != p) {
      dfs1(v, u, c, d + it.second);
      sz[u] += sz[v];
    }
  }
}
void dfs2(int u, int p, int c, int cnt, long long sum) {
  rad[c] = min(rad[c], sum);
  for (pair<int, long long> it : graph[u]) {
    int v = it.first;
    if (v != p) dfs2(v, u, c, cnt, sum - (2 * sz[v] - cnt) * it.second);
  }
}
long long solve(int a, int b, long long abCost) {
  dfs1(a, b, 0, 0);
  dfs1(b, a, 1, 0);
  long long ans = abCost * sz[a] * sz[b];
  for (int i = 0; i < n; i++) {
    if (i != a && i != b) {
      long long cost = depth[i] - depth[parent[i]];
      ans += cost * sz[i] * (((color[i] == 0) ? sz[a] : sz[b]) - sz[i]);
    }
  }
  rad[0] = rad[1] = INF;
  for (int i = 0; i < 2; i++) {
    long long tmp = 0;
    for (int j = 0; j < n; j++)
      if (color[j] == i) tmp += depth[j];
    if (i == 0)
      dfs2(a, b, 0, sz[a], tmp);
    else
      dfs2(b, a, 1, sz[b], tmp);
  }
  ans += rad[0] * sz[b];
  ans += rad[1] * sz[a];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b >> w;
    a--;
    b--;
    graph[a].push_back(pair<int, long long>(b, w));
    graph[b].push_back(pair<int, long long>(a, w));
  }
  long long ans = INF;
  for (int i = 0; i < n; i++) {
    for (pair<int, long long> j : graph[i]) {
      a = i;
      b = j.first;
      if (a < b) ans = min(ans, solve(a, b, j.second));
    }
  }
  cout << ans << "\n";
  return 0;
}
