#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > e[5000];
int qfirst[5001];
int qnext[5000];
void run(int casenr) {
  scanf("%d", &n);
  for (int i = (0); i < (n - 1); ++i) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    --a;
    --b;
    e[a].push_back(make_pair(b, w));
    e[b].push_back(make_pair(a, w));
  }
  long long ret = LLONG_MAX;
  for (int i = (0); i < (n); ++i)
    for (int ii = (0); ii < (((int)(e[i]).size())); ++ii)
      if (e[i][ii].first > i) {
        int da = i, db = e[i][ii].first;
        vector<int> side(n, -1);
        side[da] = 0;
        side[db] = 1;
        queue<int> qq;
        qq.push(da);
        qq.push(db);
        while (!qq.empty()) {
          int at = qq.front();
          qq.pop();
          for (int j = (0); j < (((int)(e[at]).size())); ++j) {
            int to = e[at][j].first;
            if (side[to] == -1) {
              side[to] = side[at];
              qq.push(to);
            }
          }
        }
        vector<int> sidecnt(2, 0);
        for (int j = (0); j < (n); ++j) ++sidecnt[side[j]];
        long long cur = 0;
        vector<int> deg(n);
        for (int j = (0); j < (n); ++j) deg[j] = ((int)(e[j]).size());
        --deg[da];
        --deg[db];
        vector<int> size(n, 1);
        vector<bool> dead(n, false);
        vector<long long> sumdist(n, 0);
        memset(qfirst, -1, sizeof(qfirst));
        vector<vector<int> > q(n + 1);
        for (int j = (0); j < (n); ++j)
          if (deg[j] == 1) {
            qnext[j] = qfirst[size[j]];
            qfirst[size[j]] = j;
          }
        for (int qq = (0); qq <= (n); ++qq)
          for (int at = qfirst[qq]; at != -1; at = qnext[at]) {
            if (deg[at] != 1) continue;
            int cnt = 0;
            for (int j = (0); j < (((int)(e[at]).size())); ++j) {
              int to = e[at][j].first;
              if (at == da && to == db || at == db && to == da) continue;
              if (dead[to]) continue;
              sumdist[to] += sumdist[at] + size[at] * e[at][j].second;
              cur += (long long)size[at] * (sidecnt[side[at]] - size[at]) *
                     e[at][j].second;
              dead[at] = true;
              size[to] += size[at];
              if (--deg[to] == 1) {
                qnext[to] = qfirst[size[to]];
                qfirst[size[to]] = to;
              }
              ++cnt;
              break;
            }
            assert(cnt == 1);
          }
        vector<int> roots;
        for (int j = (0); j < (n); ++j)
          if (!dead[j]) {
            assert(deg[j] == 0);
            roots.push_back(j);
          }
        assert(((int)(roots).size()) == 2);
        long long ocur = cur;
        cur += sumdist[roots[0]] * size[roots[1]];
        cur += sumdist[roots[1]] * size[roots[0]];
        cur += (long long)size[roots[0]] * size[roots[1]] * e[i][ii].second;
        if (cur < ret) ret = cur;
      }
  cout << ret << endl;
}
int main() {
  run(1);
  return 0;
}
