Problem: 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 p1, p2, ..., pn (1 ≤ pi ≤ n), DZY defines f(p) as <image>. 

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 xj 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 ai, bi, ci (1 ≤ ai, bi ≤ n; 1 ≤ ci ≤ 10000), denoting an edge between ai and bi with length ci. 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 xj (1 ≤ xj ≤ 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].

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O8")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 3e3 + 20, mod = 1e9 + 7, inf = 2e9, maxq = 1e5 + 30;
const long double eps = 0.0000001;
long long int poww(long long int a, long long int b) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % mod, b / 2) % mod
                      : poww(a * a % mod, b / 2) % mod));
}
pair<int, pair<long long int, long long int> > edge[N];
vector<int> adj[N];
int ans[N];
vector<pair<long long int, long long int> > comp[N];
int par[N], cnt[N], t[N];
int getpar(int v) {
  if (par[v] == v) return v;
  return par[v] = getpar(par[v]);
}
void merge(int u, int v, int w) {
  u = getpar(u);
  v = getpar(v);
  sort(comp[u].begin(), comp[u].end());
  sort(comp[v].begin(), comp[v].end());
  if (comp[u].size() < comp[v].size()) swap(u, v);
  long long int p = 0;
  int sz = comp[u].size();
  for (pair<long long int, long long int> vert : comp[v]) {
    t[vert.second] = 0;
    while (p < sz && t[vert.second] < cnt[vert.second]) {
      t[vert.second]++;
      t[ans[comp[u][p].second]]--;
      comp[u][p].first = w;
      ans[comp[u][p].second] = vert.second;
      p++;
    }
  }
  p = 0;
  sz = comp[v].size();
  for (pair<long long int, long long int> vert : comp[u]) {
    while (p < sz && t[vert.second] < cnt[vert.second]) {
      t[vert.second]++;
      t[ans[comp[v][p].second]]--;
      comp[v][p].first = w;
      ans[comp[v][p].second] = vert.second;
      p++;
    }
    if (p == sz) break;
  }
  while (!(comp[v].empty())) {
    pair<long long int, long long int> vert = comp[v].back();
    comp[v].pop_back();
    comp[u].push_back(vert);
  }
  par[v] = u;
  return;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u, w;
    cin >> v >> u >> w;
    if (v > u) swap(v, u);
    edge[i] = {w, {v, u}};
    adj[v].push_back(u);
    adj[u].push_back(v);
    comp[i + 1].push_back({0, i + 1});
    par[i + 1] = i + 1;
  }
  comp[n].push_back({0, n});
  par[n] = n;
  for (int i = 1; i < n + 1; i++) cin >> cnt[i];
  sort(edge, edge + n - 1);
  for (int i = 0; i < n - 1; i++) {
    merge(edge[i].second.first, edge[i].second.second, edge[i].first);
    getpar(1);
  }
  long long int out = inf;
  for (int i = 1; i < n + 1; i++) {
    if (!(comp[i].empty())) {
      for (pair<long long int, long long int> v : comp[i])
        out = min(out, v.first);
    }
  }
  cout << out;
  return 0;
}