In the Kingdom K., there are n towns numbered with integers from 1 to n. The towns are connected by n bi-directional roads numbered with integers from 1 to n. The i-th road connects the towns ui and vi and its length is li. There is no more than one road between two towns. Also, there are no roads that connect the towns with itself.

Let's call the inconvenience of the roads the maximum of the shortest distances between all pairs of towns.

Because of lack of money, it was decided to close down one of the roads so that after its removal it is still possible to reach any town from any other. You have to find the minimum possible inconvenience of the roads after closing down one of the roads.

Input

The first line contains the integer n (3 ≤ n ≤ 2·105) — the number of towns and roads.

The next n lines contain the roads description. The i-th from these lines contains three integers ui, vi, li (1 ≤ ui, vi ≤ n, 1 ≤ li ≤ 109) — the numbers of towns connected by the i-th road and the length of the i-th road. No road connects a town to itself, no two roads connect the same towns.

It's guaranteed that it's always possible to close down one of the roads so that all the towns are still reachable from each other.

Output

Print a single integer — the minimum possible inconvenience of the roads after the refusal from one of the roads.

Examples

Input

3
1 2 4
2 3 5
1 3 1


Output

5


Input

5
2 3 7
3 1 9
4 1 8
3 5 4
4 5 5


Output

18
#include <bits/stdc++.h>
using namespace std;
int n, cnt, tot, dfsclk, pos[400005], fst[400005], pnt[400005 << 1],
    len[400005 << 1], nxt[400005 << 1], a[400005], b[400005], c[400005],
    fa[400005];
long long f[400005], u1[400005], u2[400005], v1[400005], v2[400005], ans;
bool ok[400005];
void add(int x, int y, int z) {
  pnt[++tot] = y;
  len[tot] = z;
  nxt[tot] = fst[x];
  fst[x] = tot;
}
void dfs(int x) {
  pos[x] = ++dfsclk;
  int p;
  for (p = fst[x]; p; p = nxt[p]) {
    int y = pnt[p];
    if (y != fa[x]) {
      if (!pos[y]) {
        fa[y] = x;
        c[y] = len[p];
        dfs(y);
      } else if (pos[y] > pos[x]) {
        for (; y != x; y = fa[y]) {
          ok[y] = 0;
          a[++cnt] = y;
          b[cnt] = c[y];
        }
        ok[x] = 0;
        a[++cnt] = x;
        b[cnt] = len[p];
      }
    }
  }
}
void dp(int x, int last) {
  int p;
  for (p = fst[x]; p; p = nxt[p]) {
    int y = pnt[p];
    if (ok[y] && y != last) {
      dp(y, x);
      ans = max(ans, f[x] + f[y] + len[p]);
      f[x] = max(f[x], f[y] + len[p]);
    }
  }
}
int main() {
  scanf("%d", &n);
  int i, x, y, z;
  memset(ok, 1, sizeof(ok));
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
  }
  dfs(1);
  long long sum = 0, mx = 0;
  for (i = 1; i <= cnt; i++) dp(a[i], 0);
  for (i = 1; i <= cnt; i++) {
    sum += b[i - 1];
    u1[i] = max(u1[i - 1], f[a[i]] + sum);
    v1[i] = max(v1[i - 1], f[a[i]] + sum + mx);
    mx = max(mx, f[a[i]] - sum);
  }
  long long tmp = b[cnt];
  sum = mx = b[cnt] = 0;
  for (i = cnt; i; i--) {
    sum += b[i];
    u2[i] = max(u2[i + 1], f[a[i]] + sum);
    v2[i] = max(v2[i + 1], f[a[i]] + sum + mx);
    mx = max(mx, f[a[i]] - sum);
  }
  long long mn = v1[cnt];
  for (i = 1; i < cnt; i++)
    mn = min(mn, max(max(v1[i], v2[i + 1]), u1[i] + u2[i + 1] + tmp));
  ans = max(ans, mn);
  cout << ans << endl;
  return 0;
}
