#include <bits/stdc++.h>
using namespace std;
int n, numV;
vector<int> e[5010], c[5010];
int edge[5010][2];
long long father[5010], s[5010], size[5010], root[5010], upto[5010];
long long totalCost;
void calc(int u, int f) {
  int lim = e[u].size();
  s[u] = 1;
  for (int i = 0; i < lim; i++) {
    int v = e[u][i];
    if (v == f) continue;
    int cost = c[u][i];
    father[v] = u;
    calc(v, u);
    s[u] += s[v];
    totalCost += cost * s[v] * (n - s[v]);
  }
}
void dfs1(int u, int f) {
  int lim = e[u].size();
  size[u] = 1;
  for (int i = 0; i < lim; i++) {
    int v = e[u][i];
    if (v == f || v == -1) continue;
    int cost = c[u][i];
    dfs1(v, u);
    size[u] += size[v];
    root[u] += root[v] + cost * size[v];
  }
}
void dfs2(int u, int f) {
  int lim = e[u].size();
  for (int i = 0; i < lim; i++) {
    int v = e[u][i];
    if (v == f || v == -1) continue;
    int cost = c[u][i];
    upto[v] =
        upto[u] + root[u] - root[v] - cost * size[v] + cost * (numV - size[v]);
    dfs2(v, u);
  }
}
long long solveFor(int u, int v, long long totalCost) {
  for (int i = 0; i < e[u].size(); i++)
    if (e[u][i] == v) e[u][i] = -1;
  for (int i = 0; i < e[v].size(); i++)
    if (e[v][i] == u) e[v][i] = -1;
  if (father[v] == u)
    numV = n - s[v];
  else
    numV = s[u];
  memset(size, 0, sizeof(size));
  memset(root, 0, sizeof(root));
  memset(upto, 0, sizeof(upto));
  dfs1(u, -1);
  dfs2(u, -1);
  long long N1 = size[u];
  long long X1 = root[u];
  long long best1 = 1000000000LL * 1000000000LL;
  for (int i = 1; i <= n; i++)
    if (size[i] > 0) best1 = min(best1, upto[i] + root[i]);
  numV = n - numV;
  memset(size, 0, sizeof(size));
  memset(root, 0, sizeof(root));
  memset(upto, 0, sizeof(upto));
  dfs1(v, -1);
  dfs2(v, -1);
  long long N2 = size[v];
  long long X2 = root[v];
  long long best2 = 1000000000LL * 1000000000LL;
  for (int i = 1; i <= n; i++)
    if (size[i] > 0) best2 = min(best2, upto[i] + root[i]);
  totalCost -= X1 * N2 + X2 * N1;
  for (int i = 0; i < e[u].size(); i++)
    if (e[u][i] == -1) e[u][i] = v;
  for (int i = 0; i < e[v].size(); i++)
    if (e[v][i] == -1) e[v][i] = u;
  return totalCost + best1 * N2 + best2 * N1;
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, cost;
    cin >> u >> v >> cost;
    e[u].push_back(v);
    e[v].push_back(u);
    c[u].push_back(cost);
    c[v].push_back(cost);
    edge[i][0] = u;
    edge[i][1] = v;
  }
  calc(1, -1);
  long long ans = 1000000000LL * 1000000000LL;
  for (int i = 0; i < n - 1; i++)
    ans = min(ans, solveFor(edge[i][0], edge[i][1], totalCost));
  cout << ans << endl;
}
