#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ch = getchar(), f = 1, ans = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    ans = (((ans << 2) + ans) << 1) + (ch ^ '0');
  return f ? ans : -ans;
}
const int maxn = 200005;
int n, m;
struct edge {
  long long to, w;
};
vector<edge> e[maxn];
inline void add(int u, int v, int w) {
  e[u].push_back((edge){v, w});
  e[v].push_back((edge){u, w});
}
long long chain;
bool b[maxn];
long long pre[maxn];
bool flag;
vector<int> ring;
long long u1[maxn], v1[maxn], u2[maxn], v2[maxn];
void dfs1(int u, int fa) {
  if (flag) return;
  b[u] = 1;
  for (int i = 0; i < e[u].size(); ++i) {
    if (flag) return;
    int v = e[u][i].to;
    if (v == fa) continue;
    if (b[v]) {
      for (int t = u;; t = pre[t]) {
        ring.push_back(t);
        if (t == v) break;
      }
      flag = 1;
      return;
    }
    pre[v] = u;
    dfs1(v, u);
  }
}
long long f[maxn];
long long dep[maxn];
long long d[maxn];
long long maxdis[maxn];
long long len[maxn];
long long len1[maxn], len2[maxn];
long long dep1[maxn], dep2[maxn];
long long maxd1[maxn], maxd2[maxn];
void dfs2(int nxt, int x, int u, int fa) {
  for (int i = 0; i < e[u].size(); ++i) {
    int v = e[u][i].to;
    if (v == fa) continue;
    if (b[v]) {
      if (v == nxt) len[v] = e[u][i].w;
      continue;
    }
    dfs2(0, x, v, u);
    chain = max(chain, dep[u] + dep[v] + e[u][i].w);
    dep[u] = max(dep[u], dep[v] + e[u][i].w);
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    int u = read(), v = read(), w = read();
    add(u, v, w);
  }
  dfs1(1, 0);
  memset(b, 0, sizeof b);
  for (int i = 0; i < ring.size(); ++i) b[ring[i]] = 1;
  for (int i = 0; i < ring.size(); ++i) {
    dfs2(i + 1 == ring.size() ? ring[0] : ring[i + 1], ring[i], ring[i], 0);
  }
  for (int i = 0; i < ring.size(); ++i) {
    len1[i] = len[ring[i]];
  }
  for (int i = 0; i < ring.size() - 1; ++i) {
    len2[i] = len1[i + 1];
  }
  len1[0] = 0;
  for (int i = 1; i < ring.size(); ++i) {
    len1[i] += len1[i - 1];
  }
  for (int i = ring.size() - 1; i >= 0; --i) {
    len2[i] += len2[i + 1];
  }
  for (int i = 0; i < ring.size(); ++i) {
    if (i != 0) dep1[i] = dep1[i - 1];
    dep1[i] = max(dep1[i], len1[i] + dep[ring[i]]);
  }
  for (int i = ring.size() - 1; i >= 0; --i) {
    if (i != ring.size() - 1) dep2[i] = dep2[i + 1];
    dep2[i] = max(dep2[i], len2[i] + dep[ring[i]]);
  }
  long long mxdep = dep[ring[0]];
  for (int i = 1; i < ring.size(); ++i) {
    mxdep += len1[i] - len1[i - 1];
    maxd1[i] = max(maxd1[i - 1], mxdep + dep[ring[i]]);
    mxdep = max(mxdep, dep[ring[i]]);
  }
  mxdep = dep[ring[ring.size() - 1]];
  for (int i = ring.size() - 2; i >= 0; --i) {
    mxdep += len2[i] - len2[i + 1];
    maxd2[i] = max(maxd2[i + 1], mxdep + dep[ring[i]]);
    mxdep = max(mxdep, dep[ring[i]]);
  }
  for (int i = ring.size() - 1; i >= 0; --i) {
    if (i != ring.size() - 1) dep2[i] = dep2[i + 1];
    dep2[i] = max(dep2[i], len2[i] + dep[ring[i]]);
  }
  long long maxd = 0x3f3f3f3f3f3f3f3f;
  long long cnt = len[ring[0]];
  for (int i = 0; i < ring.size(); ++i) {
    if (i == ring.size() - 1) cnt = 0;
    long long t = dep1[i] + dep2[i + 1] + cnt;
    long long s = max(maxd1[i], maxd2[i + 1]);
    long long ans = max(s, t);
    maxd = min(maxd, ans);
  }
  maxd = max(maxd, chain);
  printf("%lld", maxd);
  return 0;
}
