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<bits/stdc++.h>
using namespace std;
#define INF (1<<29)
int N,M,L;
int Wa[111][111];
int P[111],K[111];
struct edge{
  int to,c,rev;
  edge(int to,int c,int rev) : to(to),c(c),rev(rev) {}
};
vector<edge> G[333];
bool used[333];
int dfs(int v,int t,int f){
  if( v == t ) return f;
  used[v] = true;
  for(int i=0;i<(int)G[v].size();i++){
    edge &e = G[v][i];
    if( !used[e.to] && e.c > 0 ){
      int d = dfs(e.to, t , min(f,e.c) );
      if( d > 0 ){
	e.c -= d;
	G[e.to][e.rev].c += d;
	return d;
      }
    } 
  }
  return 0;
}

int max_flow(){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(2*N,2*N+1,INF);
    if( f == 0 ) return flow;
    flow += f;
  }
}

int main(){
  while( cin >> N >> M >> L ){
    fill(Wa[0],Wa[N],INF);
    for(int i=0;i<M;i++){
      int a,b,d;
      cin >> a >> b >> d;
      --a; --b;
      Wa[a][b] = d;
      Wa[b][a] = d;
    }
    for(int i=0;i<N;i++){
      Wa[i][i] = 0;
      cin >> P[i];
    }
    for(int i=0;i<N;i++){
      cin >> K[i];
    }
  
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	for(int k=0;k<N;k++)
	  Wa[j][k] = min(Wa[j][k],Wa[j][i]+Wa[i][k]);

  
    for(int i=0;i<2*N+2;i++) G[i].clear();
    for(int i=0;i<N;i++){
     
      G[i+N].push_back( edge(2*N+1,K[i],G[2*N+1].size() ) );
      G[2*N+1].push_back( edge(i+N,0,G[i+N].size()-1) );

      G[2*N].push_back( edge(i,P[i],G[i].size()) );
      G[i].push_back( edge(2*N,0,G[2*N].size() -1) );
  
      for(int j=0;j<N;j++){
	if( Wa[i][j] < L ){
	  int nj = j+N;
	  G[i].push_back( edge(nj,INF,G[nj].size()) );
	  G[nj].push_back( edge(i,0,G[i].size() - 1) );
	}
      }
    }

    cout << max_flow() << endl;
  }
}