#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
int lab[5010];
long long ans[5010];
long long intree[5010];
int sz[5010];
int h[5010];
long long min1[2];
void dfs1(int v, int p) {
  sz[v] = 1;
  intree[v] = ans[v] = 0;
  for (int i = (0); i < (g[v].size()); ++i) {
    int to = g[v][i].first;
    if (to == p) continue;
    dfs1(to, v);
    sz[v] += sz[to];
    intree[v] += intree[to] + g[v][i].second * 1ll * sz[to];
  }
}
void dfs2(int v, int p, int root, int how) {
  h[v] = how;
  if (v == root) {
    ans[v] = intree[v];
    min1[how] = ((min1[how] < ans[v]) ? (min1[how]) : (ans[v]));
  }
  for (int i = (0); i < (g[v].size()); ++i) {
    int to = g[v][i].first;
    if (to == p) continue;
    ans[to] =
        intree[to] + (ans[v] - intree[to] - g[v][i].second * 1ll * sz[to] +
                      g[v][i].second * 1ll * (sz[root] - sz[to]));
    min1[how] = ((min1[how] < ans[to]) ? (min1[how]) : (ans[to]));
    dfs2(to, v, root, how);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  g.resize(n);
  for (int i = (0); i < (n - 1); ++i) {
    int v1, v2, w;
    scanf("%d%d%d", &v1, &v2, &w);
    v1--;
    v2--;
    g[v1].push_back(make_pair(v2, w));
    g[v2].push_back(make_pair(v1, w));
  }
  long long res = 1000000000000000000ll;
  for (int i = (0); i < (n); ++i) {
    int v1 = i;
    for (int j = (0); j < (g[i].size()); ++j) {
      int v2 = g[i][j].first;
      if (v1 > v2) continue;
      int w = g[i][j].second;
      min1[0] = min1[1] = 1000000000000000000ll;
      dfs1(v1, v2);
      dfs1(v2, v1);
      dfs2(v1, v2, v1, 0);
      dfs2(v2, v1, v2, 1);
      long long sum = 0;
      for (int k = (0); k < (n); ++k) sum += ans[k];
      res = ((res < sum / 2 + min1[0] * 1ll * sz[v2] + min1[1] * 1ll * sz[v1] +
                        sz[v1] * 1ll * w * sz[v2])
                 ? (res)
                 : (sum / 2 + min1[0] * 1ll * sz[v2] + min1[1] * 1ll * sz[v1] +
                    sz[v1] * 1ll * w * sz[v2]));
    }
  }
  cout << res << endl;
  return 0;
}
