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 *v*<sub class="lower-index">*i*</sub>. In one move you can apply the following operation:
 1.  Select the subtree of the given tree that includes the vertex with number 1. 1.  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.
The first line of the input contains *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>). Each of the next *n* - 1 lines contains two integers *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub> ≤ *n*; *a*<sub class="lower-index">*i*</sub> ≠ *b*<sub class="lower-index">*i*</sub>) indicating there's an edge between vertices *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub>. It's guaranteed that the input graph is a tree. 

The last line of the input contains a list of *n* space-separated integers *v*<sub class="lower-index">1</sub>, *v*<sub class="lower-index">2</sub>, ..., *v*<sub class="lower-index">*n*</sub> (|*v*<sub class="lower-index">*i*</sub>| ≤ 10<sup class="upper-index">9</sup>).
import os, sys
from io import BytesIO, IOBase
from collections import *


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


class dict(dict):
    def __missing__(self, key):
        return 0


class graph:
    def __init__(self, n):
        self.n, self.gdict = n, [[] for _ in range(n + 1)]

    def addEdge(self, node1, node2, w=None):
        self.gdict[node1].append(node2)
        self.gdict[node2].append(node1)

    def solve(self, i):
        new = self.pos[i] - self.neg[i] + a[i - 1]
        if new > 0:
            self.neg[i] += new
        else:
            self.pos[i] += -new

    def subtree(self, v):
        queue, visit, child = deque([v]), [False] * (n + 1), []
        visit[v], nodes, parent = True, [0] * (n + 1), [-1] * (n + 1)
        self.pos, self.neg = [0] * (n + 1), [0] * (n + 1)

        while queue:
            s = queue.popleft()

            for i1 in self.gdict[s]:
                if not visit[i1]:
                    queue.append(i1)
                    visit[i1] = True
                    child.append(i1)
                    parent[i1] = s

        for i in child[::-1]:
            self.solve(i)
            self.pos[parent[i]] = max(self.pos[parent[i]], self.pos[i])
            self.neg[parent[i]] = max(self.neg[parent[i]], self.neg[i])

        self.solve(1)
        print(self.pos[1] + self.neg[1])


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp(dtype) for _ in range(n)]
inp_enu = lambda dtype: [(i, x) for i, x in enumerate(inp(dtype))]
inp_enus = lambda dtype, n: [[i] + inp(dtype) for i in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b

n = int(input())
g = graph(n)
for _ in range(n - 1):
    u, v = inp(int)
    g.addEdge(u, v)

a = inp(int)
g.subtree(1)
