#include <bits/stdc++.h>
using namespace std;
const int maxn = 200011;
const int maxm = 400011;
int n, ecnt, first[maxn], to[maxm], nxt[maxm], w[maxm];
int b[maxn], scnt, father[maxn], val[maxn], fa_w[maxn];
bool sss[maxn], vis[maxn];
long long f[maxn], pre[maxn], best[maxn], pre2[maxn], best2[maxn], ans, chain;
inline int getint() {
  int w = 0, q = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 1, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? -w : w;
}
inline void dfs_find(int x, int fa) {
  vis[x] = 1;
  for (int i = first[x]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    if (vis[v]) {
      if (sss[v]) continue;
      int u = x;
      while (u != v) {
        sss[u] = true;
        b[++scnt] = u;
        val[scnt] = fa_w[u];
        u = father[u];
      }
      sss[u] = true;
      b[++scnt] = v;
      val[scnt] = w[i];
      continue;
    }
    father[v] = x;
    fa_w[v] = w[i];
    vis[v] = true;
    dfs_find(v, x);
  }
}
inline void dfs(int x, int fa) {
  for (int i = first[x]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa || sss[v]) continue;
    dfs(v, x);
    chain = max(chain, f[x] + f[v] + w[i]);
    f[x] = max(f[x], f[v] + w[i]);
  }
}
inline void work() {
  n = getint();
  int x, y, z;
  for (int i = 1; i <= n; i++) {
    x = getint();
    y = getint();
    z = getint();
    nxt[++ecnt] = first[x];
    first[x] = ecnt;
    to[ecnt] = y;
    w[ecnt] = z;
    nxt[++ecnt] = first[y];
    first[y] = ecnt;
    to[ecnt] = x;
    w[ecnt] = z;
  }
  dfs_find(1, 0);
  long long tot = 0, da = 0;
  int now;
  for (int i = 1; i <= scnt; i++) dfs(b[i], 0);
  for (int i = 1; i <= scnt; i++) {
    tot += val[i - 1];
    now = b[i];
    pre[i] = max(pre[i - 1], tot + f[now]);
    best[i] = max(best[i - 1], tot + da + f[now]);
    da = max(da, f[now] - tot);
  }
  tot = 0;
  long long duan = val[scnt];
  val[scnt] = da = 0;
  for (int i = scnt; i >= 1; i--) {
    tot += val[i];
    now = b[i];
    pre2[i] = max(pre2[i + 1], tot + f[now]);
    best2[i] = max(best2[i + 1], tot + da + f[now]);
    da = max(da, f[now] - tot);
  }
  ans = best[scnt];
  long long choose;
  for (int i = 1; i < scnt; i++) {
    choose = max(best[i], best2[i + 1]);
    choose = max(choose, pre[i] + pre2[i + 1] + duan);
    if (choose < ans) ans = choose;
  }
  ans = max(ans, chain);
  printf("%lld", ans);
}
int main() {
  work();
  return 0;
}
