A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.

A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.

You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation:

  1. Select the subtree of the given tree that includes the vertex with number 1. 
  2. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. 



Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.

Input

The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. 

The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).

Output

Print the minimum number of operations needed to solve the task.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3
1 2
1 3
1 -1 1


Output

3
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Stack;

/**
 * Works good for CF
 * @author cykeltillsalu
 */
public class D {

	//some local config
	static boolean test = false;
	static String testDataFile = "testdata.txt";
	static String feedFile = "feed.txt";
	CompetitionType type = CompetitionType.CF;
	private static String ENDL = "\n";

	class State{
		
	}
	
	// solution
	private void solve() throws Throwable {
		
		int n = iread();
		
		List[] edges = new List[n+1];
		long[] w = new long[n+1]; 
		long[] numdown = new long[n+1], numup = new long[n+1];
		for (int i = 0; i < edges.length; i++) {
			edges[i] = new ArrayList();
		}
		
		for (int i = 0; i < n-1; i++) {
			int a = iread(), b = iread();
			edges[a].add(b);
			edges[b].add(a);
		}
		for (int i = 0; i < n; i++) {
			w[i+1] = lread();
		}
		List[] parent = new List[n+1];
		for (int i = 0; i < n+1; i++) {
			parent[i] = new ArrayList();
		}
		List[] children = new List[n+1];
		Stack<Integer> stack = new Stack<Integer>();
		stack.push(1);
		boolean[] visited = new boolean[n+1];
		int[] childcnt = new int[n+1];
		visited[1] = true;
		while(stack.size() > 0){
			Integer pop = stack.pop();
			for (int i = 0; i < edges[pop].size(); i++) {
				Integer v = (Integer) edges[pop].get(i);
				if(!visited[v]){
					parent[v].add(pop);
//					children[pop].add(v);
					childcnt[pop] ++;
					stack.push(v);
					visited[v] = true;
				}
			}
		}
		
		LinkedList<Integer> que = new LinkedList();
		for (int i = 1; i <= n; i++) {
			if(childcnt[i] == 0){
				que.offer(i);
			}
		}
		while(que.size() > 0){
			int pop = que.poll();
			if(pop == 1){
				continue;
			}
			int p = (Integer) parent[pop].get(0);
			childcnt[p] --;
			if(childcnt[p] == 0){
				que.offer(p);
			}
			w[pop] += numup[pop] - numdown[pop];
			if(w[pop] < 0){
				numup[pop] += Math.abs(w[pop]);
			} else {
				numdown[pop] += w[pop];
			}
			
			numup[p] = Math.max(numup[p], numup[pop]);
			numdown[p] = Math.max(numdown[p], numdown[pop]);
			
		}
		
		long net = w[1] + numup[1] - numdown[1];
		System.out.println(Math.abs(net) + numup[1] + Math.abs(numdown[1]));
		out.flush();
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) throws Throwable {
		
		if(test){ //run all cases from testfile:
			BufferedReader testdataReader = new BufferedReader(new FileReader(testDataFile));
			String readLine = testdataReader.readLine();
			int casenr = 0;
			out: while (true) {
				BufferedWriter w = new BufferedWriter(new FileWriter(feedFile));
				if(!readLine.equalsIgnoreCase("input")){
					break;
				}
				while (true) {
					readLine = testdataReader.readLine();
					if(readLine.equalsIgnoreCase("output")){
						break;
					}
					w.write(readLine + "\n");
				}
				w.close();
				System.out.println("Answer on case "+(++casenr)+": ");
				
				new D().solve();
				System.out.println("Expected answer: ");
				
				
				while (true) {
					readLine = testdataReader.readLine();
					
					if(readLine == null){
						break out;
					}
					if(readLine.equalsIgnoreCase("input")){
						break;
					}
					System.out.println(readLine);
				}
				System.out.println("----------------");
			}
			testdataReader.close();
		} else { // run on server
			new D().solve();
		}
		out.close();
	}

	public D() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(feedFile)));
		}
	}

	InputStreamReader inp = new InputStreamReader(System.in);
	BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
	
	enum CompetitionType {CF, OTHER};
}