#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
vector<int> adj[N];
int a[N], b[N], w[N];
bool ban[N];
long long totdist[N], sz[N];
void dfs(int root, int par) {
  int u, id;
  sz[root] = 1;
  totdist[root] = 0;
  for (int i = 0; i < adj[root].size(); ++i) {
    id = adj[root][i];
    u = a[id] ^ b[id] ^ root;
    if (u == par || ban[id]) continue;
    dfs(u, root);
    sz[root] += sz[u];
    totdist[root] += sz[u] * w[id] + totdist[u];
  }
}
long long dfs2(long long &R, int root, int par, long long td, long long tsz) {
  long long tot = totdist[root] + td;
  R += tot;
  long long ret = tot;
  long long add = 0, asz = 0;
  for (int i = 0; i < adj[root].size(); ++i) {
    int id = adj[root][i];
    int u = a[id] ^ b[id] ^ root;
    if (u == par || ban[id]) continue;
    add = add + sz[u] * w[id] + totdist[u];
    asz += sz[u];
  }
  ++asz;
  for (int i = 0; i < adj[root].size(); ++i) {
    int id = adj[root][i];
    int u = a[id] ^ b[id] ^ root;
    if (u == par || ban[id]) continue;
    add = add - sz[u] * w[id] - totdist[u];
    asz -= sz[u];
    ret = min(ret, dfs2(R, u, root, td + add + (tsz + asz) * w[id], tsz + asz));
    add = add + sz[u] * w[id] + totdist[u];
    asz += sz[u];
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d%d", &a[i], &b[i], &w[i]);
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  long long ret = 1e18, temp;
  for (int i = 0; i < n - 1; ++i) {
    ban[i] = 1;
    dfs(a[i], 0);
    dfs(b[i], 0);
    long long temp = 0;
    long long f = dfs2(temp, a[i], 0, 0, 0);
    long long s = dfs2(temp, b[i], 0, 0, 0);
    temp /= 2;
    long long asz = sz[a[i]], bsz = sz[b[i]];
    temp += (asz * bsz) * w[i];
    temp += s * asz + f * bsz;
    ret = min(ret, temp);
    ban[i] = 0;
  }
  cout << ret << endl;
}
