#include <cstdio>
#include <vector>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

typedef pair <int, int> ii;
typedef tuple <int, int, int> iii;

#define INF 1000000000

//#define DEBUG;

int N;
vector <iii> adjList[100005];
int indeg[100005];
iii edgeList[100005];
queue <ii> bfs;
bool visited[100005];
int passTimes[100005];
long long ans;

int subtree[100005];
int getSubtree(int u, int prevP)
{
    int curSize = 1;
    for (iii n : adjList[u])
    {
        int v, w, i; tie(v, w, i) = n;
        if (v == prevP) continue;
        curSize += getSubtree(v, u);
    }
    return subtree[u] = curSize;
}

int dfs(int u, int prevP)
{
    for (iii n : adjList[u])
    {
        int v, w, i; tie(v, w, i) = n;
        if (v == prevP) continue;
        ans += (long long) w * min(N - subtree[v], subtree[v]) * 2;
        dfs(v, u);
    }
}

vector <int> getCentroid(int u, int prevP)
{
    vector <int> centroids;
    bool isCentroid = true;
    for (iii n : adjList[u])
    {
        int v, w, i; tie(v, w, i) = n;
        if (v == prevP) continue;
        if (subtree[v] > N / 2) isCentroid = false;
        vector <int> temp = getCentroid(v, u);
        for (centroid : temp) centroids.push_back(centroid);
    }
    if (N - subtree[u] > N / 2) isCentroid = false;
    if (isCentroid) centroids.push_back(u);
    return centroids;
}

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N - 1; i++)
    {
        int A, B, C; scanf("%d%d%d", &A, &B, &C);
        adjList[A].emplace_back(B, C, i);
        adjList[B].emplace_back(A, C, i);
        edgeList[i] = iii(A, B, C);
        indeg[A]++; indeg[B]++;
    }
    /*
    for (int i = 1; i <= N; i++) if (indeg[i] == 1) bfs.emplace(i, 1), visited[i] = true;
    while (!bfs.empty())
    {
        int u, times; tie(u, times) = bfs.front(); bfs.pop();
        for (iii n : adjList[u])
        {
            int v, w, i; tie(v, w, i) = n;
            printf("%d -> %d; %d * %d\n", u, v, w, times * 2);
            passTimes[i] = times * 2;
            ans += passTimes[i] * w;
            if (!visited[v]) bfs.emplace(v, times + 1);
            visited[v] = true;
        }
    }
    */

    getSubtree(1, -1);
    dfs(1, -1);

    #ifdef DEBUG
    printf("adjList:\n");
    for (int u = 1; u <= N; u++)
    {
        printf("%d:", u);
        for (iii n : adjList[u])
        {
            int v, w, i; tie(v, w, i) = n;
            printf(" (%d, %d, %d)", v, w, i);
        }
        printf("\n");
    }
    printf("\n");
    printf("passTimes:\n");
    for (int i = 1; i <= N; i++)
    {
        printf("%d: %d\n", i, passTimes[i]);
    }
    printf("\n");
    #endif // DEBUG

    vector <int> centroids = getCentroid(1, -1);
    if (centroids.size() == 2)
    {
        int u = centroids[0], v = centroids[1];
        for (iii n : adjList[u])
        {
            int v1, w, i; tie(v1, w, i) = n;
            if (v1 == v) ans -= w;
        }
    }
    else
    {
        int minW = INF;
        for (iii n : adjList[centroids[0]])
        {
            int v, w, i; tie(v, w, i) = n;
            minW = min(minW, w);
        }
        ans -= minW;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 17024