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:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <complex>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;

static const double EPS = 1e-12;

static const int tx[] = {+0,+1,+0,-1};
static const int ty[] = {-1,+0,+1,+0};

class Edge{
public:
  int _to;
  int _capacity;
  int _reverse;
  Edge(int to,int capacity,int reverse) :
    _to(to), _capacity(capacity), _reverse(reverse) {}
};

class FordFulkerson {
private:
  int _n;
  bool *_used;
  vector<Edge>* _edges;
  void fill_used(){
    fill(_used,_used + _n ,false);
  }
public:
  ~FordFulkerson(){
    delete[] _edges;
    delete[] _used;
  }

  FordFulkerson(int n){
    _n = n;
    _edges = new vector<Edge>[n];
    _used = new bool[n]();
  }

  void add_edge(int from,int to,int capacity){
    _edges[from].push_back(Edge(to,capacity,_edges[to].size()));
    _edges[to].push_back(Edge(from,0,_edges[from].size()-1));
  }

  int dfs(int current,int sink,int flow){
    if(current == sink) return flow;
    _used[current] = true;
    for(int i=0;i<_edges[current].size();i++){
      Edge& e = _edges[current][i];
      int to = e._to;
      if(_used[to] || e._capacity <= 0) continue;

      int d = dfs(to,sink,min(flow,e._capacity));
      if(d <= 0) continue;
      
      e._capacity -= d;
      _edges[to][e._reverse]._capacity += d;
      return d;
    }
    
    return 0;
  }

  int compute_max_flow(int source,int sink){
    int res = 0;
    while(true){
      fill_used();
      int tmp = dfs(source,sink,INF);
      if(tmp == 0) break;
      res += tmp;
    }
    return res;
  }
};

int main(){
  int num_of_domes;
  int num_of_pipelines;
  int day_limit;

  while(~scanf("%d %d %d",&num_of_domes,&num_of_pipelines,&day_limit)){
    int dp[101][101];
    memset(dp,0x3f,sizeof(dp));

    for(int pipeline_i = 0; pipeline_i < num_of_pipelines; pipeline_i++){
      int from,to,cost;
      scanf("%d %d %d",&from,&to,&cost);
      from--; to--;
      dp[from][to] = cost;
      dp[to][from] = cost;
    }

    for(int from = 0; from < num_of_domes; from++){
      int to = from;
      dp[from][to] = 0;
    }

    for(int mid = 0; mid < num_of_domes; mid++){
      for(int from = 0; from < num_of_domes; from++){
        for(int to = 0; to < num_of_domes; to++){
          dp[from][to] = min(dp[from][to], dp[from][mid] + dp[mid][to]);
        }
      }
    }

    FordFulkerson ford_fulkerson(num_of_domes * 2 + 2);
    for(int dome_i = 0; dome_i < num_of_domes; dome_i++){
      int current_reside_citizens;
      scanf("%d",&current_reside_citizens);
      ford_fulkerson.add_edge(num_of_domes * 2,dome_i,current_reside_citizens);
    }

    for(int dome_i = 0; dome_i < num_of_domes; dome_i++){
      int capacity;
      scanf("%d",&capacity);
      ford_fulkerson.add_edge(num_of_domes + dome_i,num_of_domes * 2 + 1,capacity);
    }

    for(int from = 0; from < num_of_domes; from++){
      for(int to = 0; to < num_of_domes; to++){
        if(dp[from][to] < day_limit){
          ford_fulkerson.add_edge(from,num_of_domes + to,INF);
        }
      }
    }
    printf("%d\n",ford_fulkerson.compute_max_flow(num_of_domes * 2,num_of_domes * 2 + 1));
  }
}