/*
思路:
可以将城市与首都之间抽象成一个无环连通图,即为一棵树
然后找出树的直径;
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int h[N];
const int M = 2*N;
int e[M],w[M],ne[M],idx;
int n;
int dist[N];
void dfs(int u,int f,int d)
{
dist[u] = d;
for(int i = h[u];i != -1; i = ne[i])
{
int j = e[i];
if(j != f) dfs(j,u,d+w[i]);
}
}
void add(int a,int b,int c)
{
w[idx] = c, e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
int main()
{
cin >> n;
memset(h,-1,sizeof h);
for(int i =0 ; i<n ;i++)
{
int a,b ,w ;cin >> a >> b >>w;
add(a,b,w); add(b,a,w);
}
dfs(1,-1,0); //第一次找最远点
int zyd = 0;
for(int i =1; i <= n ;i++)
{
if(dist[zyd] < dist[i]) zyd = i;
}
memset(dist,0,sizeof dist); //第二次找最远点
dfs(zyd,-1,0);
zyd = 0;
for(int i =1; i <= n ;i++)
{
if(dist[zyd] < dist[i]) zyd = i;
}
long long res = dist[zyd] * 10 + (dist[zyd] + 1ll) * dist[zyd] / 2;
cout << res;
}