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 <cstring>
#include <queue>
using namespace std;

const int N = 205, M = 50000, inf = 0x3fffffff;
int n, m, l, x, y, z, e, s, t, d[N][N], hd[N], to[M], f[M], nxt[M], ch[N];

void add(int x, int y, int z) {
	to[e] = y, nxt[e] = hd[x], f[e] = z, hd[x] = e++;
	to[e] = x, nxt[e] = hd[y], f[e] = 0, hd[y] = e++;
}

bool tell() {
	memset(ch, -1, sizeof ch);
	queue<int> q;
	ch[s] = 0;
	q.push(s);
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i = hd[u]; ~i; i = nxt[i]) if(ch[to[i]] == -1 && f[i])
			ch[to[i]] = ch[u] + 1, q.push(to[i]);
	}
	return ch[t] != -1;
}

int zeng(int a, int b) {
	if(a == t) return b;
	int r = 0;
	for(int i = hd[a]; ~i && b > r; i = nxt[i]) if(ch[to[i]] == ch[a] + 1 && f[i]) {
		int t = zeng(to[i], min(b-r, f[i]));
		f[i] -= t, r += t, f[i^1] += t;
	}
	if(!r) ch[a] = -1;
	return r;
}

int dinic() {
	int r = 0, t;
	while(tell()) while(t = zeng(s, inf)) r += t;
	return r;
}

int main() {
	while(~scanf("%d%d%d", &n, &m, &l)) {
		e = 0, t = n*2+1;
		memset(d, 0x3f, sizeof d);
		memset(hd, -1, sizeof hd);
		for(int i = 1; i <= n; i++) d[i][i] = 0;
		while(m--) scanf("%d%d%d", &x, &y, &z), d[x][y] = d[y][x] = z;
		for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		for(int i = 1; i <= n; i++) {
			scanf("%d", &x);
			add(0, i, x);
			for(int j = 1; j <= n; j++) if(d[i][j] < l) add(i, n+j, inf);
		}
		for(int i = 1; i <= n; i++) scanf("%d", &x), add(n+i, t, x);
		printf("%d\n", dinic());
	}
	return 0;
}