#include <bits/stdc++.h>
using namespace std;
inline void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &$val, const Args &...args) {
  string $name;
  *iss >> $name;
  if ($name.back() == ',') $name.pop_back();
  cout << $name << " = " << $val << "; ", err(iss, args...);
}
int n, m, K, T, Q, cn;
struct Out {
  int v, w;
};
list<Out> adj[5005];
struct info {
  long long sum, cnt;
} nich[5005];
long long upor[5005];
void dfsNich(int u, const int &par) {
  long long sum = 0, cnt = 1;
  for (auto &v : adj[u])
    if (v.v != par) {
      dfsNich(v.v, u);
      sum += nich[v.v].sum + nich[v.v].cnt * v.w, cnt += nich[v.v].cnt;
    }
  nich[u] = {sum, cnt};
}
long long cntNodes, mnSum;
void dfsUpor(int u, const int &par) {
  mnSum = min(mnSum, nich[u].sum + upor[u]);
  for (auto &v : adj[u])
    if (v.v != par) {
      long long siblings = nich[u].sum - (nich[v.v].sum + nich[v.v].cnt * v.w);
      upor[v.v] = upor[u] + siblings + (cntNodes - nich[v.v].cnt) * v.w;
      dfsUpor(v.v, u);
    }
}
int main() {
  cin.tie(NULL);
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back({v, w}), adj[v].push_back({u, w});
  }
  long long mn = 1000000000000000000LL;
  for (int i = 1; i <= n; i++) {
    for (auto &j : adj[i]) {
      if (j.v < i) continue;
      dfsNich(j.v, i), dfsNich(i, j.v);
      long long cur = nich[j.v].cnt * nich[i].cnt * j.w;
      cntNodes = nich[j.v].cnt, mnSum = 1000000000000000000LL, upor[j.v] = 0,
      dfsUpor(j.v, i), cur += mnSum * nich[i].cnt;
      cntNodes = nich[i].cnt, mnSum = 1000000000000000000LL, upor[i] = 0,
      dfsUpor(i, j.v), cur += mnSum * nich[j.v].cnt;
      long long os = 0;
      for (int k = 1; k <= n; k++) {
        os += upor[k] + nich[k].sum;
      }
      cur += os >> 1;
      mn = min(mn, cur);
    }
  }
  printf("%lld\n", mn);
  return 0;
}
