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 <vector>
#include <queue>
#include <cstring>
#include <iostream>
using namespace std;

const int N = 250; //max size of vertex
const int inf = 1<<29;
int n,m,l;
int cap[N][N],flow[N][N];
int level[N];
int adj[N][N];
bool finished[N];

inline int residue(int s,int t) { return cap[s][t] - flow[s][t]; }

void makeLevel(int s) {
    memset(level, -1, sizeof(level));
    level[s] = 0;
    queue<int> Q; Q.push(s);
    while(!Q.empty()) {
        int here = Q.front(); Q.pop();
        for(int there=0; there<n*2+2; ++there) {
            if(level[there] < 0 && residue(here,there) > 0) {
                level[there] = level[here]+1;
                Q.push(there);
            }
        }
    }
}

int augment(int here,int curf,int t) {
    if(here == t || curf == 0) return curf;
    if(finished[here] != 0) return 0;
    finished[here] = 1;
    for(int there=0; there<n*2+2; ++there) {
        if(level[there] > level[here]) {
            int f = augment(there, min(curf, residue(here, there)), t);
            if(f > 0) {
                flow[here][there] += f;
                flow[there][here] -= f;
                finished[here] = false;
                return f;
            }
        }
    }
    return 0;
}

int Dinic(int s,int t) {
    memset(flow, 0, sizeof(flow));
    int ret = 0;
    for(bool cont = true; cont; ) {
        cont = false;
        makeLevel(s);
        memset(finished, 0, sizeof(finished));
        for(int f; (f = augment(s, inf, t)) > 0; cont = true)
            ret += f;
    }
    return ret;
}

int main() {
    int a,b,d;
    while(cin>>n>>m>>l) {
        for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) adj[i][j] = inf;
        for(int i=0; i<m; ++i) {
            cin>>a>>b>>d;
            a--,b--;
            adj[a][b] = min(d, adj[a][b]);
            adj[b][a] = adj[a][b];
        }

        for(int i=0; i<n; ++i) adj[i][i] = 0;

        //Warshall-Floyd
        for(int k=0; k<n; ++k) {
            for(int i=0; i<n; ++i) {
                for(int j=0; j<n; ++j)
                    adj[i][j] = min(adj[i][k]+adj[k][j], adj[i][j]);
            }
        }

        memset(cap, 0, sizeof(cap));
        memset(finished, 0, sizeof(finished));
        memset(flow, 0, sizeof(flow));

        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                if(adj[i][j] >= l) continue;
                // cout<<"add "<<i<<" "<<j<<endl;
                cap[i][j+n] = inf;
                cap[j][i+n] = inf;
            }
        }

        int p;
        for(int i=0; i<n; ++i) {
            cin>>p;
            cap[2*n][i] += p;
        }

        int k;
        for(int i=0; i<n; ++i) {
            cin>>k;
            cap[i+n][2*n+1] += k;
        }

        // for(int i=0; i<=2*n+1; ++i) {
        //     for(int j=0; j<=2*n+1; ++j) cout<<cap[i][j]<<" ";
        //     cout<<endl;
        // }

        cout<<Dinic(2*n,2*n+1)<<endl;
    }
}