#include <bits/stdc++.h>
using namespace std;
stack<long long> S;
bool vis[222222];
long long n, R[222222], L[222222], H[222222], PA[222222], SA[222222],
    PL[222222], SL[222222], tot;
long long TOT, LA[222222], NE[444444], EN[444444], LE[444444], d;
long long GM(long long x, long long y, long long z) {
  if (x >= y && x >= z) return x;
  if (y >= z) return y;
  return z;
}
void ADD(long long x, long long y, long long z) {
  TOT++;
  EN[TOT] = y;
  LE[TOT] = z;
  NE[TOT] = LA[x];
  LA[x] = TOT;
}
long long DFS(long long x, long long f) {
  if (vis[x]) return x;
  vis[x] = 1;
  S.push(x);
  for (long long i = LA[x]; i; i = NE[i])
    if (EN[i] != f) {
      long long y = DFS(EN[i], x);
      if (y) return y;
    }
  S.pop();
  return 0;
}
long long DFSH(long long x, long long f) {
  long long A = 0, B = 0;
  for (long long i = LA[x]; i; i = NE[i])
    if (EN[i] != f) {
      B = max(B, DFSH(EN[i], x) + LE[i]);
      if (A < B) swap(A, B);
    }
  d = max(A + B, d);
  return A;
}
void FSON(long long x) {
  long long A = 0, B = 0;
  for (long long i = LA[R[x]]; i; i = NE[i])
    if (EN[i] != R[x - 1] && EN[i] != R[x + 1]) {
      long long y = DFSH(EN[i], R[x]);
      B = max(B, y + LE[i]);
      if (A < B) swap(A, B);
    }
  H[x] = A;
  d = max(d, A + B);
}
int main() {
  long long i, j, x, y, z, Maxl, TL, ans;
  scanf("%I64d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%I64d%I64d%I64d", &x, &y, &z);
    ADD(x, y, z);
    ADD(y, x, z);
  }
  x = DFS(1, 0);
  while (!S.empty()) {
    R[++tot] = S.top();
    S.pop();
    if (R[tot] == x) break;
  }
  R[tot + 1] = R[1];
  R[0] = R[tot];
  for (i = 1; i <= tot; i++)
    for (j = LA[R[i]]; j; j = NE[j])
      if (EN[j] == R[i + 1]) {
        L[i] = LE[j];
        break;
      }
  for (i = 1; i <= tot; i++) FSON(i);
  PA[1] = PL[1] = H[1];
  SA[tot] = SL[tot] = H[tot];
  SA[tot + 1] = -1e18;
  SL[tot + 1] = -1e18;
  TL = 0;
  for (i = 2; i <= tot; i++) TL += L[i - 1], PL[i] = max(PL[i - 1], TL + H[i]);
  TL = 0;
  for (i = tot; i >= 1; i--) TL += L[i], SL[i] = max(SL[i + 1], TL + H[i]);
  Maxl = H[1];
  for (i = 2; i <= tot; i++) {
    Maxl += L[i - 1];
    PA[i] = max(PA[i - 1], H[i] + Maxl);
    Maxl = max(Maxl, H[i]);
  }
  Maxl = H[tot];
  for (i = tot - 1; i >= 1; i--) {
    Maxl += L[i];
    SA[i] = max(SA[i + 1], H[i] + Maxl);
    Maxl = max(Maxl, H[i]);
  }
  ans = max(d, PA[tot]);
  for (i = 1; i <= tot; i++)
    ans = min(ans, GM(max(d, PA[i]), SA[i + 1], PL[i] + SL[i + 1]));
  cout << ans;
}
