#include <bits/stdc++.h>
using namespace std;
int wt[5001][5001];
long long int subdistmemo[10004];
long long int subnodes[10004];
long long int rdist[10005];
vector<vector<int> > v;
vector<pair<int, int> > e;
long long int numnodes(int edg) {
  if (subnodes[edg] != -1) return subnodes[edg];
  int i, cnode = e[edg].second;
  long long int ret = 0;
  for (i = 0; i < v[cnode].size(); i++) {
    if ((v[cnode][i] | 1) != (edg | 1)) ret += numnodes(v[cnode][i]);
  }
  return subnodes[edg] = ret + 1;
}
long long int rootdist(int rootedge) {
  int i, cnode = e[rootedge].second;
  if (rdist[rootedge] != -1) return rdist[rootedge];
  rdist[rootedge] = 0;
  for (i = 0; i < v[cnode].size(); i++) {
    if ((v[cnode][i] | 1) != (rootedge | 1))
      rdist[rootedge] += rootdist(v[cnode][i]) +
                         numnodes(v[cnode][i]) *
                             wt[e[v[cnode][i]].first][e[v[cnode][i]].second];
  }
  return rdist[rootedge];
}
long long int subtreedist(int rootedge) {
  if (subdistmemo[rootedge] != -1) return subdistmemo[rootedge];
  int cnode = e[rootedge].second, tnodes = numnodes(rootedge), i, j;
  long long int ret = 0;
  for (i = 0; i < v[cnode].size(); i++) {
    j = v[cnode][i];
    if ((j | 1) != (rootedge | 1))
      ret += subtreedist(j) +
             (rootdist(j) + wt[e[j].first][e[j].second] * numnodes(j)) *
                 (tnodes - numnodes(j));
  }
  return subdistmemo[rootedge] = ret;
}
long long int getmin(int cedge, int remedge, long long int pans,
                     long long int tnodes) {
  int cnode = e[cedge].second;
  long long int cans = pans;
  if (remedge != cedge) {
    cans -= numnodes(cedge) * wt[e[cedge].first][e[cedge].second];
    cans += (tnodes - numnodes(cedge)) * wt[e[cedge].first][e[cedge].second];
  }
  long long int ret = cans;
  int i;
  for (i = 0; i < v[cnode].size(); i++) {
    if ((cedge | 1) == (v[cnode][i] | 1) || (cedge | 1) == (v[cnode][i] | 1))
      continue;
    ret = min(ret, getmin(v[cnode][i], remedge, cans, tnodes));
  }
  return ret;
}
int main() {
  int x, y, z, n, i, j;
  memset(rdist, -1, sizeof(rdist));
  memset(subdistmemo, -1, sizeof(subdistmemo));
  memset(subnodes, -1, sizeof(subnodes));
  scanf("%d", &n);
  v.resize(n + 1);
  for (i = 1; i < n; i++) {
    cin >> x >> y >> z;
    wt[x][y] = wt[y][x] = z;
    e.push_back(make_pair(x, y));
    v[x].push_back((int)e.size() - 1);
    e.push_back(make_pair(y, x));
    v[y].push_back((int)e.size() - 1);
  }
  long long int bans = (1LL << 62);
  for (i = 0; i < e.size(); i += 2) {
    j = (i ^ 1);
    long long int minsum =
        getmin(i, i, rootdist(i), numnodes(i)) * numnodes(j) +
        getmin(j, j, rootdist(j), numnodes(j)) * numnodes(i);
    bans = min(bans, subtreedist(i) + subtreedist(j) +
                         (n - numnodes(i)) * numnodes(i) *
                             (wt[e[i].first][e[i].second]) +
                         minsum);
  }
  cout << bans << endl;
  return 0;
}
