#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

struct tree_t {
  int n;           // |V|, index begins with 0
  int r;           // root
  vector<P> edges; // E
  vector<ll> cost; // cost or distance
};

class Tree {
private:
  struct node {
    int id; vi childs; int parent; ll cost; int deg; ll d;
    bool operator<(const node & another) const {
      return deg != another.deg ? deg < another.deg : id < another.id;
    }
  };
  int n;
public:
  vector<node> nodes;
  vi leaves;
  int root;
  Tree(tree_t T) {
    n = T.n;
    root = T.r;
    nodes.resize(n);
    Loop(i, n) nodes[i] = { i,{},-1,0,-1,0 };
    map<int, vector<pair<int, ll>>> edges;
    Loop(i, n - 1) {
      if (T.cost.size() == 0) {
        edges[T.edges[i].first].push_back({ T.edges[i].second,1 });
        edges[T.edges[i].second].push_back({ T.edges[i].first,1 });
      }
      else {
        edges[T.edges[i].first].push_back({ T.edges[i].second,T.cost[i] });
        edges[T.edges[i].second].push_back({ T.edges[i].first,T.cost[i] });
      }
    }
    leaves = {};
    stack<int> stk;
    stk.push(root);
    while (stk.size()) {
      int a = stk.top(); stk.pop();
      if (nodes[a].deg != -1) continue;
      if (a == root) nodes[a].deg = 0;
      int leaf_flag = true;
      Loop(i, edges[a].size()) {
        int b = edges[a][i].first;
        if (nodes[b].deg != -1) {
          nodes[a].parent = b;
          nodes[a].cost = edges[a][i].second;
          nodes[a].deg = nodes[b].deg + 1;
          nodes[a].d = nodes[b].d + nodes[a].cost;
        }
        else {
          leaf_flag = false;
          nodes[a].childs.push_back(b);
          stk.push(b);
        }
      }
      if (leaf_flag) leaves.push_back(a);
    }
    if (n == 1) leaves.push_back(root);
    return;
  }
  pair<int, vi> get_center_of_gravity() {
    pair<int, vi> ret = { INT_MAX, {} };
    vector<node> c_nodes = nodes;
    sort(c_nodes.begin(), c_nodes.end());
    vi record(n, 1);
    Loopr(i, n) {
      int x = n - 1, max_x = INT_MIN;
      Loop(j, c_nodes[i].childs.size()) {
        int b = c_nodes[i].childs[j];
        max_x = max(max_x, record[b]);
        x -= record[b];
        record[c_nodes[i].id] += record[b];
      }
      max_x = max(max_x, x);
      if (max_x < ret.first) ret = { max_x, {c_nodes[i].id} };
      else if (max_x == ret.first) ret.second.push_back(c_nodes[i].id);
    }
    sort(ret.second.begin(), ret.second.end());
    return ret;
  }
  ll solve() {
    if (n == 0) return 0;
    vector<node> c_nodes = nodes;
    sort(c_nodes.begin(), c_nodes.end());
    vi record(n, 0);
    Loopr(i, n) {
      if (c_nodes[i].id == root) continue;
      else record[c_nodes[i].id] = 2;
      Loop(j, c_nodes[i].childs.size()) {
        int b = c_nodes[i].childs[j];
        record[c_nodes[i].id] += record[b];
      }
    }
    ll sum = 0;
    Loop(i, n) {
      if (i == root) continue;
      sum += record[i] * nodes[i].cost;
    }
    pair<int, vi> g = get_center_of_gravity();
    if (g.second.size() == 2) {
      int a = g.second[0], b = g.second[1];
      if (nodes[a].parent == b) sum -= nodes[a].cost;
      else sum -= nodes[b].cost;
    }
    else {
      int a = g.second[0];
      ll min_x = LLONG_MAX;
      if (a != root) min_x = nodes[a].cost;
      Loop(i, nodes[a].childs.size()) {
        int b = nodes[a].childs[i];
        min_x = min(min_x, nodes[b].cost);
      }
      sum -= min_x;
    }
    return sum;
  }
};

int main() {
  tree_t T;
  cin >> T.n;
  T.r = 0;
  Loop(i, T.n - 1) {
    int s, t;
    ll c;
    cin >> s >> t >> c;
    T.edges.push_back({ s - 1,t - 1 });
    T.cost.push_back(c);
  }
  Tree tree(T);
  T.r = tree.get_center_of_gravity().second[0];
  Tree tree2(T);
  cout << tree2.solve() << endl;
  return 0;
}

Measured memory_bytes: 47328