#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
bool MinPlace(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool MaxPlace(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename S, typename T>
ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  for (int i = 0; i < (int)v.size(); i++) {
    out << v[i];
    if (i != (int)v.size() - 1) out << ", ";
  }
  out << "]";
  return out;
}
int n;
vector<int> ch(5001);
long long int base = 0;
vector<vector<pair<int, int>>> gr(5001, vector<pair<int, int>>());
void setup(int u, int pa, long long int w = 0) {
  ch[u] = 1;
  for (auto vv : gr[u]) {
    int v = vv.first;
    if (v != pa) {
      setup(v, u, vv.second);
      ch[u] += ch[v];
    }
  }
  base += (w * ch[u] * (n - ch[u]));
}
void dfs2(int u, int pa, long long int &shift, long long int now, int sz) {
  MinPlace(shift, now);
  for (auto vv : gr[u]) {
    int v = vv.first;
    if (v == pa || ch[v] < sz - ch[v]) continue;
    dfs2(v, u, shift, now + (1ll * vv.second) * (sz - 2 * ch[v]), sz);
  }
}
void dfs1(int u, long long int &opt, long long int w = 0, int pa = 0) {
  if (pa) {
    long long int s1 = 0, s2 = 0;
    dfs2(pa, u, s1, 0, ch[pa]);
    dfs2(u, pa, s2, 0, n - ch[pa]);
    MinPlace(opt, s1 * (n - ch[pa]) + s2 * ch[pa]);
  }
  for (auto vv : gr[u]) {
    int v = vv.first;
    if (v == pa) continue;
    ch[u] = n - ch[v];
    ch[v] = n;
    dfs1(v, opt, vv.second, u);
    ch[v] = n - ch[u];
    ch[u] = n;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    gr[u].push_back(make_pair(v, w));
    gr[v].push_back(make_pair(u, w));
  }
  setup(1, 0);
  long long int change = 0;
  dfs1(1, change);
  cout << base + change << "\n";
};
