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 REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

const long long Inf = numeric_limits<long long>::max() / 4;

namespace flow_algorithm
{
  template<class Flow>
  struct edge
  {
    int to;
    Flow cap, rev;
  };
  /*
    template<class Flow>
    using edges = vector<edge<Flow>>;
    
    template<class Flow>
    using graph = vector<edges<Flow>>;
  */
  
  typedef vector<edge<long long>> edges;
  typedef vector<edges> graph;
  
  template<class Flow>
  class dinic
  {
  private:
    int V;
    //    graph<Flow> g;
    graph g;
    vector<int> level;
    vector<int> iter;
    
  public:
    //    Flow static constexpr Inf = numeric_limits<Flow>::max() / 4;
    
  private:
    
    void bfs(int s)
    {
      rep(i, V) level[i] = -1;
      queue<int> q;
      q.push(s);
      level[s] = 0;
      while(!q.empty()) {
        int curr = q.front(); q.pop();
        rep(i, g[curr].size()) {
          edge<Flow>& e = g[curr][i];
          if(level[e.to] != -1) { continue; }
          if(e.cap <= 0) { continue; }
          level[e.to] = level[curr] + 1;
          q.push(e.to);
        }
      }
    }
    
    Flow dfs(int curr, int tar, Flow flow)
    {
      if(curr == tar) { return flow; }
      for(int &i = iter[curr]; i<(int)g[curr].size(); i++) {
        edge<Flow>& e = g[curr][i];
        if(e.cap <= 0) { continue; }
        if(level[curr] >= level[e.to]) { continue; }
        Flow d = dfs(e.to, tar, min(flow, e.cap));
        if(d <= 0) { continue; }
        e.cap -= d;
        g[e.to][e.rev].cap += d;
        return d;
      }
      return 0;
    }
    
  public:
    
    dinic(int V_)
    {
      V = V_;
      g.resize(V);
      level.resize(V);
      iter.resize(V);
    }
    
    void add_edge(int from, int to, Flow cap)
    {
      g[from].push_back({to, cap, (Flow)g[to].size()});
      g[to].push_back({from, 0, (Flow)g[from].size()-1});
    }
    
    Flow max_flow(int src, int dest)
    {
      Flow flow = 0;
      for(;;) {
        bfs(src);
        if(level[dest] < 0) { return flow; }
        rep(i, V) iter[i] = 0;
        Flow f;
        while((f = dfs(src, dest, Inf)) > 0) {
          flow += f;
        }
      }
    }
    
  };
  
  
}

typedef long long ll;

int main() {
  
  int N; ll M, L;
  while(cin >> N >> M >> L) {
    ll g[N][N];
    rep(i, N) rep(j, N) g[i][j] = Inf;
    
    rep(i, M) {
      int a, b, d; cin >> a >> b >> d; a--, b--;
      g[a][b] = g[b][a] = d;
    }
    
    rep(k, N) rep(i, N) rep(j, N) {
      if(g[i][k] == Inf && g[k][j] == Inf) { continue; }
      g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
    }
    
    rep(i, N) { g[i][i] = 0; }
    
    int const SRC = 2*N+1, SINK = 2*N+2;
    
    flow_algorithm::dinic<ll> dn(2*N+10);
    
    vector<int> ps(N);
    rep(i, N) {
      cin >> ps[i];
      dn.add_edge(SRC, i, ps[i]);
    }
    
    rep(i, N) rep(j, N) {
      //      if(i == j) { continue; }
      if( g[i][j] < L ) {
        dn.add_edge(i, N+j, Inf);
      }
    }
    
    rep(i, N) {
      ll K; cin >> K;
      dn.add_edge(N+i, SINK, K);
    }
    
    cout << dn.max_flow(SRC, SINK) << endl;
  }
  
  return 0;
}