#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 60);
const int N = 2e5 + 10;
long long ans = inf, Ans = 0;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct Tedge {
  Tedge() {}
  Tedge(int v, long long w, int nxt) : v(v), w(w), nxt(nxt) {}
  int v, nxt;
  long long w;
} e[N << 1];
int head[N], cnt;
void addedge(int x, int y, long long z) {
  e[++cnt] = Tedge(y, z, head[x]);
  head[x] = cnt;
}
int cn, circle[N], dfs_num, dfn[N], be, en;
bool mark[N];
void find_circle(int x, int y) {
  dfn[x] = ++dfs_num;
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].v != y)
      if (!dfn[e[i].v])
        find_circle(e[i].v, x);
      else if (dfn[e[i].v] < dfn[x])
        be = dfn[e[i].v], en = dfn[x];
  if (be <= dfn[x] && dfn[x] <= en) mark[circle[cn++] = x] = 1;
}
long long dis[N], sum[N], tor[N];
long long dfs_dis(int x, int y) {
  long long max1 = 0, max2 = 0;
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].v != y && !mark[e[i].v]) {
      long long tmp = dfs_dis(e[i].v, x) + e[i].w;
      if (tmp > max1)
        max2 = max1, max1 = tmp;
      else if (tmp > max2)
        max2 = tmp;
    }
  Ans = max(Ans, max1 + max2);
  return max1;
}
struct Tnode {
  Tnode() {}
  Tnode(int i, long long a, int j, long long b) : i(i), a(a), j(j), b(b) {}
  int i, j;
  long long a, b;
};
struct segment_tree {
  Tnode t[N << 2];
  long long delta[N << 2];
  void up(int x) {
    int ti, tj;
    long long ta = -inf, tb = -inf;
    if (t[(x << 1)].a > ta)
      tb = ta, tj = ti, ta = t[(x << 1)].a, ti = t[(x << 1)].i;
    else if (t[(x << 1)].a > tb)
      tb = t[(x << 1)].a, tj = t[(x << 1)].i;
    if (t[(x << 1 | 1)].a > ta)
      tb = ta, tj = ti, ta = t[(x << 1 | 1)].a, ti = t[(x << 1 | 1)].i;
    else if (t[(x << 1 | 1)].a > tb)
      tb = t[(x << 1 | 1)].a, tj = t[(x << 1 | 1)].i;
    if (t[(x << 1)].b > tb) tb = t[(x << 1)].b, tj = t[(x << 1)].j;
    if (t[(x << 1 | 1)].b > tb) tb = t[(x << 1 | 1)].b, tj = t[(x << 1 | 1)].j;
    t[x] = Tnode(ti, ta, tj, tb);
  }
  void down(int x) {
    t[(x << 1)].a += delta[x];
    t[(x << 1)].b += delta[x];
    delta[(x << 1)] += delta[x];
    t[(x << 1 | 1)].a += delta[x];
    t[(x << 1 | 1)].b += delta[x];
    delta[(x << 1 | 1)] += delta[x];
    delta[x] = 0;
  }
  void build(int x, int l, int r, int op) {
    t[x] = Tnode(-1, -inf, -1, -inf);
    if (l == r)
      return (void)(t[x] = Tnode(l, dis[circle[l]] + op * sum[l], -1, -inf));
    int mid = l + r >> 1;
    build((x << 1), l, mid, op);
    build((x << 1 | 1), mid + 1, r, op);
    up(x);
  }
  void modify(int x, int l, int r, int L, int R, long long v) {
    if (L <= l && r <= R)
      return (void)(t[x].a += v, t[x].b += v, delta[x] += v);
    int mid = l + r >> 1;
    down(x);
    if (L <= mid) modify((x << 1), l, mid, L, R, v);
    if (R > mid) modify((x << 1 | 1), mid + 1, r, L, R, v);
    up(x);
  }
} t1, t2;
long long calc(Tnode A, Tnode B) {
  return max(max((A.a + B.a) * (A.i != B.i), (A.a + B.b) * (A.i != B.j)),
             max((A.b + B.a) * (A.j != B.i), (A.b + B.b) * (A.j != B.j)));
}
void solve_circle() {
  for (int i = 0; i < cn; i++) dis[circle[i]] = dfs_dis(circle[i], 0);
  for (int i = 0; i < cn; i++)
    for (int j = head[circle[i]]; j; j = e[j].nxt)
      if (e[j].v == circle[(i + 1) % cn]) tor[i] = e[j].w;
  for (int i = 1; i < cn; i++) sum[i] = sum[i - 1] + tor[i - 1];
  long long tot = sum[cn - 1] + tor[cn - 1];
  t1.build(1, 0, cn - 1, +1), t2.build(1, 0, cn - 1, -1);
  for (int i = 0; i < cn; i++) {
    ans = min(ans, calc(t1.t[1], t2.t[1]));
    t1.modify(1, 0, cn - 1, 0, cn - 1, -tor[i]),
        t1.modify(1, 0, cn - 1, i, i, +tot);
    t2.modify(1, 0, cn - 1, 0, cn - 1, +tor[i]),
        t2.modify(1, 0, cn - 1, i, i, -tot);
  }
}
int main() {
  int n = read();
  for (int i = 0; i < n; i++) {
    int x = read(), y = read(), z = read();
    addedge(x, y, (long long)z);
    addedge(y, x, (long long)z);
  }
  find_circle(1, 0);
  solve_circle();
  printf("%lld\n", max(Ans, ans));
  return 0;
}
