#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=1e5+5;
ll ans;
int n,rt1,rt2,B0,BB[N],B[N<<1][3];
void link(int u,int v,int w)
{
	B[++B0][1]=v,B[B0][0]=BB[u],B[B0][2]=w,BB[u]=B0;
}
int findrt(int v,int fr=1)
{
	int num=1,mx=0;
	efo(i,v,u) if(u!=fr)
	{
		int t=findrt(u,v);
		mx=max(mx,t),num+=t;
	}
	if(mx<=n/2 && n-num<=n/2)
	{
		if(!rt1) rt1=v;
		else rt2=v;
	}
	return num;
}
void dfs(int v,int fr,ll s=0)
{
	ans+=s;
	efo(i,v,u) if(u!=fr) dfs(u,v,s+B[i][2]);
}
int main()
{
	int x,y,z;
	n=read();
	fo(i,1,n-1) x=read(),y=read(),z=read(),link(x,y,z),link(y,x,z);
	findrt(1);
	dfs(rt1,rt1);
	int mn=1e9;
	if(rt2)
		efo(i,rt1,v) if(v==rt2)
		{
			printf("%lld\n",ans+ans-B[i][2]);
			return 0;
		}
	efo(i,rt1,v) mn=min(mn,B[i][2]);
	printf("%lld",ans+ans-mn);
	return 0;
}
### Prompt

In CPP, your task is to solve the following problem:

There is a tree with N vertices, numbered 1 through N. The i-th edge in this tree connects Vertices A_i and B_i and has a length of C_i.

Joisino created a complete graph with N vertices. The length of the edge connecting Vertices u and v in this graph, is equal to the shortest distance between Vertices u and v in the tree above.

Joisino would like to know the length of the longest Hamiltonian path (see Notes) in this complete graph. Find the length of that path.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq A_i < B_i \leq N
* The given graph is a tree.
* 1 \leq C_i \leq 10^8
* All input values are integers.

Input

Input is given from Standard Input in the following format:


N
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{N-1} B_{N-1} C_{N-1}


Output

Print the length of the longest Hamiltonian path in the complete graph created by Joisino.

Examples

Input

5
1 2 5
3 4 7
2 3 3
2 5 2


Output

38


Input

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


Output

132

### Response

```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=1e5+5;
ll ans;
int n,rt1,rt2,B0,BB[N],B[N<<1][3];
void link(int u,int v,int w)
{
	B[++B0][1]=v,B[B0][0]=BB[u],B[B0][2]=w,BB[u]=B0;
}
int findrt(int v,int fr=1)
{
	int num=1,mx=0;
	efo(i,v,u) if(u!=fr)
	{
		int t=findrt(u,v);
		mx=max(mx,t),num+=t;
	}
	if(mx<=n/2 && n-num<=n/2)
	{
		if(!rt1) rt1=v;
		else rt2=v;
	}
	return num;
}
void dfs(int v,int fr,ll s=0)
{
	ans+=s;
	efo(i,v,u) if(u!=fr) dfs(u,v,s+B[i][2]);
}
int main()
{
	int x,y,z;
	n=read();
	fo(i,1,n-1) x=read(),y=read(),z=read(),link(x,y,z),link(y,x,z);
	findrt(1);
	dfs(rt1,rt1);
	int mn=1e9;
	if(rt2)
		efo(i,rt1,v) if(v==rt2)
		{
			printf("%lld\n",ans+ans-B[i][2]);
			return 0;
		}
	efo(i,rt1,v) mn=min(mn,B[i][2]);
	printf("%lld",ans+ans-mn);
	return 0;
}
```