#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define all(v) begin(v),end(v)
#define allr(v) v.rbegin(),v.rend()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define cases int t; cin >> t; while(t--)
#define fast_cin() ios_base::sync_with_stdio(0) 

const int mod = 1e9+7;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int MAXN = 1e5+10;

vector<pll> tree[MAXN];
vector<pll> centroidTree[MAXN];
bool centroidMarked[MAXN];
ll a,b,c;
 
/* method to add edge between to nodes of the undirected tree */
void addEdge(int u, int v)
{
    tree[u].push_back({v,c});
    tree[v].push_back({u,c});
}
 
/* method to setup subtree sizes and nodes in current tree */
void DFS(int src, bool visited[], int subtree_size[], int* n)
{
    /* mark node visited */
    visited[src] = true;
 
    /* increase count of nodes visited */
    *n += 1;
 
    /* initialize subtree size for current node*/
    subtree_size[src] = 1;
 
    vector<pll>::iterator it;
 
    /* recur on non-visited and non-centroid neighbours */
    for (it = tree[src].begin(); it != tree[src].end(); it++)
        if (!visited[((*it)).F] && !centroidMarked[((*it)).F])
        {
            DFS(((*it)).F, visited, subtree_size, n);
            subtree_size[src]+=subtree_size[((*it)).F];
        }
}
 
int getCentroid(int src, bool visited[], int subtree_size[], int n)
{
    /* assume the current node to be centroid */
    bool is_centroid = true;
 
    /* mark it as visited */
    visited[src] = true;
 
    /* track heaviest child of node, to use in case node is 
       not centroid */
    int heaviest_child = 0;
 
    vector<pll>::iterator it;
 
    /* iterate over all adjacent nodes which are children 
       (not visited) and not marked as centroid to some 
       subtree */
    for (it = tree[src].begin(); it!=tree[src].end(); it++)
        if (!visited[(*it).F] && !centroidMarked[(*it).F])
        {
            /* If any adjacent node has more than n/2 nodes,
             * current node cannot be centroid */
            if (subtree_size[(*it).F]>n/2)
                is_centroid=false;
 
            /* update heaviest child */
            if (heaviest_child==0 ||
                subtree_size[(*it).F]>subtree_size[heaviest_child])
                heaviest_child = ((*it)).F;
        }
 
    /* if current node is a centroid */
    if (is_centroid && n-subtree_size[src]<=n/2)
        return src;
 
    /* else recur on heaviest child */
    return getCentroid(heaviest_child, visited, subtree_size, n);
}
 
/* function to get the centroid of tree rooted at src.
 * tree may be the original one or may belong to the forest */
int getCentroid(int src)
{
    bool visited[MAXN];
 
    int subtree_size[MAXN];
 
    /* initialize auxiliary arrays */
    memset(visited, false, sizeof visited);
    memset(subtree_size, 0, sizeof subtree_size);
 
    /* variable to hold number of nodes in the current tree */
    int n = 0;
 
    /* DFS to set up subtree sizes and nodes in current tree */
    DFS(src, visited, subtree_size, &n);
 
    for (int i=1; i<MAXN; i++)
        visited[i] = false;
 
    int centroid = getCentroid(src, visited, subtree_size, n);
 
    centroidMarked[centroid]=true;
 
    return centroid;
}
 

ll mans = 0;
bool vis[MAXN];
bool flag ;
ll minweight ;
int cent;
int N;

ll mydfs(int i, ll lastweight)
{
	vis[i] = true;
	ll ans = 1;
	for(pll j : tree[i])
	{
		if(!vis[j.F])
		{
			ans += mydfs(j.F, j.S);
		}
	}
	if(N%2 == 0 and ans >= N/2 and cent != i)
	{
		flag = true;
		minweight = lastweight;
	}
	mans += 2*(ans)*(lastweight);

	return ans;
}


int main()
{
	cin >> N;
	minweight = 1e18;
	// ll sum = 0;
	for(int i=0;i<N-1;i++)
	{
		cin >> a >> b >> c;
		addEdge(a,b);
		// minweight = min(minweight, c);
		// sum += c;
	}
	cent = getCentroid(1);

	for(pll i : tree[cent])
		minweight = min(minweight, i.S);

	trace(cent, minweight);
	mydfs(cent, 0);
	mans -= minweight;
	cout << mans << endl;
	return 0;
}

Measured memory_bytes: 16128