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 <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m,l;
int d[101][101];
int P[101];
int K[101];
const int INF=1000000000;
const int MAX_V = 301;
int sp,gp;

struct edge{
	int to,cap,rev;
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
	edge e;
	e.to = to;
	e.cap = cap;
	e.rev = G[to].size();
	G[from].push_back(e);
	e.to = from;
	e.cap = 0;
	e.rev = G[from].size()-1;
	G[to].push_back(e);
}

// ÁpXðTõ
int dfs(int v,int t,int f){
	if(v == t)
		return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow = 0;
	while(1){
		fill(used,used+MAX_V,false);
		int f = dfs(s,t,INF);
		if(f == 0)return flow;
		else flow += f;
	}
	return 0;
}
void warshallFloyd(){
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
}

int main(){

	while(cin>>n>>m>>l){
		for(int i=0;i<MAX_V;i++)G[i].clear();
		for(int i=0;i<101;i++)for(int j=0;j<101;j++)
			if(i==j)d[i][j]=0;
			else d[i][j]=INF;
		for(int i=0;i<m;i++){
			int a,b,D;
			cin>>a>>b>>D;
			a--;b--;
			d[a][b]=d[b][a]=D;
		}
		warshallFloyd();
		for(int i=0;i<n;i++)cin>>P[i];
		for(int i=0;i<n;i++)cin>>K[i];
		sp=2*n;
		gp=2*n+1;
		// ÅZ£ªLæè¬³¢ÌàÌðGbWÅÂÈ®
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				if(d[i][j]<l)add_edge(i,j+n,INF);
		// start©ç
		for(int i=0;i<n;i++)add_edge(sp,i,P[i]);
		// goalÖ
		for(int i=0;i<n;i++)add_edge(i+n,gp,K[i]);
		int res=max_flow(sp,gp);
		cout<<res<<endl;
	}
	return 0;
}