#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
struct rib {
  int a, b, w;
};
rib a[5010];
vector<int> g[5010];
long long re[5010];
long long fr[5010];
long long col[5010];
long long a1, a2;
int p[5010];
int del;
int n;
void dfs(int v, int co) {
  col[v] = 1;
  fr[v] = 0;
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i] == del) continue;
    int to = v ^ a[g[v][i]].a ^ a[g[v][i]].b, len = a[g[v][i]].w;
    if (p[to] != 0) continue;
    p[to] = co;
    dfs(to, co);
    col[v] += col[to];
    fr[v] += fr[to] + col[to] * len;
  }
}
void dfs2(int v, int p, long long w, int sz, long long &z) {
  re[v] = fr[v] + w;
  z += re[v];
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i] == del) continue;
    int to = v ^ a[g[v][i]].a ^ a[g[v][i]].b, len = a[g[v][i]].w;
    if (to == p) continue;
    long long pl = fr[v] - fr[to] - col[to] * len;
    dfs2(to, v, w + pl + (sz - col[to]) * len, sz, z);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    rib z;
    cin >> z.a >> z.b >> z.w;
    z.a--;
    z.b--;
    a[i] = z;
    g[z.a].push_back(i);
    g[z.b].push_back(i);
  }
  long long ans = LLINF;
  for (int j = 0; j < n - 1; j++) {
    del = j;
    memset(p, 0, sizeof(p));
    int c1 = -1, c2 = -1;
    long long a1 = 0, a2 = 0, col1 = 0, col2 = 0;
    for (int i = 0; i < n; i++)
      if (!p[i]) {
        int co = 0;
        if (c1 == -1)
          c1 = i, co = 1;
        else
          c2 = i, co = 2;
        p[i] = co;
        dfs(i, co);
        if (co == 1)
          col1 = col[i];
        else
          col2 = col[i];
        if (co == 1)
          dfs2(i, -1, 0, col[i], a1);
        else
          dfs2(i, -1, 0, col[i], a2);
      }
    long long m1 = LLINF, m2 = LLINF;
    for (int i = 0; i < n; i++)
      if (p[i] == 1)
        m1 = min(m1, re[i]);
      else
        m2 = min(m2, re[i]);
    ans = min(ans,
              a1 / 2 + a2 / 2 + (m1)*col2 + (m2)*col1 + col1 * col2 * a[j].w);
  }
  cout << ans << "\n";
  return 0;
}
