#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const long long INF = 1e18;
template <typename Tp>
inline int getmin(Tp &x, Tp y) {
  return y < x ? x = y, 1 : 0;
}
template <typename Tp>
inline int getmax(Tp &x, Tp y) {
  return y > x ? x = y, 1 : 0;
}
template <typename Tp>
inline void read(Tp &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') f = 1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  if (f) x = -x;
}
struct data {
  int v, w, nxt;
} edge[maxn << 1];
int n, p = -1, cnt, id, head[maxn], vis[maxn], cir[maxn];
long long ans, mx, mxdis, tmp, sum[maxn], dep[maxn], dis[maxn];
long long pm1[maxn], pm2[maxn], sm1[maxn], sm2[maxn], m1[maxn], m2[maxn];
queue<pair<int, int> > q;
inline int pre(int x) { return x == 1 ? cnt : x - 1; }
inline int nxt(int x) { return x == cnt ? 1 : x + 1; }
inline void insert(int u, int v, int w) {
  edge[++p] = (data){v, w, head[u]};
  head[u] = p;
  edge[++p] = (data){u, w, head[v]};
  head[v] = p;
}
void input() {
  int u, v, w;
  read(n);
  memset(head, 0xff, sizeof(head));
  for (register int i = 1; i <= n; i++) {
    read(u);
    read(v);
    read(w);
    insert(u, v, w);
  }
}
int dfs(int x, int pre) {
  if (vis[x]) return x;
  int tmp;
  vis[x] = 1;
  for (int i = head[x]; ~i; i = edge[i].nxt)
    if (i ^ pre)
      if (tmp = dfs(edge[i].v, i ^ 1)) {
        if (tmp == -1) return -1;
        cir[++cnt] = x;
        sum[cnt] = edge[i].w;
        return tmp == x ? -1 : tmp;
      }
  return 0;
}
void bfs(int s, int ban1, int ban2) {
  while (!q.empty()) q.pop();
  int x, lst;
  mxdis = dis[s] = 0ll;
  id = 0;
  q.push(make_pair(s, -1));
  while (!q.empty()) {
    x = q.front().first;
    lst = q.front().second;
    q.pop();
    if (getmax(mxdis, dis[x])) id = x;
    for (int i = head[x]; ~i; i = edge[i].nxt)
      if (i ^ lst && edge[i].v ^ ban1 && edge[i].v ^ ban2) {
        dis[edge[i].v] = dis[x] + edge[i].w;
        q.push(make_pair(edge[i].v, i ^ 1));
      }
  }
}
int main() {
  input();
  dfs(1, -1);
  for (register int i = 1; i <= cnt; i++) {
    sum[i] += sum[i - 1];
    bfs(cir[i], cir[pre(i)], cir[nxt(i)]);
    dep[i] = mxdis;
    bfs(id, cir[pre(i)], cir[nxt(i)]);
    getmax(mx, mxdis);
  }
  ans = INF;
  pm1[0] = pm2[0] = sm1[cnt + 1] = sm2[cnt + 1] = -INF;
  sm2[cnt + 2] = -INF;
  for (register int i = 1; i <= cnt; i++) {
    m1[i] = max(m1[i - 1], dep[i] + sum[i] + pm1[i - 1]);
    pm1[i] = max(pm1[i - 1], dep[i] - sum[i]);
    pm2[i] = max(pm2[i - 1], dep[i] + sum[i]);
  }
  for (register int i = cnt; i; i--) {
    m2[i] = max(m2[i + 1], dep[i + 1] - sum[i + 1] + sm2[i + 2]);
    sm1[i] = max(sm1[i + 1], dep[i] - sum[i]);
    sm2[i] = max(sm2[i + 1], dep[i] + sum[i]);
  }
  for (register int i = 1; i < cnt; i++) {
    tmp = 0ll;
    getmax(tmp, m1[i]);
    getmax(tmp, m2[i]);
    getmax(tmp, sum[cnt] + sm1[i + 1] + pm2[i]);
    getmin(ans, tmp);
  }
  tmp = 0ll;
  for (register int i = 2; i <= cnt; i++)
    getmax(tmp, dep[i] + sum[i] + pm1[i - 1]);
  getmin(ans, tmp);
  getmax(ans, mx);
  printf("%I64d\n", ans);
  return 0;
}
