#include <bits/stdc++.h>
using namespace std;
int n, bgc, cir[200005 * 2 + 10], cnt;
bool vis[200005 + 10];
long long ans = 0x7fffffffffffffffll, f[200005 + 10][3], mx,
          sum[200005 * 2 + 10];
struct E {
  int v, wt;
  bool vis;
  E *next, *back;
} * adj[200005 + 10], edge[200005 * 2 + 10], *ecnt = edge, *pre[200005 + 10];
inline void addedge(int u, int v, int wt) {
  E *p = ++ecnt;
  p->v = v;
  p->wt = wt;
  p->vis = 0;
  p->next = adj[u];
  adj[u] = p;
  p = p->back = ++ecnt;
  p->v = u;
  p->wt = wt;
  p->vis = 0;
  p->next = adj[v];
  adj[v] = p;
  p->back = ecnt - 1;
}
void find_circle(int u) {
  if (vis[u]) {
    bgc = u;
    return;
  }
  vis[u] = 1;
  for (E *p = adj[u]; p; p = p->next) {
    if (!p->vis) {
      pre[p->v] = p;
      p->back->vis = p->vis = 1;
      find_circle(p->v);
    }
  }
}
void dfs(int u, int fa) {
  for (E *p = adj[u]; p; p = p->next) {
    if (p->v != fa && !p->vis) {
      dfs(p->v, u);
      if (f[p->v][0] + p->wt > f[u][0]) {
        f[u][1] = f[u][0];
        f[u][0] = f[p->v][0] + p->wt;
      } else if (f[p->v][0] + p->wt > f[u][1])
        f[u][1] = f[p->v][0] + p->wt;
      f[u][2] = max(f[u][2], f[p->v][2]);
    }
  }
  f[u][2] = max(f[u][2], f[u][0] + f[u][1]);
}
struct node {
  long long mx, smx;
  int mxpos;
  inline node() {}
  inline node(long long mx, long long smx, int mxpos)
      : mx(mx), smx(smx), mxpos(mxpos) {}
  node *ch[2];
} tree[200005 * 8 + 10], *root[2], *tcnt = tree;
void update(node *p) {
  if (p->ch[0]->mx > p->ch[1]->mx) {
    p->mx = p->ch[0]->mx, p->mxpos = p->ch[0]->mxpos;
    p->smx = max(p->ch[0]->smx, p->ch[1]->mx);
  } else {
    p->mx = p->ch[1]->mx, p->mxpos = p->ch[1]->mxpos;
    p->smx = max(p->ch[1]->smx, p->ch[0]->mx);
  }
}
node merge_ans(const node &a, const node &b) {
  if (a.mx > b.mx) return node(a.mx, max(a.smx, b.mx), a.mxpos);
  return node(b.mx, max(a.mx, b.smx), b.mxpos);
}
void build(node *&p, int l, int r, int ff) {
  p = ++tcnt;
  if (l == r) {
    p->mx = f[cir[l]][0] + ff * sum[l];
    p->mxpos = l;
    p->smx = -0x7fffffffffffffffll;
    return;
  }
  int mid((l + r) >> 1);
  build(p->ch[0], l, mid, ff);
  build(p->ch[1], mid + 1, r, ff);
  update(p);
}
node get_ans(node *p, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return *p;
  if (ll > r || rr < l)
    return node(-0x7fffffffffffffffll, -0x7fffffffffffffffll, 0);
  int mid((l + r) >> 1);
  return merge_ans(get_ans(p->ch[0], l, mid, ll, rr),
                   get_ans(p->ch[1], mid + 1, r, ll, rr));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int u, v, wt;
    scanf("%d %d %d", &u, &v, &wt);
    addedge(u, v, wt);
  }
  find_circle(1);
  int i = bgc;
  for (E *p = edge + 1; p <= ecnt; p++) p->vis = 0;
  do {
    cir[++cnt] = i;
    pre[i]->vis = pre[i]->back->vis = 1;
    i = pre[i]->back->v;
  } while (i != bgc);
  for (i = 1; i <= cnt; i++) {
    dfs(cir[i], 0), mx = max(mx, f[cir[i]][2]);
    cir[i + cnt] = cir[i];
  }
  for (i = 2; i <= 2 * cnt; i++) sum[i] = sum[i - 1] + pre[cir[i - 1]]->wt;
  build(root[0], 1, cnt * 2, 1);
  build(root[1], 1, cnt * 2, -1);
  node a, b;
  for (i = 1; i <= cnt; i++) {
    a = get_ans(root[0], 1, cnt * 2, i, i + cnt - 1);
    b = get_ans(root[1], 1, cnt * 2, i, i + cnt - 1);
    if (a.mxpos == b.mxpos)
      ans = min(ans, max(a.mx + b.smx, a.smx + b.mx));
    else
      ans = min(ans, a.mx + b.mx);
  }
  ans = max(ans, mx);
  printf("%lld\n", ans);
}
