#include <bits/stdc++.h>
using namespace std;
struct EDGE {
  int u, v, w, next;
} e[10010];
int head[10010], cnt = 0;
void add(int u, int v, int w) {
  e[cnt].u = u;
  e[cnt].v = v;
  e[cnt].w = w;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
long long dp[10010];
int num[10010];
void dfs(int u, int fa) {
  num[u] = 1;
  dp[u] = 0;
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].v, w = e[i].w;
    if (v == fa) continue;
    dfs(v, u);
    num[u] += num[v];
    dp[u] += dp[v] + (long long)num[v] * w;
  }
}
long long mid;
void DFS(int u, int fa, int s, long long &t1) {
  if (dp[u] < t1) t1 = dp[u];
  mid += dp[u];
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].v, w = e[i].w;
    if (v == fa) continue;
    dp[v] = dp[u] + (long long)(num[s] - num[v]) * w - (long long)num[v] * w;
    DFS(v, u, s, t1);
  }
}
void deal(int s, int t, int w) {
  long long t1 = 1000000000000000000LL, t2 = 1000000000000000000LL;
  mid = 0;
  dfs(s, t);
  DFS(s, t, s, t1);
  dfs(t, s);
  DFS(t, s, t, t2);
  mid /= 2;
  mid += t1 * num[t] + t2 * num[s] + (long long)num[s] * num[t] * w;
}
void solve(int s, int t, int w, long long &ans) {
  deal(s, t, w);
  if (mid < ans) ans = mid;
}
int main() {
  int n;
  scanf("%d", &n);
  memset(head, -1, sizeof(head));
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add(u, v, w);
    add(v, u, w);
  }
  long long ans = 1000000000000000000LL;
  for (int i = 0; i < cnt; i += 2) solve(e[i].u, e[i].v, e[i].w, ans);
  cout << ans << endl;
  return 0;
}
