#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
const long long INF = 1e18 + 10;
int n, k;
vector<pair<int, int>> e[MAX];
vector<pair<int, int>> cir;
pair<int, int> par[MAX];
long long d[MAX], pre_diam[MAX], pre_far[MAX], suf_diam[MAX], suf_far[MAX],
    part_len[MAX];
bool visit[MAX];
int cir_start, cir_end, cir_len;
int ru, rv;
long long f[MAX];
long long answer;
void init() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int u, v, l;
    cin >> u >> v >> l;
    e[u].push_back({v, l});
    e[v].push_back({u, l});
  }
}
void dfs_cir(int u) {
  visit[u] = true;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].first;
    int l = e[u][i].second;
    if (v != par[u].first) {
      if (visit[v]) {
        cir_start = v;
        cir_end = u;
        cir_len = l;
      } else {
        par[v] = {u, l};
        dfs_cir(v);
      }
    }
    if (cir_end != 0) return;
  }
}
void find_circle() {
  dfs_cir(1);
  cir.push_back({cir_end, par[cir_end].second});
  while (cir.back().first != cir_start) {
    int x, l;
    x = par[cir.back().first].first;
    if (x == cir_start)
      l = cir_len;
    else
      l = par[x].second;
    cir.push_back({x, l});
  }
  k = cir.size();
}
long long dfs_d(int u, int x1, int x2) {
  long long res = 0;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].first;
    int l = e[u][i].second;
    if (v != x1 && v != x2) {
      res = max(res, dfs_d(v, u, 0) + l);
    }
  }
  return res;
}
void calc_d() {
  for (int i = 0; i < k; i++) {
    int v1, v2;
    if (i > 0)
      v1 = cir[i - 1].first;
    else
      v1 = cir.back().first;
    if (i < k - 1)
      v2 = cir[i + 1].first;
    else
      v2 = cir.front().first;
    d[i] = dfs_d(cir[i].first, v1, v2);
  }
}
void calc_pre() {
  part_len[0] = d[0];
  pre_far[0] = d[0];
  long long from_first = 0;
  for (int i = 1; i < k; i++) {
    pre_diam[i] =
        max(pre_diam[i - 1], part_len[i - 1] + cir[i - 1].second + d[i]);
    from_first += cir[i - 1].second;
    pre_far[i] = max(pre_far[i - 1], from_first + d[i]);
    part_len[i] = max(part_len[i - 1] + cir[i - 1].second, d[i]);
  }
}
void calc_suf() {
  part_len[k - 1] = d[k - 1];
  suf_far[k - 1] = d[k - 1] + cir[k - 1].second;
  long long from_first = cir[k - 1].second;
  for (int i = k - 2; i >= 0; i--) {
    suf_diam[i] = max(suf_diam[i + 1], part_len[i + 1] + cir[i].second + d[i]);
    from_first += cir[i].second;
    suf_far[i] = max(suf_far[i + 1], from_first + d[i]);
    part_len[i] = max(part_len[i + 1] + cir[i].second, d[i]);
  }
}
void pre_compute() {
  calc_d();
  calc_pre();
  calc_suf();
}
void remove_edge(vector<pair<int, int>>& a, int v) {
  for (int i = 0; i < a.size(); i++)
    if (a[i].first == v) {
      for (int j = i; j < a.size() - 1; j++) {
        a[j] = a[j + 1];
      }
      break;
    }
  a.resize(a.size() - 1);
}
void remove_edge() {
  ru = rv = -1;
  long long res = INF;
  suf_diam[k] = suf_far[k] = -INF;
  for (int i = 0; i < k; i++) {
    long long max_val =
        max(max(pre_diam[i], suf_diam[i + 1]), pre_far[i] + suf_far[i + 1]);
    if (max_val < res) {
      ru = cir[i].first;
      if (i < k - 1)
        rv = cir[i + 1].first;
      else
        rv = cir[0].first;
      res = max_val;
    }
  }
  remove_edge(e[ru], rv);
  remove_edge(e[rv], ru);
}
void dfs(int u, int p) {
  long long v1 = 0, v2 = 0;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].first;
    int l = e[u][i].second;
    if (v != p) {
      dfs(v, u);
      f[u] = max(f[u], f[v] + l);
      f[v] += l;
      if (f[v] > v1) {
        v2 = v1;
        v1 = f[v];
      } else
        v2 = max(v2, f[v]);
    }
  }
  answer = max(answer, v1 + v2);
}
void find_result() {
  dfs(1, 0);
  cout << answer;
}
void process() {
  find_circle();
  pre_compute();
  remove_edge();
  find_result();
}
int main() {
  ios_base::sync_with_stdio(false);
  init();
  process();
}
