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>
using namespace std;
const long long INF64 = ((long long)1E18);
const int INF = 1E9 + 7;
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  out << "(" << pair.first << ", " << pair.second << ")";
  return out;
}
int dost[3004], n;
vector<pair<int, int> > t[3004];
vector<int> weights;
bool done[3004];
int a, b, W;
void go(int act, int papa) {
  done[act] = 1;
  a += 1;
  b += dost[act];
  for (__typeof((t[act]).begin()) it = ((t[act]).begin()); it != (t[act]).end();
       ++it)
    if (it->second < W && it->first != papa) {
      go(it->first, act);
    }
}
bool comp(const pair<int, int>& l, const pair<int, int>& r) {
  return l.first - l.second > r.first - r.second;
}
bool moge(int w) {
  W = w;
  memset((done), 0, sizeof(done));
  vector<pair<int, int> > todo;
  for (int i = (1); i <= (n); ++i)
    if (!done[i]) {
      a = b = 0;
      go(i, -1);
      todo.push_back(make_pair(a, b));
    }
  sort((todo).begin(), (todo).end(), comp);
  {
    if (0)
      cerr << "W"
           << " = " << W << endl;
  };
  {
    if (0) {
      cerr << "todo"
           << " = ";
      for (__typeof(((todo)).begin()) it = (((todo)).begin());
           it != ((todo)).end(); ++it)
        cerr << *it << ", ";
      cout << endl;
    }
  };
  int trzeba = 0;
  int mamy = 0;
  int allsum = 0;
  for (__typeof((todo).begin()) it = ((todo).begin()); it != (todo).end(); ++it)
    allsum += it->second;
  for (__typeof((todo).begin()) it = ((todo).begin()); it != (todo).end();
       ++it) {
    if (it->first > allsum - it->second) return 0;
  }
  return 1;
  return trzeba <= 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = (1); i <= (n - 1); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    weights.push_back(c);
    t[a].push_back(make_pair(b, c));
    t[b].push_back(make_pair(a, c));
  }
  for (int i = (1); i <= (n); ++i) cin >> dost[i];
  sort((weights).begin(), (weights).end());
  int best = 0, s = 0, e = ((int)(weights).size()) - 1;
  while (s <= e) {
    int q = (s + e) / 2;
    if (moge(weights[q])) {
      best = weights[q];
      s = q + 1;
    } else
      e = q - 1;
  }
  cout << best << endl;
  return 0;
}