A key feature of the Siruseri railway network is that it has exactly one route between any pair of stations.
The government has chosen three contractors to run the canteens at the stations on the railway network. To ensure that there are no disputes between the contractors it has been decided that if two stations, say $A$ and $B$, are assigned to a particular contractor then all the stations that lie on the route from $A$ to $B$ will also be awarded to the same contractor.
The government would like the assignment of stations to the contractors to be as equitable as possible. The government has data on the number of passengers who pass through each station each year. They would like to assign stations so that the maximum number of passengers passing through any contractor's collection of stations is minimized.
For instance, suppose the railway network is as follows, where the volume of passenger traffic is indicated by the side of each station.

One possible assignment would to award stations $1$ and $3$ to one contractor (there by giving him a traffic of $35$ passengers), station $2$ to the second contractor (traffic of $20$) and stations $4, 5$ and $6$ to the third contractor (traffic of $100$). In this assignment, the maximum traffic for any one contractor is 100. On the other hand if we assigned stations $1, 2$ and $3$ to one contractor, station $4$ and $6$ to the second contractor and station $5$ to the third contractor the maximum traffic for any one contractor is $70$. You can check that you cannot do better. (The assignment $1$, $2$ and $3$ to one contractor, $4$ to the second contractor, and $5$ and $6$ to the third contractor has a lower value for the maximum traffic ($55$) but it is not a valid assignment as the route from $5$ to $6$ passes through $4$.)

-----Input:-----
The first line of the input contains one integer $N$ indicating the number of railways stations in the network. The stations are numbered $1,2,..., N$. This is followed by $N$ lines of input, lines $2,3,...,N+1$, indicating the volume of traffic at each station. The volume of traffic at station $i$, $1 \leq i \leq N$, is given by a single integer in line $i+1$. The next $N-1$ lines of input, lines $N+2, N+3, ..., 2 \cdot N$, describe the railway network. Each of these lines contains two integers, denoting a pair of stations that are neighbours.

-----Output:-----
The output should be a single integer, corresponding to the minimum possible value of the maximum traffic of any contractor among all valid assignment of the stations to the three contractors.

-----Constraints:-----
- $1 \leq N \leq 3000$.

-----Sample Input-----
6
10
20
25
40
30
30
4 5
1 3
3 4
2 3
6 4

-----Sample Output-----
70

```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 = "#for _ in range(int(input()):\n#n,m = map(int,input().split())\n#x = [int(w) for w in input().split()]\n#n = int(input())\n#x = [int(input()) for _ in range(n)]\n#for i in range(n):\n#dt = {} for i in x:dt[i] = dt.get(i,0)+1\n#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}\n\ndef dfs(v):\n    visited.add(v)\n    parents.append(v)\n    for u in parents:\n        desc[v][u] = True\n    for u in graph[v]:\n        if u not in visited:\n            dfs(u)\n            val[v] += val[u]\n    parents.pop()\n\n\nn = int(input())\ncost,graph,val = {},{},{}\n# val(i) is sum of cost of descendants of i\nfor i in range(1,n+1):\n    cost[i] = int(input())\n    graph[i] = []\n    val[i] = cost[i]\nfor _ in range(n-1):\n    a,b = map(int,input().split())\n    graph[a].append(b)\n    graph[b].append(a)\n\ndesc = [[False for i in range(n+1)] for i in range(n+1)]\n# desc(i,j) is true if i is descendant of j\nvisited = set()\nparents =[]   # Ancestors stack\n\n\ndfs(1)\ntotal = sum(cost.values())\nbest = float('inf')\nfor i in range(1,n):\n    for j in range(i+1,n+1):\n        split = 0\n        s1 = val[i]\n        s2 = val[j]\n        if desc[i][j]:\n            s2 -= val[i]\n        if desc[j][i]:\n            s1 -= val[j]\n        s3 = total-s1-s2\n        split = max(s1,s2,s3)\n        best = min(best,split)\nprint(best)        "
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13747