#include <bits/stdc++.h>
using namespace std;
long long n, x, y, z, t, ts, sum1, sum2, res;
long long h[400010], b[400010], c[400010], w[400010], f[400010], l1[400010],
    l2[400010], r1[400010], r2[400010];
struct edge {
  long long to, w, next;
} e[400010];
void add(long long x, long long y, long long z) {
  t++;
  e[t].to = y;
  e[t].w = z;
  e[t].next = h[x];
  h[x] = t;
}
long long find(long long x, long long f = -1) {
  if (b[x])
    return x;
  else
    b[x] = -1;
  for (long long i = h[x]; i > 0; i = e[i].next)
    if (e[i].to != f) {
      res = find(e[i].to, x);
      if (res) {
        c[++ts] = x;
        w[ts] = e[i].w;
        b[x] = 1;
        if (res == x)
          return 0;
        else
          return res;
      }
    }
  return 0;
}
void dfs(long long x, long long fa = -1) {
  for (long long i = h[x]; i; i = e[i].next)
    if (b[e[i].to] != 1 && e[i].to != fa) {
      dfs(e[i].to, x);
      sum1 = max(sum1, f[x] + f[e[i].to] + e[i].w);
      f[x] = max(f[x], f[e[i].to] + e[i].w);
    }
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
  }
  find(1);
  w[0] = 0;
  for (long long i = 1; i <= ts; i++) dfs(c[i]), w[i] += w[i - 1];
  res = l1[0] = l2[0] = -2e18;
  for (long long i = 1; i <= ts; i++) {
    l2[i] = max(l2[i - 1], f[c[i]] + w[i] + res);
    l1[i] = max(l1[i - 1], f[c[i]] + w[i]);
    res = max(res, f[c[i]] - w[i]);
  }
  res = r1[ts + 1] = r2[ts + 1] = -2e18;
  for (long long i = ts; i >= 1; i--) {
    r2[i] = max(r2[i + 1], f[c[i]] - w[i] + res);
    r1[i] = max(r1[i + 1], f[c[i]] + w[ts] - w[i]);
    res = max(res, f[c[i]] + w[i]);
  }
  sum2 = 2e18;
  for (long long i = 1; i <= ts; i++)
    sum2 = min(sum2, max(l1[i - 1] + r1[i], max(l2[i - 1], r2[i])));
  cout << max(sum1, sum2);
  return 0;
}
