#include <bits/stdc++.h>
using namespace std;
const int N = 5002;
int n;
vector<vector<pair<int, int>>> g(N);
long long down[N], up[N], ans = 1000000000000000000ll;
vector<int> comp1, comp2;
inline int calcDown(int i, int p, vector<int> &comp) {
  comp.push_back(i);
  int ret = 1;
  for (pair<int, int> j : g[i])
    if (j.first != p) {
      int childs = calcDown(j.first, i, comp);
      down[i] += 1ll * childs * j.second + down[j.first];
      ret += childs;
    }
  return ret;
}
inline int calcUp(int i, int p, int compSize, int cost) {
  int ret = 1;
  for (pair<int, int> j : g[i])
    if (j.first != p) {
      ret += calcUp(j.first, i, compSize, j.second);
    }
  up[i] = down[p] - down[i] - 1ll * ret * cost + 1ll * cost * (compSize - ret);
  return ret;
}
inline void addUpParent(int i, int p) {
  up[i] += up[p];
  for (pair<int, int> j : g[i])
    if (j.first != p) addUpParent(j.first, i);
}
inline void update(int i, int p, int cost) {
  memset(down, 0, sizeof down);
  comp1.clear();
  comp2.clear();
  calcDown(i, p, comp1);
  calcDown(p, i, comp2);
  memset(up, 0, sizeof up);
  for (pair<int, int> j : g[i])
    if (j.first != p)
      calcUp(j.first, i, ((int)(comp1).size()), j.second),
          addUpParent(j.first, i);
  for (pair<int, int> j : g[p])
    if (j.first != i)
      calcUp(j.first, p, ((int)(comp2).size()), j.second),
          addUpParent(j.first, p);
  long long curr = 0;
  long long mn1 = 1000000000000000000ll, mn2 = 1000000000000000000ll;
  for (int j : comp1) {
    curr += down[j] + up[j];
    mn1 = min(mn1, down[j] + up[j]);
  }
  for (int j : comp2) {
    curr += down[j] + up[j];
    mn2 = min(mn2, down[j] + up[j]);
  }
  assert(curr % 2 == 0);
  ans =
      min(ans, curr / 2 +
                   1ll * cost * ((int)(comp1).size()) * ((int)(comp2).size()) +
                   mn1 * ((int)(comp2).size()) + mn2 * ((int)(comp1).size()));
}
inline void dfs(int i, int p, int cost) {
  update(i, p, cost);
  for (pair<int, int> j : g[i])
    if (j.first != p) dfs(j.first, i, j.second);
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (int)(n - 1); ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  for (pair<int, int> j : g[1]) dfs(j.first, 1, j.second);
  cout << ans;
}
