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 = 'n=int(input())\r\ncost=[]\r\nd={}\r\nval_desc=[0]*n\r\nvisited=set()\r\nvisited.add(0)\r\ndfstack=[]\r\ndesc = [[False for i in range(n)] for i in range(n)]\r\nfor i in range(n):\r\n\tcost.append(int(input()))\r\n\td[i]=[]\r\n\r\nfor i in range(n-1):\r\n\tj,k=list(map(int,input().split()))\r\n\td[j-1].append(k-1)\r\n\td[k-1].append(j-1)\r\n\r\ndef dfs(u):\r\n\tval_desc[u]+=cost[u]\r\n\tdfstack.append(u)\r\n\tfor i in dfstack:\r\n\t\tdesc[u][i]=True\r\n\tfor i in d[u]:\r\n\t\tif i not in visited:\r\n\t\t\tvisited.add(i)\r\n\t\t\tdfs(i)\r\n\t\t\tval_desc[u]+=val_desc[i]\t\t\t\r\n\tdfstack.pop(-1)\r\n\r\ndfs(0)\r\nmp=10**9\r\ncoco=sum(cost)\r\nfor i in range(n):\r\n\tfor j in range(i+1,n):\r\n\t\tvali=val_desc[i]\r\n\t\tvalj=val_desc[j]\r\n\t\tif desc[i][j]:\r\n\t\t\tvalj-=val_desc[i]\r\n\t\tif desc[j][i]:\r\n\t\t\tvali-=val_desc[j]\r\n\t\tp=max(vali,valj,coco-vali-valj)\r\n\t\tmp=min(mp,p)\r\n#print(desc)\r\n#print(val_desc)\r\n#print\r\nprint(mp)\r\n\r\n\r\n\t\r\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13619