#include <bits/stdc++.h>
using namespace std;
const int M = 5000 + 5;
struct EDGE {
  int u;
  int v;
  long long int d;
} edge[M];
vector<EDGE> adj[M];
int childnum[M];
long long int dis[M];
int flag[M];
void dfs(int cur, int par, int rem, int f) {
  flag[cur] = f;
  for (int i = 0; i < adj[cur].size(); i++) {
    int u = adj[cur][i].u;
    int v = adj[cur][i].v;
    long long int d = adj[cur][i].d;
    int nxt = u;
    if (nxt == cur) {
      nxt = v;
    }
    if (nxt != par && nxt != rem) {
      dfs(nxt, cur, rem, f);
      childnum[cur] = childnum[cur] + childnum[nxt];
      dis[cur] = dis[cur] + dis[nxt] + d * childnum[nxt];
    }
  }
  childnum[cur] += 1;
}
int parnum[M];
long long int dis2[M];
void dfs2(int cur, int par, int rem, long long int d) {
  int n1 = childnum[par] - childnum[cur];
  int n2 = parnum[par];
  long long int s1 = dis[par] - dis[cur] - d * childnum[cur];
  long long int s2 = dis2[par];
  parnum[cur] = n1 + n2;
  dis2[cur] = s2 + s1 + d * (n1 + n2);
  for (int i = 0; i < adj[cur].size(); i++) {
    int u = adj[cur][i].u;
    int v = adj[cur][i].v;
    long long int nxtd = adj[cur][i].d;
    int nxt = u;
    if (nxt == cur) {
      nxt = v;
    }
    if (nxt != par && nxt != rem) {
      dfs2(nxt, cur, rem, nxtd);
    }
  }
}
int main() {
  time_t t_start, t_end;
  t_start = clock();
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, d;
    cin >> u >> v >> d;
    edge[i].u = u;
    edge[i].v = v;
    edge[i].d = d;
    adj[u].push_back(edge[i]);
    adj[v].push_back(edge[i]);
  }
  long long int ans = -1;
  for (int i = 1; i <= n - 1; i++) {
    int u = edge[i].u;
    int v = edge[i].v;
    long long int d = edge[i].d;
    for (int j = 1; j <= n; j++) {
      dis[j] = dis2[j] = childnum[j] = parnum[j] = 0;
    }
    dfs(u, 0, v, 1);
    dis[0] = dis[u];
    childnum[0] = childnum[u];
    dfs2(u, 0, v, 0);
    dfs(v, 0, u, 2);
    dis[0] = dis[v];
    childnum[0] = childnum[v];
    dfs2(v, 0, u, 0);
    long long int indis = 0;
    int node1 = u;
    long long int d1 = dis[u] + dis2[u];
    int num1 = 0;
    int node2 = v;
    long long int d2 = dis[v] + dis2[v];
    int num2 = 0;
    for (int j = 1; j <= n; j++) {
      indis = indis + dis[j] + dis2[j];
      if (flag[j] == 1) {
        long long int curd = dis[j] + dis2[j];
        if (curd < d1) {
          d1 = curd;
          node1 = j;
        }
        num1++;
      } else {
        long long int curd = dis[j] + dis2[j];
        if (curd < d2) {
          d2 = curd;
          node2 = j;
        }
        num2++;
      }
    }
    long long int ddis = 0;
    ddis = indis / 2 + num1 * num2 * d + d1 * num2 + d2 * num1;
    if (ans == -1) {
      ans = ddis;
    } else {
      ans = min(ans, ddis);
    }
  }
  cout << ans << endl;
  t_end = clock();
  return 0;
}
