#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
struct edge {
  int to, v, id;
};
edge make_edge(int to, int v, int id) {
  edge tmp;
  tmp.to = to;
  tmp.v = v;
  tmp.id = id;
  return tmp;
}
int n;
long long sz[5011], dis[5011], ans, res = LINF;
vector<edge> con[5011];
pair<pair<int, int>, int> E[5011];
void dfs1(int x, int pre, long long &sum) {
  sum += dis[x];
  sz[x] = 1;
  for (int i = 0; i < con[x].size(); i++) {
    int v = con[x][i].to;
    if (v != pre) {
      dis[v] = dis[x] + con[x][i].v;
      dfs1(v, x, sum);
      sz[x] += sz[v];
    }
  }
}
long long dfs2(int x, int pre, long long sum, int t) {
  long long ret = sum;
  for (int i = 0; i < con[x].size(); i++) {
    int v = con[x][i].to;
    if (v != pre) {
      ret = min(
          ret,
          dfs2(v, x, sum - con[x][i].v * sz[v] + con[x][i].v * (sz[t] - sz[v]),
               t));
      ans += con[x][i].v * sz[v] * (sz[t] - sz[v]);
    }
  }
  return ret;
}
int main() {
  n = getnum();
  int x, y, z;
  for (int i = 1; i < n; i++) {
    x = getnum(), y = getnum(), z = getnum();
    con[x].push_back(make_edge(y, z, i));
    con[y].push_back(make_edge(x, z, i));
    E[i] = make_pair(make_pair(x, y), z);
  }
  for (int i = 1; i < n; i++) {
    x = E[i].first.first, y = E[i].first.second, z = E[i].second;
    dis[x] = dis[y] = 0;
    ans = 0;
    long long sum1 = 0, sum2 = 0;
    dfs1(x, y, sum1);
    dfs1(y, x, sum2);
    ans += z * sz[x] * sz[y];
    ans += dfs2(x, y, sum1, x) * sz[y];
    ans += dfs2(y, x, sum2, y) * sz[x];
    res = min(res, ans);
  }
  putnum(res), putendl();
  return 0;
}
