DZY loves planting, and he enjoys solving tree problems.

DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every z.

For every integer sequence p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ n), DZY defines f(p) as $\operatorname{min}_{i = 1}^{n} g(i, p_{i})$. 

DZY wants to find such a sequence p that f(p) has maximum possible value. But there is one more restriction: the element j can appear in p at most x_{j} times.

Please, find the maximum possible f(p) under the described restrictions.


-----Input-----

The first line contains an integer n (1 ≤ n ≤ 3000).

Each of the next n - 1 lines contains three integers a_{i}, b_{i}, c_{i} (1 ≤ a_{i}, b_{i} ≤ n; 1 ≤ c_{i} ≤ 10000), denoting an edge between a_{i} and b_{i} with length c_{i}. It is guaranteed that these edges form a tree.

Each of the next n lines describes an element of sequence x. The j-th line contains an integer x_{j} (1 ≤ x_{j} ≤ n).


-----Output-----

Print a single integer representing the answer.


-----Examples-----
Input
4
1 2 1
2 3 2
3 4 3
1
1
1
1

Output
2

Input
4
1 2 1
2 3 2
3 4 3
4
4
4
4

Output
3



-----Note-----

In the first sample, one of the optimal p is [4, 3, 2, 1].

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'n = int(input())\nedges = [[int(x) for x in input().split()] for i in range(n-1)]\nedges = sorted(edges)\nuse_count = [0]+[int(input()) for i in range(n)]\nlo,hi = 0,10000\ndef getpar(par,u):\n    if par[par[u]] == par[u]:\n        return par[u]\n    par[u] = getpar(par,par[u])\n    return par[u]\ndef unite(par,sz,use,u,v):\n    u = getpar(par,u)\n    v = getpar(par,v)\n    par[u] = v\n    sz[v] += sz[u]\n    use[v] += use[u]\ndef solve(fp):\n    par = [i for i in range(n+1)]\n    sz = [1 for i in range(n+1)]\n    use = [use_count[i] for i in range(n+1)]\n    for edge in edges:\n        if edge[2] < fp:\n            unite(par,sz,use,edge[0],edge[1])\n    total_use = sum(use_count)\n    for i in range(n+1):\n        p = getpar(par,i)\n        if(p == i):\n            if(total_use - use[p] < sz[p]):\n                return False\n    return True\nwhile lo < hi:\n    mid = (lo+hi+1)//2\n    if solve(mid):\n        lo = mid\n    else:\n        hi = mid-1\nprint(lo)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13007