Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!

He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these n cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities.

All cities are numbered 1 to n. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city.

Help Shapur find how much He should travel.

Input

First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities.

Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.

Output

A single integer number, the minimal length of Shapur's travel.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples

Input

3
1 2 3
2 3 4


Output

7


Input

3
1 2 3
1 3 3


Output

9
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;


public class Main {
	static Scanner sc = new Scanner(System.in);
	static ArrayList<Integer>[] adj;
	static boolean[] visited;
	static int[] reachable;
	static int[] order;
	static int count;
		/*public static void main(String[] args) throws IOException {
		while(true)
		{
			int n=sc.nextInt();
			int m=sc.nextInt();
			int[] a= new int[n];
			ArrayList<Integer>[] adj= new ArrayList[1000000];
			
			for (int i = 0; i < adj.length; i++) {
				adj[i]= new ArrayList<Integer>();
			}
			for (int i = 0; i < a.length; i++) {
				a[i]=sc.nextInt();
				adj[a[i]-1].add(i+1);
			}
			
			for (int i = 0; i < m; i++) {
				int k=sc.nextInt();
				int v=sc.nextInt();
				if(k<=adj[v-1].size())
				{
					System.out.println(adj[v-1].get(k-1));
				}
				else
				{
					System.out.println(0);
				}
					
					
			}
			if(!sc.ready())
			{
				break;
			}
		}*/
	
	/*public static void main(String[] args) throws IOException {
		int times=sc.nextInt();
		
		for (int i = 0; i < times; i++) {
			int n= sc.nextInt();
			ArrayList<Integer>[] adj= new ArrayList[n];
			
			for (int j = 0; j < adj.length; j++) {
				adj[j]=new ArrayList<Integer>();
			}
			
			for (int j = 0; j < adj.length; j++) {
				String[] a=sc.nextLine().split(" ");
			
				for (int k = 0; k < a.length; k++) {
					adj[j].add(Integer.parseInt(a[k])-1);
				}
			}
			int min=-1;
			for (int j = 0; j < adj.length; j++) {
				if(min==-1 || min>adj[j].size())
				{
					min=adj[j].size();
				}
				
			}
			boolean first=true;
			for (int j = 0; j < adj.length; j++) {
				if(adj[j].size()==min)
				{
					int output=j+1;

					if(first==true)
					{
						System.out.print(output);
						first=false;
					}
					else
					{
						System.out.print(" " + output);
					}
					
				}
			}
			System.out.println();
	}*/
	
	/*public static void main(String[] args) throws IOException{
		int t=sc.nextInt();
		
		for (int i = 0; i < t; i++) {
			int n=sc.nextInt();
			int m=sc.nextInt();
			
			int[][] adj= new int[n][m];
			
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < m; k++) {
					adj[j][k]=sc.nextInt();
				}
			}
			
			boolean flag=true;
		
			ArrayList<Integer>[] adjList= new ArrayList[n];
			
			for (int j = 0; j < adjList.length; j++) {
				adjList[j]=new ArrayList<Integer>();
			}
			for (int j = 0; j < m; j++) {
				ArrayList<Integer> a= new ArrayList<Integer>();
				for (int k = 0; k < n; k++) {
					if(adj[k][j]==1)
					{
						a.add(k);
					}
				}
				if(a.size()!=2)
				{
					flag=false;break;
				}
				int v1=a.remove(0);
				int v2=a.remove(0);
				if(adjList[v1].contains(v2))
				{
					flag=false;break;
				}
				adjList[v1].add(v2);
				adjList[v2].add(v1);
			}
			if(flag)
			{
				System.out.println("Yes");
			}
			else
			{
				System.out.println("No");
			}
	}
		
	}*/
	
	/*public static void main(String[] args) throws IOException {
		int t=sc.nextInt();
		TreeMap<Character, Integer> map =new TreeMap<Character, Integer>();
		char c='A';
		for (int i = 0; i < 26; i++) {
			map.put(c++, i);
		}
		
		for (int i = 0; i < t; i++) {
			boolean[] v = new boolean[26];
			adj= new ArrayList[26];
			for (int j = 0; j < adj.length; j++) {
				adj[j]=new ArrayList<Integer>();
			}
			String s=sc.nextLine();
			while(s.charAt(0)!='*')
			{
				char v1=s.charAt(1);
				char v2=s.charAt(3);
				adj[map.get(v1)].add(map.get(v2));
				adj[map.get(v2)].add(map.get(v1));
				s=sc.nextLine();
			}
			s=sc.nextLine();
			for (int j = 0; j < s.length(); j=j+2) {
				v[map.get(s.charAt(j))]=true;
			}
			
			int nTrees=0;
			int nAcorns=0;
			visited= new boolean[26];
			for (int j = 0; j < adj.length; j++) {
				if(v[j] && !visited[j])
				{
					count=0;
					dfs(j);
					if(count==1)
					{
						nAcorns++;
					}
					else
					{
						nTrees++;
					}
				}
			}
			System.out.println("There are " + nTrees + " tree(s) and " + nAcorns + " acorn(s).");
		}
	}*/
	
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		
		while(n!=0)
		{
			adj= new ArrayList[n];
			
			for (int i = 0; i < adj.length; i++) {
				adj[i]=new ArrayList<Integer>();
			}
			
			int v=sc.nextInt();
			while(v!=0) {
				int neighbor=sc.nextInt();
				while(neighbor!=0)
				{
					adj[v-1].add(neighbor-1);
					neighbor=sc.nextInt();
				}
				v=sc.nextInt();
			}
			
			int q=sc.nextInt();
			for (int j = 0; j < q; j++) {
				visited= new boolean[n];
				int v2=sc.nextInt();
				for (int i = 0; i < adj[v2-1].size(); i++) {
					if(!visited[adj[v2-1].get(i)])
					{
						dfs(adj[v2-1].get(i));
					}
				}
				int count=0;
				for (int k = 0; k < visited.length; k++) {
					if(!visited[k])
					{
						count++;
					}
				}
				System.out.print(count);
				for (int k = 0; k <visited.length; k++) {
					if(!visited[k])
					{
						int output=k+1;
						System.out.print(" " + output);
					}
				}
				System.out.println();
			}
			
			n=sc.nextInt();
		}
	}*/
	
	static ArrayList<Integer>[] adjList;
	static boolean circle;
	static int iCircle;
	public static int dfs2(int v)
	{
		order[v]=++count;
		if(order[adjList[v].get(0)]==0)
		{
			int n=dfs2(adjList[v].get(0));
			if(circle)
			{
				reachable[v]=n;
			}
			else
			{
				reachable[v]=n+1;
			}
		}
		else
		{
			if(order[adjList[v].get(0)]!=-1)
			{
				reachable[v]=order[v]-order[adjList[v].get(0)]+1;
				circle=true;
				iCircle=adjList[v].get(0);
			}
			else
			{
				reachable[v]=1+reachable[adjList[v].get(0)];
			}
		}
		order[v]=-1;
		if(circle && v==iCircle)
		{
			circle=false;
		}
		return reachable[v];
	}
	/*public static void main(String[] args) throws IOException {
		int T=sc.nextInt();
		
		for (int i = 1; i <= T; i++) {
			int N=sc.nextInt();
			
			adjList = new ArrayList[N];
			
			for (int j = 0; j < adjList.length; j++) {
				adjList[j]=new ArrayList<Integer>();
			}
			
			for (int j = 0; j < N; j++) {
				int u=sc.nextInt();
				int v=sc.nextInt();
				adjList[u-1].add(v-1);
			}
			order= new int[N];
			reachable=new int[N];
			for (int j = 0; j < adjList.length; j++) {
				if(order[j]==0)
				{
					count=0;
					dfs2(j);
					
				}			
			}
			int max=-1;
			int index=-1;
			for (int j = 0; j < reachable.length; j++) {
				if(max==-1 || reachable[j]>max)
				{
					max=reachable[j];
					index=j;
				}
			}
			index++;
			System.out.println("Case " + i + ": " + index);
		}
	}*/
	static int depth;
	public static void dfs3(int v, int d)
	{
		visited[v]=true;
		//System.out.println("Depth: " + d);
		for (int i = 0; i < adj[v].size(); i++) {
			if(!visited[adj[v].get(i)])
			{
				//System.out.println("Visiting " + adj[v].get(i));
				 dfs3(adj[v].get(i), d + 1);
				// System.out.println("backtracking to " + v);
			}
		}
		if(depth<d)
		{
			depth=d;
			//System.out.println("max depth so far: " + depth);
		}
		
	}
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		adj=new ArrayList[n];
		ArrayList<Integer> superManagers= new ArrayList<Integer>();
		
		for (int i = 0; i < adj.length; i++) {
			adj[i]=new ArrayList<Integer>();
		}
		for (int i = 0; i < adj.length; i++) {
			int t=sc.nextInt();
			if(t==-1)
			{
				superManagers.add(i);
			}
			else
			{
				adj[i].add(t-1);
				adj[t-1].add(i);
			}
			
		}
		visited=new boolean[n];
		depth=0;
		while(!superManagers.isEmpty())
		{
			int v=superManagers.remove(0);
			//System.out.println("Entering from " + v);
			dfs3(v, 1);
		}

		System.out.println(depth);
	}*/
	
	/*public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		int m=sc.nextInt();
		
		int[] colors= new int[n];
		adj= new ArrayList[n];
		
		for (int i = 0; i < adj.length; i++) {
			adj[i]=new ArrayList<Integer>();
		}
		for (int i = 0; i < colors.length; i++) {
			colors[i]=sc.nextInt();
		}
		
		for (int i = 0; i < m; i++) {
			int u=sc.nextInt();
			int v=sc.nextInt();
			adj[u-1].add(v-1);
			adj[v-1].add(u-1);
		}
	
		TreeSet<Integer>[] arr= new TreeSet[100000];
		
		for (int i = 0; i < arr.length; i++) {
			arr[i]=new TreeSet<Integer>();
		}
		for (int i = 0; i < adj.length; i++) {
			int vColor=colors[i];
			arr[vColor-1].add(vColor-1);
			for (int j = 0; j < adj[i].size(); j++) {
					arr[vColor-1].add(colors[adj[i].get(j)]-1);
			}
		}
		
		int max=-1;
		int indx=-1;
		for (int i = 0; i < arr.length; i++) {
			if((max==-1 || max<arr[i].size()-1) && arr[i].size()!=0)
			{
				max=arr[i].size()-1;
				indx=i+1;
			}
		}
		System.out.println(indx);
	}*/
	static long sum;
	static long max;
	static int nLeaves;
	public static void dfs(int v, int l)
	{
		visited[v]=true;
		
		for (int i = 0; i < array[v].size(); i++) {
			if(!visited[array[v].get(i).end])
			{
				sum+=array[v].get(i).weight;
				dfs(array[v].get(i).end,l + array[v].get(i).weight);
			}
		}
		if(l>max)
		{
			max=l;
		}
		if (array[v].size()==1 && v!=0) {
			nLeaves++;
		}
	}

	static ArrayList<Edge>[] array;
	public static void main(String[] args) throws IOException {
		int n=sc.nextInt();
		array= new ArrayList[n];
		
		for (int i = 0; i < array.length; i++) {
			array[i]=new ArrayList<Main.Edge>();
		}
		for (int i = 0; i < n-1; i++) {
			int x=sc.nextInt();
			int y=sc.nextInt();
			int w=sc.nextInt();
			array[x-1].add(new Edge(y-1, w));
			array[y-1].add(new Edge(x-1, w));
		}
		sum=0;
		max=0;
		nLeaves=0;
		visited=new boolean[n];
		dfs(0,0);
		if(nLeaves==1)
		{
			System.out.println(sum);
		}
		else
		{
			System.out.println(2*sum-max);
		}
	}
	static class Edge
	{
		int end;
		int weight;

		public Edge(int e, int w) {
			// TODO Auto-generated constructor stub
			end=e;
			weight=w;
			}
		
		public String toString()
		{
			return "(" + end + "," + weight + ")";
		}
		
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			int start = 0;
			boolean dec = false, neg = false;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}
}
