#include <bits/stdc++.h>
using namespace std;
int w, x, y, v, i, n;
int s[2];
int C[5005];
long long mn[2], ans = 1000000000000000000LL, anss[2];
vector<pair<int, int> > V[5005];
pair<int, pair<int, int> > Edges[5005];
inline int f(int x, int root) {
  ++s[1];
  C[x] = 1;
  for (__typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++)
    if (it->first != root) C[x] += f(it->first, x);
  return C[x];
}
inline long long f2(int x, int root) {
  long long t = 0;
  for (__typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++)
    if (it->first != root) {
      anss[w] += (long long)it->second * C[it->first] * (s[w] - C[it->first]);
      t += (long long)it->second * C[it->first] + f2(it->first, x);
    }
  return t;
}
inline void f3(int x, int root, long long atans) {
  long long q;
  for (__typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++)
    if (it->first != root) {
      q = atans;
      q += (long long)it->second * (s[w] - C[it->first]) -
           (long long)it->second * C[it->first];
      mn[w] = min(mn[w], q);
      f3(it->first, x, q);
    }
}
inline void f4(int x, int root) {
  for (__typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++)
    if (it->first != root) {
      f4(it->first, x);
    }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n - 1; i++) {
    scanf("%d %d %d", &x, &y, &v);
    V[x].push_back(make_pair(y, v));
    V[y].push_back(make_pair(x, v));
    Edges[i] = (make_pair(v, make_pair(x, y)));
  }
  for (i = 1; i <= n - 1; i++) {
    s[0] = s[1] = 0;
    x = Edges[i].second.first;
    y = Edges[i].second.second;
    f(x, y);
    s[0] = s[1];
    s[1] = 0;
    f(y, x);
    anss[0] = anss[1] = 0;
    w = 0;
    mn[0] = f2(x, y);
    w = 1;
    mn[1] = f2(y, x);
    w = 0;
    f3(x, y, mn[0]);
    w = 1;
    f3(y, x, mn[1]);
    ans = min(ans, (long long)s[0] * s[1] * Edges[i].first +
                       (long long)s[0] * mn[1] + (long long)s[1] * mn[0] +
                       anss[0] + anss[1]);
  }
  printf("%lld", ans);
  return 0;
}
