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

namespace Dinic {
	const int mxn=5000, mxm=500000;
	int S, T;
	int head[mxn];
	int next[mxm], to[mxm], flow[mxm];
	inline void addedge(int idx, int a, int b, int f)
	{
		next[idx]=head[a]; head[a]=idx;
		to[idx]=b; flow[idx]=f;
	}
	int newm;
	inline void add(int a, int b, int f)
	{
		addedge((++newm)<<1, a, b, f);
		addedge(newm<<1|1, b, a, 0);
	}
	inline void init()
	{
		memset(head, 0, sizeof(head));
		newm=0;
	}
	int ch[mxn];
	inline bool tell()
	{
		memset(ch, -1, sizeof(ch));
		ch[S]=1;
		queue<int> q;
		q.push(S);
		while(!q.empty())
		{
			int u=q.front(); q.pop();
			for(int i=head[u]; i; i=next[i])
			{
				const int v=to[i];
			//printf("->%d %d %d\n", v, ch[v], flow[i]);
				if(ch[v]>0 || !flow[i]) continue;
				ch[v]=ch[u]+1;
				q.push(v);
			}
		}
		return ch[T]>0;
	}
	int expand(int a, int b)
	{
		//printf("expanding %d, %d\n", a, b);
		if(a==T) return b;
		int r=0, c;
		for(int i=head[a]; i && r<b; i=next[i])
		{
			int v=to[i];
			if(ch[v]!=ch[a]+1 || !flow[i]) continue;
			c=expand(v, min(b-r, flow[i]));
			r+=c;
			flow[i]-=c, flow[i^1]+=c;
		}
		return r;
	}
	inline int dinic(int sS, int tT)
	{
		S=sS, T=tT;
		int r=0, c;
		while(tell()) while(c=expand(S, 0x3f3f3f3f)) r+=c;
		return r;
	}
}

const int maxn=100+5;
int mx[maxn][maxn];


int main()
{
	int n, m, l; 
	while(scanf("%d%d%d", &n, &m, &l)==3)
	{
		memset(mx, 0x3f, sizeof(mx));
		for(int i=1; i<=n; ++i) mx[i][i]=0;
		for(int i=1; i<=m; ++i)
		{
			int x, y, l; scanf("%d%d%d", &x, &y, &l);
			mx[y][x]=mx[x][y]=min(mx[x][y], l);
		}
		for(int k=1; k<=n; ++k) for(int i=1; i<=n; ++i)
			for(int j=1; j<=n; ++j) mx[i][j]=min(mx[i][j], mx[i][k]+mx[k][j]);
		Dinic::init();
		for(int i=1; i<=n; ++i)
		{
			int x; scanf("%d", &x);
			Dinic::add(1, i+5, x);
		}
		for(int i=1; i<=n; ++i)
		{
			int x; scanf("%d", &x);
			Dinic::add(i+n+10, 2, x);
		}
		for(int i=1; i<=n; ++i) for(int j=1; j<=n; ++j)
		{
			if(mx[i][j]<l) 
			{
				Dinic::add(i+5, j+n+10, 0x3f3f3f3f);
				//printf("adding..%d %d\n", i, j);
			}
		}
		printf("%d\n", Dinic::dinic(1, 2));
	}
	
	return 0;
}