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<algorithm>
#include<vector>
#include<cmath>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
struct Pox
{
  int to,cap,rev;
  Pox(int to=-1,int cap=-1,int rev=-1):to(to),cap(cap),rev(rev){}
};
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Pox> VP;
typedef vector<VP> VVP;

int N,M,L;



void printVI(VI &a)
{
  cout << "printVI =====" << endl;
  rep(i,a.size())cout << a[i] << " ";
  cout << endl << endl;
}

void printVVI(VVI &a)
{
  cout << "ptinrVVI =====" << endl;
  rep(i,a.size())
    {
      rep(j,a[i].size())
	{
	  cout << a[i][j] << " ";
	}
      cout << endl;
    }
  cout << endl;
}

void printVVP(VVP &g)
{
  cout << "printVVP ====" << endl;
  rep(i,g.size())
    {
      cout << "i: " << i << ": ";
      rep(j,g[i].size())
	{
	  cout << "(" << g[i][j].to << "," << g[i][j].cap << "," << g[i][j].rev << ") "; 
	}
      cout << endl;
    }
  cout << endl;
}

void add_edge(VVP &G,int from,int to,int cap)
{
  G[from].push_back(Pox(to,cap,G[to].size()));
  G[to].push_back(Pox(from,0,G[from].size()-1));
} 


void bfs(int s,VI &level,VVP &G)
{
  rep(i,level.size())level[i] = -1;
  level[s] = 0;
  deque<int> deq;
  deq.push_back(s);
  while(!deq.empty())
    {
      int p = deq.front(); deq.pop_front();
      for(int i=0;i<G[p].size();i++)
	{
	  Pox &pox = G[p][i];
	  if(pox.cap > 0 && level[pox.to] < 0)
	    {
	      level[pox.to] = level[p]+1;
	      deq.push_back(pox.to);
	    }
	}
    }
}

int dfs(VVP &G,VI &level,VI &iter,int v,int t,int f)
{
  //cout << "v = " << v << endl;
  if(v == t)return f;
  for(int &i=iter[v];i<G[v].size();i++)
    {
      Pox &pox = G[v][i];
      if(pox.cap <= 0)continue;
      if(level[pox.to] <= level[v])continue;
      //cout << "goto " << pox.to << endl;
      int flow = dfs(G,level,iter,pox.to,t,min(f,pox.cap));
      //assert(flow <= pox.cap);
      if(flow > 0)
	{
	  pox.cap -= flow;
	  G[pox.to][pox.rev].cap += flow;
	  return flow;
	}
    }
  return 0;
}

int maximum_flow(VVP &G,int s,int t)
{
  int SIZE = 2*N+3;
  VI level(G.size());
  VI iter(G.size()); 

  int f = 0;
  while(true)
    {
      rep(i,G.size())iter[i] = 0;
      bfs(s,level,G);
      //cout << "N = " << N << endl;
      //printVI(level);

      if(level[t] == -1)return f;
      int flow = dfs(G,level,iter,s,t,(1<<29));
      //cout << "return f = " << f  << endl;
      assert(flow >= 0);
      if(!flow)return f;
      if(flow > 0)
	f += flow;

    }

}


int main()
{
  while(cin >> N >> M >> L)
    {
      int SIZE1 = N+1;
      int SIZE2 = 2*N+2;
      int total = 0;
      VVI FWG(SIZE1,VI(SIZE1));
      VVP G(SIZE2);
      VI P(SIZE1),K(SIZE1);
      rep(i,SIZE1)rep(j,SIZE1)FWG[i][j] = i==j?0:(1<<29);
      rep(i,M)
	{
	  int A,B,D;
	  cin >> A >> B >> D;
	  FWG[A][B] = D;
	  FWG[B][A] = D;
	}

      rep(k,SIZE1)rep(i,SIZE1)rep(j,SIZE1)FWG[i][j] = min(FWG[i][j],FWG[i][k]+FWG[k][j]);

      REP(i,1,SIZE1)cin >> P[i];
      REP(i,1,SIZE1)cin >> K[i],total += K[i];

      REP(i,1,N+1)add_edge(G,0,i,P[i]);	
      REP(i,1,N+1)add_edge(G,i+N,2*N+1,K[i]);
      REP(i,1,N+1)
	REP(j,1,N+1)
	if(FWG[i][j] < L)
	  add_edge(G,i,j+N,(1<<29));
	  
      /*
      printVVI(FWG);
      rep(i,G.size())
      cout << G[i].size() << endl;
      cout << endl;
      printVVP(G);
      */
      int ret = maximum_flow(G,0,2*N+1);
      assert(0 <= ret && ret <= total);
      cout << ret << endl;

    }
  return 0;
}