## implementation

#include <cassert>
#include <cstdio>
#include <functional>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

constexpr int inf = 1e9+7;
int main() {
int n; scanf("%d", &n);
vector<vector<pair<int, int> > > g(n);
repeat (i, n - 1) {
int a, b, c; scanf("%d%d%d", &a, &b, &c); -- a; -- b;
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
}
vector<int> size(n);
ll result = 0;
int offset = inf;
int centroid = -1;
int min_centroid_weight = inf;
function<void (int, int)> go = [&](int i, int parent) {
size[i] = 1;
int centroid_weight = 0;
for (auto edge : g[i]) {
int j, edge_weight; tie(j, edge_weight) = edge;
if (j == parent) continue;
go(j, i);
size[i] += size[j];
int s = min(size[j], n - size[j]);
result += edge_weight * 2ll * s;
if (2 * s == n) {
offset = edge_weight;
}
setmax(centroid_weight, size[j]);
}
setmax(centroid_weight, n - size[i]);
if (centroid_weight < min_centroid_weight) {
min_centroid_weight = centroid_weight;
centroid = i;
}
};
go(0, -1);
if (offset == inf) {
for (auto edge : g[centroid]) {
int edge_weight = edge.second;
setmin(offset, edge_weight);
}
}
result -= offset;
printf("%lld\n", result);
return 0;
}