#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int from, to, len, next;
} edge[4999 * 2];
int head[5000], L;
void init(int n) {
  memset(head, -1, 4 * n);
  L = 0;
}
void add_edge(int u, int v, int len) {
  edge[L].from = u;
  edge[L].to = v;
  edge[L].len = len;
  edge[L].next = head[u];
  head[u] = L++;
}
int size[5000];
long long dp[5000];
void dfs(int u, int fu) {
  size[u] = 1;
  dp[u] = 0;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fu) continue;
    dfs(v, u);
    size[u] += size[v];
    dp[u] += dp[v] + (long long)size[v] * edge[i].len;
  }
}
long long sum, tot;
int m;
void dfs2(int u, int fu) {
  sum = min(sum, dp[u]);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fu) continue;
    tot += (long long)(m - size[v]) * size[v] * edge[i].len;
    dp[v] = dp[u] + (long long)(m - size[v] * 2) * edge[i].len;
    dfs2(v, u);
  }
}
const long long inf = 0x7f7f7f7f7f7f7f7fLL;
int main() {
  int n;
  scanf("%d", &n);
  init(n);
  for (int i = 1; i < n; ++i) {
    int u, v, len;
    scanf("%d%d%d", &u, &v, &len);
    add_edge(--u, --v, len);
    add_edge(v, u, len);
  }
  long long ans = inf;
  for (int i = 0; i < n * 2 - 2; i += 2) {
    tot = 0;
    sum = inf;
    dfs(edge[i].from, edge[i].to);
    m = size[edge[i].from];
    dfs2(edge[i].from, edge[i].to);
    tot += (long long)(n - m) * sum;
    sum = inf;
    dfs(edge[i].to, edge[i].from);
    m = size[edge[i].to];
    dfs2(edge[i].to, edge[i].from);
    tot += (long long)(n - m) * sum;
    tot += (long long)m * (n - m) * edge[i].len;
    ans = min(tot, ans);
  }
  printf("%I64d\n", ans);
  return 0;
}
