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<complex>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(c)   (c).begin(),(c).end()

#define P(i)  (2*i+0)
#define D(i)  (2*i+1)

const int N = 100;
const int inf = (1<<25);
int cap[500][500];
bool visited[500];
int flow[500][500];
int layer[500];

void make_layer(int n,int s,int t){
  queue<int> Q;
  Q.push(s);
  layer[s]=0;
  while(!Q.empty()){
    int now=Q.front();Q.pop();
    rep(i,n){
      if (cap[now][i]-flow[now][i] >0 && layer[i] == -1){
	layer[i]=layer[now]+1;
	Q.push(i);
      }
    }
  }
}

int augment(int now,int t,int n,int f){
  if (now==t||f==0)return f;
  if (visited[now])return 0;
  visited[now]=true;
  rep(i,n){
    if (layer[now] < layer[i]){
      int tmp = augment(i,t,n,min(f,cap[now][i]-flow[now][i]));
      if (tmp > 0){
	flow[now][i]+=tmp;
	flow[i][now]=-flow[now][i];
	visited[now]=false;
	return tmp;
      }
    }
  }
  return 0;
}

int dinic(int n,int s,int t){
  int ansflow=0;
  rep(i,n)rep(j,n)flow[i][j]=0;
  bool flag=true;
  while(flag){
    fill(layer,layer+n,-1);
    fill(visited,visited+n,false);
    flag=false;

    make_layer(n,s,t);
    if (layer[t] == -1)break;

    for(int f=1;f;flag=true){
      f = augment(s,t,n,inf);
      if (f == 0)break;
      ansflow+=f;
    }
  }
  return ansflow;
}

int dist[N][N];
void wf(int n){
  rep(k,n)rep(i,n)rep(j,n)dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}

int main(){
  int n,m,L;
  while(cin>>n>>m>>L){
    int node=n*2+2;
    int src=n*2,sink=n*2+1;
    rep(i,node)rep(j,node)cap[i][j]=0;
    rep(i,n){
      rep(j,n)dist[i][j]=inf;
      dist[i][i]=0;
    }    

    rep(i,n){
      //cap[src][P(i)]=inf;
      //cap[D(i)][sink]=inf;
    }

    rep(i,m){
      int f,t,c;
      cin>>f>>t>>c;
      dist[f-1][t-1]=dist[t-1][f-1]=c;
    }
    
    rep(i,n){
      cin>>cap[src][P(i)];
    }

    rep(i,n){
      cin>>cap[D(i)][sink];
    }

    wf(n);
    rep(i,n){
      rep(j,n){
	if (dist[i][j] < L){
	  cap[P(i)][D(j)]=inf;
	}
      }
    }

    cout << dinic(node,src,sink)<<endl;
  }
  return 0;
}