#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x;
}
int n, cnt;
bool bo[200010];
int fa[200010], a[200010], dep[200010];
long long d[200010], di[200010], dis[200010], b[200010], va[200010];
long long s1[200010], s2[200010], t1[200010], t2[200010], ans;
int head[200010], ne[200010 << 1], ver[200010 << 1], value[200010 << 1], tot;
void add(int z, int y, int x) {
  ver[++tot] = y;
  value[tot] = z;
  ne[tot] = head[x];
  head[x] = tot;
  ver[++tot] = x;
  value[tot] = z;
  ne[tot] = head[y];
  head[y] = tot;
}
void dfs(int u, int pre) {
  dep[u] = dep[pre] + 1;
  fa[u] = pre;
  for (int i = head[u], v, val; i; i = ne[i]) {
    v = ver[i];
    val = value[i];
    if (v == pre || bo[v]) continue;
    dis[v] = val;
    if (dep[v]) {
      if (dep[v] < dep[u])
        for (int j = u; j != fa[v]; j = fa[j]) {
          bo[j] = true;
          a[++cnt] = j;
          va[cnt] = dis[j];
        }
    } else
      dfs(v, u);
  }
}
void dp(int u, int pre) {
  long long val;
  for (int i = head[u], v; i; i = ne[i]) {
    v = ver[i];
    if (v == pre || bo[v]) continue;
    val = value[i];
    dp(v, u);
    ans = max(ans, d[u] + d[v] + val);
    d[u] = max(d[u], d[v] + val);
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) add(read(), read(), read());
  dfs(1, 0);
  for (int i = 1; i <= cnt; i++) dp(a[i], 0), b[i] = d[a[i]];
  long long sum = 0, maxx = 0;
  for (int i = 1; i <= cnt; i++) {
    sum += va[i - 1];
    s1[i] = max(s1[i - 1], sum + b[i]);
    t1[i] = max(t1[i - 1], sum + b[i] + maxx);
    maxx = max(maxx, b[i] - sum);
  }
  sum = maxx = 0;
  long long len = va[cnt];
  va[cnt] = 0;
  for (int i = cnt; i >= 1; i--) {
    sum += va[i];
    s2[i] = max(s2[i + 1], sum + b[i]);
    t2[i] = max(t2[i + 1], sum + b[i] + maxx);
    maxx = max(maxx, b[i] - sum);
  }
  long long ans1 = t1[cnt];
  for (int i = 1; i < cnt; i++)
    ans1 = min(ans1, max(max(t1[i], t2[i + 1]), s1[i] + s2[i + 1] + len));
  ans = max(ans, ans1);
  cout << ans << endl;
  return 0;
}
