#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
int n;
vector<int> child[5010];
vector<int> Len[5010];
int u1, u2;
bool F[5010];
int dp_cnt[5010];
unsigned long long sum_of_all;
long long best_delta;
long long best_delta_ever;
void dfs1(int v) {
  F[v] = true;
  dp_cnt[v] = 1;
  for (int a = (0); a <= ((int)((child[v]).size()) - 1); a++)
    if (child[v][a] != u1 && child[v][a] != u2 && !F[child[v][a]]) {
      dfs1(child[v][a]);
      dp_cnt[v] += dp_cnt[child[v][a]];
    }
}
void dfs2(int v, unsigned long long dlen, int cnt, long long delta) {
  F[v] = true;
  best_delta = min(delta, best_delta);
  for (int a = (0); a <= ((int)((child[v]).size()) - 1); a++)
    if (!F[child[v][a]])
      dfs2(child[v][a], dlen + Len[v][a], cnt + dp_cnt[v] - dp_cnt[child[v][a]],
           delta + (long long)(cnt + dp_cnt[v] - 2 * dp_cnt[child[v][a]]) *
                       Len[v][a]);
}
void sol() {
  for (int a = (1); a <= (n); a++)
    for (int b = (0); b <= ((int)((child[a]).size()) - 1); b++)
      if (a < child[a][b]) {
        u1 = a;
        u2 = child[a][b];
        memset(F, 0, sizeof(F));
        dfs1(u1);
        dfs1(u2);
        sum_of_all += (unsigned long long)dp_cnt[u1] *
                      (unsigned long long)dp_cnt[u2] *
                      (unsigned long long)Len[a][b];
        memset(F, 0, sizeof(F));
        best_delta = 0;
        F[u2] = true;
        dfs2(u1, 0, 0, 0);
        long long b1 = best_delta;
        memset(F, 0, sizeof(F));
        best_delta = 0;
        F[u1] = true;
        dfs2(u2, 0, 0, 0);
        long long b2 = best_delta;
        if (best_delta_ever > b1 * dp_cnt[u2] + b2 * dp_cnt[u1])
          best_delta_ever = b1 * dp_cnt[u2] + b2 * dp_cnt[u1];
      }
  cout << sum_of_all + best_delta_ever << "\n";
}
int main() {
  scanf("%d", &n);
  for (int a = (1); a <= (n - 1); a++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    child[x].push_back(y);
    Len[x].push_back(z);
    child[y].push_back(x);
    Len[y].push_back(z);
  }
  sol();
  return 0;
}
