Problem: Year 20XX — a nuclear explosion has burned the world. Half the people on the planet have died. Fearful.

One city, fortunately, was not directly damaged by the explosion. This city consists of N domes (numbered 1 through N inclusive) and M bidirectional transportation pipelines connecting the domes. In dome i, Pi citizens reside currently and there is a nuclear shelter capable of protecting Ki citizens. Also, it takes Di days to travel from one end to the other end of pipeline i.

It has been turned out that this city will be polluted by nuclear radiation in L days after today. So each citizen should take refuge in some shelter, possibly traveling through the pipelines. Citizens will be dead if they reach their shelters in exactly or more than L days.

How many citizens can survive at most in this situation?



Input

The input consists of multiple test cases. Each test case begins with a line consisting of three integers N, M and L (1 ≤ N ≤ 100, M ≥ 0, 1 ≤ L ≤ 10000). This is followed by M lines describing the configuration of transportation pipelines connecting the domes. The i-th line contains three integers Ai, Bi and Di (1 ≤ Ai < Bi ≤ N, 1 ≤ Di ≤ 10000), denoting that the i-th pipeline connects dome Ai and Bi. There is at most one pipeline between any pair of domes. Finally, there come two lines, each consisting of N integers. The first gives P1 , . . ., PN (0 ≤ Pi ≤ 106) and the second gives K1 , . . ., KN (0 ≤ Ki ≤ 106).

The input is terminated by EOF. All integers in each line are separated by a whitespace.

Output

For each test case, print in a line the maximum number of people who can survive.

Example

Input

1 0 1
51
50
2 1 1
1 2 1
1000 0
0 1000
4 3 5
1 2 4
1 3 1
3 4 2
0 1000 1000 1000
3000 0 0 0


Output

50
0
3000

Solution (in CPP):

Solution:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_GN = MAX_N * 2 + 2;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

int n, m, l;
vpii nbrs[MAX_N];
int ps[MAX_N], ks[MAX_N];
vi rnbrs[MAX_GN];
int dists[MAX_GN], prvs[MAX_GN];
int caps[MAX_GN][MAX_GN], flows[MAX_GN][MAX_GN];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m >> l;
    if (cin.eof()) break;

    for (int i = 0; i < n; i++) nbrs[i].clear();
    
    for (int i = 0; i < m; i++) {
      int a, b, d;
      cin >> a >> b >> d;
      a--, b--;
      nbrs[a].push_back(pii(b, d));
      nbrs[b].push_back(pii(a, d));
    }

    for (int i = 0; i < n; i++) cin >> ps[i];
    for (int i = 0; i < n; i++) cin >> ks[i];

    int gn = 2 * n + 2;
    for (int i = 0; i < gn; i++) rnbrs[i].clear();

    for (int st = 0; st < n; st++) {
      for (int i = 0; i < n; i++) dists[i] = INF;
      dists[st] = 0;
      rnbrs[st].push_back(st + n);
      rnbrs[st + n].push_back(st);
      caps[st][st + n] = INF;
      caps[st + n][st] = 0;
      
      priority_queue<pii,vpii,greater<pii> > q;
      q.push(pii(0, st));

      while (! q.empty()) {
	pii u = q.top();
	q.pop();

	int ud = u.first;
	int ui = u.second;
	if (ud != dists[ui]) continue;

	vpii& nbru = nbrs[ui];
	for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	  int vi = vit->first;
	  int vd = ud + vit->second;
	  if (vd < l && dists[vi] > vd) {
	    dists[vi] = vd;
	    q.push(pii(vd, vi));
	    rnbrs[st].push_back(vi + n);
	    rnbrs[vi + n].push_back(st);
	    caps[st][vi + n] = INF;
	    caps[vi + n][st] = 0;
	  }
	}
      }
    }

    int st = 2 * n, gl = 2 * n + 1;

    for (int i = 0; i < n; i++) {
      rnbrs[st].push_back(i);
      caps[st][i] = ps[i];
      caps[i][st] = 0;
      rnbrs[i + n].push_back(gl);
      caps[i + n][gl] = ks[i];
      caps[gl][i + n] = 0;
    }
    memset(flows, 0, sizeof(flows));

    int max_flow = 0;

    for(;;) {
      for (int i = 0; i < gn; i++) dists[i] = INF, prvs[i] = -1;
      dists[st] = 0;

      priority_queue<pii,vpii,greater<pii> > q;
      q.push(pii(0, st));

      while (! q.empty()) {
	pii u = q.top();
	q.pop();

	int ud = u.first;
	int ui = u.second;
	if (ud != dists[ui]) continue;
	if (ui == gl) break;

	int vd = ud + 1;
	vi& rnbru = rnbrs[ui];
	for (vi::iterator vit = rnbru.begin(); vit != rnbru.end(); vit++) {
	  int vi = *vit;
	  int vc = caps[ui][vi] - flows[ui][vi];
	  if (vc > 0 && dists[vi] > vd) {
	    dists[vi] = vd;
	    prvs[vi] = ui;
	    q.push(pii(vd, vi));
	  }
	}
      }

      if (dists[gl] >= INF) break;

      int min_flow = INF;
      for (int i = gl; i != st; i = prvs[i]) {
	int& i0 = prvs[i];
	int flow = caps[i0][i] - flows[i0][i];
	if (min_flow > flow) min_flow = flow;
      }

      for (int i = gl; i != st; i = prvs[i]) {
	int& i0 = prvs[i];
	flows[i0][i] += min_flow;
	flows[i][i0] -= min_flow;
      }

      max_flow += min_flow;
    }

    cout << max_flow << endl;
  }

  return 0;
}