#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  int fx = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') fx = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + s - '0';
    s = getchar();
  }
  x *= fx;
}
const int N = 201000;
const long long inf = 0x3f3f3f3f3f3f3f3f;
struct Edge {
  int ver, nxt, w;
} a[N << 1];
int head[N], is[N], st[N], vis[N];
long long f[N], pre[N];
int gl[N], gr[N], hl[N], hr[N], hhl[N], hhr[N], ggl[N], ggr[N];
int n, m, tot, top;
long long Ans;
void get_cir(int x, int las) {
  if (vis[x]) {
    int p = top;
    while (st[p] ^ x) --p;
    for (int i = p; i <= top; i++) is[st[i - p + 1] = st[i]] = 1;
    st[0] = -1, top -= p - 1;
    return;
  }
  vis[st[++top] = x] = 1;
  for (int i = head[x]; i && ~st[0]; i = a[i].nxt)
    if (a[i].ver ^ las) get_cir(a[i].ver, x);
  if (~st[0]) vis[st[top--]] = 0;
}
void dfs(int x, int las) {
  long long sec = 0ll;
  for (int i = head[x]; i; i = a[i].nxt)
    if (!is[a[i].ver] && a[i].ver ^ las) {
      dfs(a[i].ver, x);
      f[a[i].ver] += a[i].w;
      if (f[a[i].ver] >= f[x])
        sec = f[x], f[x] = f[a[i].ver];
      else if (f[a[i].ver] > sec)
        sec = f[a[i].ver];
    }
  Ans = max(Ans, f[x] + sec);
}
inline long long G(int x) { return x ? f[st[x]] - pre[x] : -inf; }
inline long long H(int x) { return x ? f[st[x]] + pre[x] : -inf; }
void work() {
  st[0] = st[top];
  for (int x = 1; x <= top; ++x) {
    for (int i = head[st[x - 1]]; i; i = a[i].nxt)
      if (a[i].ver == st[x]) {
        pre[x] = pre[x - 1] + a[i].w;
        break;
      }
    dfs(st[x], 0);
  }
  for (int i = 1; i <= top; i++) {
    gl[i] = gl[i - 1], ggl[i] = ggl[i - 1];
    hl[i] = hl[i - 1], hhl[i] = hhl[i - 1];
    if (G(i) > G(gl[i]))
      ggl[i] = gl[i], gl[i] = i;
    else if (G(i) > G(ggl[i]))
      ggl[i] = i;
    if (H(i) > H(hl[i]))
      hhl[i] = hl[i], hl[i] = i;
    else if (H(i) > H(hhl[i]))
      hhl[i] = i;
  }
  for (int i = top; i; --i) {
    gr[i] = gr[i + 1], ggr[i] = ggr[i + 1];
    hr[i] = hr[i + 1], hhr[i] = hhr[i + 1];
    if (G(i) > G(gr[i]))
      ggr[i] = gr[i], gr[i] = i;
    else if (G(i) > G(ggr[i]))
      ggr[i] = i;
    if (H(i) > H(hr[i]))
      hhr[i] = hr[i], hr[i] = i;
    else if (H(i) > H(hhr[i]))
      hhr[i] = i;
  }
  long long ans;
  if (hl[top] != gl[top])
    ans = G(gl[top]) + H(hl[top]);
  else
    ans = max(G(ggl[top]) + H(hl[top]), G(gl[top]) + H(hhl[top]));
  for (int i = 1; i < top; i++) {
    long long val = pre[top] + H(hl[i]) + G(gr[i + 1]), tmp;
    if (gl[i] ^ hl[i])
      tmp = G(gl[i]) + H(hl[i]);
    else
      tmp = max(G(ggl[i]) + H(hl[i]), G(gl[i]) + H(hhl[i]));
    val = max(val, tmp);
    i++;
    if (gr[i] ^ hr[i])
      tmp = G(gr[i]) + H(hr[i]);
    else
      tmp = max(G(ggr[i]) + H(hr[i]), G(gr[i]) + H(hhr[i]));
    val = max(val, tmp);
    i--;
    ans = min(ans, val);
  }
  cout << max(ans, Ans) << endl;
}
void init() {
  read(n);
  for (int i = 1, u, v, w; i <= n; i++) {
    read(u), read(v), read(w);
    a[++tot].ver = v, a[tot].w = w, a[tot].nxt = head[u], head[u] = tot;
    a[++tot].ver = u, a[tot].w = w, a[tot].nxt = head[v], head[v] = tot;
  }
  get_cir(1, 1);
}
int main() {
  init();
  work();
  return 0;
}
