#include <bits/stdc++.h>
using namespace std;
long n, a[20000], b[20000], c[20000];
long long arp[20000], dsum[20000], upsum[20000], subsize[20000];
vector<pair<long, long> > g[7000];
long csize;
long long ans, minsum, minsum1;
long long tans;
long tresize;
void dfs1(long v) {
  arp[v] = 1;
  subsize[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    long ver = g[v][i].first;
    long cost = g[v][i].second;
    if (arp[ver]) continue;
    dfs1(ver);
    subsize[v] += subsize[ver];
    dsum[v] += dsum[ver];
    dsum[v] += subsize[ver] * cost;
  }
}
void dfs2(long v) {
  arp[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    long ver = g[v][i].first;
    long cost = g[v][i].second;
    if (arp[ver]) continue;
    upsum[ver] = upsum[v];
    upsum[ver] += dsum[v] - dsum[ver] - subsize[ver] * cost;
    upsum[ver] += (tresize - subsize[ver]) * cost;
    dfs2(ver);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  ans = 1000000000;
  ans *= ans;
  ans *= 3;
  for (int i = 1; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int cedge = 1; cedge < n; cedge++) {
    for (int i = 1; i <= n; i++) g[i].clear();
    for (int i = 1; i < n; i++)
      if (i != cedge) {
        g[a[i]].push_back(make_pair(b[i], c[i]));
        g[b[i]].push_back(make_pair(a[i], c[i]));
      }
    for (int i = 1; i <= n; i++) arp[i] = dsum[i] = upsum[i] = subsize[i] = 0;
    dfs1(a[cedge]);
    csize = 0;
    for (int i = 1; i <= n; i++) {
      csize += arp[i];
      arp[i] = 0;
    }
    tresize = csize;
    dfs2(a[cedge]);
    minsum = 1000000000000000000ll;
    for (int i = 1; i <= n; i++)
      if (arp[i] == 1) minsum = min(minsum, dsum[i] + upsum[i]);
    for (int i = 1; i <= n; i++) arp[i] = 0;
    tresize = n - tresize;
    dfs1(b[cedge]);
    for (int i = 1; i <= n; i++) arp[i] = 0;
    dfs2(b[cedge]);
    minsum1 = 1000000000000000000ll;
    for (int i = 1; i <= n; i++)
      if (arp[i] == 1) minsum1 = min(minsum1, dsum[i] + upsum[i]);
    for (int i = 1; i <= n; i++) arp[i] = 0;
    tans = 0;
    for (int i = 1; i <= n; i++) tans += dsum[i] + upsum[i];
    tans /= 2;
    tans += minsum * (n - csize) + minsum1 * csize +
            1ll * csize * (n - csize) * c[cedge];
    ans = min(ans, tans);
  }
  cout << ans << endl;
  cin.get();
  cin.get();
  return 0;
}
