#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
  x = 0;
  char c = getchar();
  int flag = 0;
  while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (flag) x = -x;
}
template <class T>
T _max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
T _min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
bool checkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
const int N = 200005;
const long long inf = 1e18;
int n, dfs_clock = 0;
int dfn[N], fa[N];
vector<pair<int, int> > G[N];
int loop[N], loop_node = 0, on_loop[N];
long long dp[N], Max[N];
int value[N];
long long a[N], b[N], dep[N];
long long L[N], R[N];
long long LL[N], RR[N];
void add_edge(int x, int y, int z) { G[x].push_back(make_pair(y, z)); }
void dfs(int x, int f, int dis) {
  dfn[x] = ++dfs_clock;
  fa[x] = f;
  value[x] = dis;
  for (int i = 0; i < (int)G[x].size(); ++i) {
    int to = G[x][i].first;
    int val = G[x][i].second;
    if (to == f) continue;
    if (dfn[to]) {
      if (dfn[to] < dfn[x]) continue;
      int tmp = to;
      for (;;) {
        loop[++loop_node] = tmp;
        on_loop[tmp] = 1;
        if (tmp == x)
          a[loop_node] = val;
        else
          a[loop_node] = value[tmp];
        if (tmp == x) break;
        tmp = fa[tmp];
      }
    } else {
      dfs(to, x, val);
    }
  }
}
void dfs2(int x, int f, int typ) {
  for (int i = 0; i < (int)G[x].size(); ++i) {
    int to = G[x][i].first;
    int val = G[x][i].second;
    if (to == f || on_loop[to]) continue;
    dfs2(to, x, typ);
    checkmax(dp[x], Max[x] + Max[to] + val);
    checkmax(Max[x], Max[to] + val);
  }
}
void init() {
  read(n);
  for (int i = 1, u, v, z; i <= n; ++i) {
    read(u);
    read(v);
    read(z);
    add_edge(u, v, z);
    add_edge(v, u, z);
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= loop_node; ++i) {
    dfs2(loop[i], 0, i);
  }
}
void solve() {
  long long diameter = 0, ans = inf;
  for (int i = 1; i <= n; ++i) {
    checkmax(diameter, dp[i]);
  }
  for (int i = 1; i <= loop_node; ++i) {
    dep[i] = Max[loop[i]];
  }
  long long sum = 0;
  for (int i = 1; i <= loop_node; ++i) {
    b[i] = sum;
    sum += a[i];
  }
  long long Max = -inf;
  L[0] = R[loop_node + 1] = -inf;
  for (int i = 1; i <= loop_node; ++i) {
    L[i] = _max(L[i - 1], dep[i] + b[i] + Max);
    checkmax(Max, dep[i] - b[i]);
  }
  Max = -inf;
  for (int i = loop_node; i >= 1; --i) {
    R[i] = _max(R[i + 1], dep[i] - b[i] + Max);
    checkmax(Max, dep[i] + b[i]);
  }
  LL[0] = -inf;
  RR[loop_node + 1] = -inf;
  for (int i = 1; i <= loop_node; ++i) {
    LL[i] = LL[i - 1];
    checkmax(LL[i], dep[i] + b[i]);
  }
  for (int i = loop_node; i >= 1; --i) {
    RR[i] = RR[i + 1];
    checkmax(RR[i], dep[i] - b[i]);
  }
  long long tmp = L[loop_node];
  for (int idx = 1; idx < loop_node; ++idx) {
    long long res = _max(L[idx], R[idx + 1]);
    checkmax(res, sum + LL[idx] + RR[idx + 1]);
    checkmin(tmp, res);
  }
  ans = _max(diameter, tmp);
  printf("%lld\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
