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 JAVA):

Solution:
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

//Flame of Nucleus
public class Main{

	int INF = 1<<29;
	
	public static int maxFlow(int s, int t, int[][] cap) {
		int n = cap.length, INF = Integer.MAX_VALUE;
		int res = 0;
		int[] prev = new int[n];
		boolean[] used = new boolean[n];
		Queue<Integer> q = new LinkedList<Integer>();
		for(;;){
			// use BFS to find argument-path
			Arrays.fill(used, false);
			Arrays.fill(prev, -1);
			q.clear();
			q.add(s);
			used[s] = true;
			while(!q.isEmpty()){
				int v = q.poll();
				if (v==t) break;
				for(int i=0;i<n;i++)if(!used[i] && 0<cap[v][i]){
					q.add(i);
					prev[i] = v;
					used[i] = true;
				}
			}
			if (!used[t]) return res;
			int v = t, f = INF;
			while(prev[v]!=-1){
				int p = prev[v];
				f = Math.min(f, cap[p][v]);
				v = p;
			}
			v = t;
			while(prev[v]!=-1){
				int p = prev[v];
				cap[p][v] -= f;
				cap[v][p] += f;
				v = p;
			}
			res += f;
		}
	}
	
//	int augumentPath(int v, int t, int f, int[][] cap, boolean[] used){
//		if(v==t)return f;
//		used[v] = true;
//		for(int i=0;i<cap[v].length;i++){
//			if(cap[v][i]>0 && !used[i]){
//				int d = augumentPath(i, t, Math.min(f, cap[v][i]), cap, used);
//				if(d>0){
//					cap[v][i] -= d;
//					cap[i][v] += d;
//					return d;
//				}
//			}
//		}
//		return 0;
//	}
//
//	int maxFlow(int s, int t, int[][] cap){
//		int flow = 0;
//		int n = cap.length;
//		boolean[] used = new boolean[n];
//		while(true){
//			Arrays.fill(used, false);
//			int f = augumentPath(s, t, Integer.MAX_VALUE, cap, used);
//			if(f==0)return flow;
//			flow += f;
//		}
//	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt(), m = sc.nextInt(), L = sc.nextInt();
			int[][] wf = new int[n+1][n+1];
			for(int[]a:wf)Arrays.fill(a, INF);
			for(int i=1;i<=n;i++)wf[i][i]=0;
			while(m--!=0){
				int s = sc.nextInt(), t = sc.nextInt(), c = sc.nextInt();
				wf[s][t]=wf[t][s]=c;
			}
			for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)wf[i][j]=Math.min(wf[i][j], wf[i][k]+wf[k][j]);
			int[] p = new int[n+1], k = new int[n+1];
			for(int i=1;i<=n;i++)p[i]=sc.nextInt();
			for(int i=1;i<=n;i++)k[i]=sc.nextInt();
			int[][] cap = new int[n*2+2][n*2+2];
			for(int i=1;i<=n;i++)cap[0][i]=p[i];
			for(int i=1;i<=n;i++)cap[n+i][2*n+1]=k[i];
			for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(wf[i][j]<L)cap[i][n+j]=p[i];
			System.out.println(maxFlow(0, 2*n+1, cap));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}