Problem: A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tubes equals e. Volume of each vessel equals v liters. Of course, the amount of the water in any vessel cannot exceed v liters in the process of transfusions.

Given the initial amounts ai of water in the vessels and the desired amounts bi find a sequence of transfusions that deals with the task. Total number of transfusions must not exceed 2·n2.

Input

First line of the input contains integers n, v, e (1 ≤ n ≤ 300, 1 ≤ v ≤ 109, 0 ≤ e ≤ 50000).

Next two lines contain n integers each: initial ai and the desired amounts bi of water in corresponding vessels (0 ≤ ai, bi ≤ v).

Next e lines describe one tube each in the format x y (1 ≤ x, y ≤ n, x ≠ y) for a tube between vessels number x and y. There might be multiple tubes between two vessels. You may assume that vessels are numbered from 1 to n in some way.

Output

Print "NO" (without quotes), if such sequence of transfusions does not exist.

Otherwise print any suitable sequence in the following format. On the first line print the total number of transfusions k (k should not exceed 2·n2). In the following k lines print transfusions in the format x y d (transfusion of d liters from the vessel number x to the vessel number y, x and y must be distinct). For all transfusions d must be a non-negative integer.

Examples

Input

2 10 1
1 9
5 5
1 2


Output

1
2 1 4


Input

2 10 0
5 2
4 2


Output

NO


Input

2 10 0
4 2
4 2


Output

0

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class C {	
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;
    
    public class Node{
    	int id;
    	Node parent;
    	int rank;
    	int a;
    	int b;
    	public Node(int id, int a, int b){
    		this.id = id;
    		this.a = a;
    		this.b = b;
    		this.parent = this;
    		this.rank = 1;
    	}
    }
    int N;
    int V;
    boolean[][] edge;
    Node[] nodes;
    ArrayList<int[]> answer;
    
	public void solve() throws IOException {				
		N = nextInt();
		V = nextInt();
		int E = nextInt();
		answer = new ArrayList<int[]>();
		
		int[] A = new int[N];
		int[] B = new int[N];
		for(int i = 0; i < N; i++)
			A[i] = nextInt();
		for(int i = 0; i < N; i++)
			B[i] = nextInt();
		
		nodes = new Node[N];
		for(int i = 0; i < N; i++)
			nodes[i] = new Node(i, A[i], B[i]);
		
		edge = new boolean[N][N];
		for(int i = 0; i < E; i++){
			int v1 = nextInt()-1;
			int v2 = nextInt()-1;
			union(nodes[v1], nodes[v2]);
			edge[v1][v2] = true;
			edge[v2][v1] = true;
		}	
		
//		for(int i = 0; i < N; i++){
//			out.println(i + ": " + nodes[i].parent.id + ", " + nodes[i].rank );
//		}
		
		int[] group = new int[N];
		long[] group_total_a = new long[N];
		long[] group_total_b = new long[N];
		for(int i = 0; i < N; i++){
			Node n = nodes[i];
			while(n.parent != n) 
				n = n.parent;
			group[i] = n.id;
			
			group_total_a[n.id] += (long)nodes[i].a;
			group_total_b[n.id] += (long)nodes[i].b;
		}
		
		for(int i = 0; i < N; i++)
			if( group_total_a[i] != group_total_b[i] ) {
				out.println("NO"); return;
			}
		
		for(int i = 0; i < N; i++){
			if( nodes[i].a > nodes[i].b ){
				int excess = nodes[i].a - nodes[i].b;
				for(int j = 0; j < N; j++){
					if( group[i] == group[j] && nodes[j].a < nodes[j].b){
						int need = nodes[j].b - nodes[j].a; 
						flow( i, j, Math.min(excess, need) );
						excess -= Math.min(excess, need);
						if( excess == 0) break;
					}											
				}
				if( excess != 0) throw new RuntimeException();
			}
		}
		
//		for(int i = 0; i < N; i++){
//			if( nodes[i].a != nodes[i].b ){
//				System.out.println(i + ": " + nodes[i].a + ", " + nodes[i].b);
//				throw new RuntimeException();
//			}
//		}
//		if( answer.size() > N*N*2)
//			throw new RuntimeException();
		
		out.println( answer.size() );
		for(int[] an: answer){
			out.println( an[0] + " " + an[1] + " " + an[2]);
		}
	}
	
	public void doflow(int from, int to, int amount){
		answer.add( new int[] {from+1, to+1, amount} );
		nodes[from].a -= amount;
		nodes[to].a += amount;
	}
	
	public void flowhelper(int[] path, int cur, int amount){
		if(cur == path.length-1) return;
		
		int remain = V - nodes[path[cur+1]].a; 
		if( remain >= amount ){
			doflow( path[cur], path[cur+1], amount);
			flowhelper(path, cur+1, amount);
		}
		else{
			int firstflow = Math.min( nodes[path[cur+1]].a, amount);
			flowhelper(path, cur+1, firstflow);
			doflow( path[cur], path[cur+1], amount);
			
			if( firstflow < amount)
				flowhelper(path, cur+1, amount - firstflow);			
		}
	}
	
	public void flow(int from, int to, int amount){
		int[] path = findpath(from, to);
		flowhelper(path, 0, amount);	
	}
	
	public int[] findpath(int source, int dest){
		Queue<Integer> queue = new LinkedList<Integer>();
		int[] parents = new int[N];
		Arrays.fill(parents, -1);
		
		queue.add(dest);
		while(!queue.isEmpty()){
			int cur = queue.poll();
			if( cur == source) break;
			for(int i = 0; i < N; i++){
				if( edge[cur][i] && parents[i] == -1){
					parents[i] = cur;
					queue.add(i);
				}
			}
		}
		ArrayList<Integer> path = new ArrayList<Integer>();
		while( source != dest ){
			path.add(source);
			source = parents[source];
		}
		path.add(source);
		
		int[] ret = new int[path.size()];
		for(int i = 0; i < ret.length; i++)
			ret[i] = path.get(i);
		
		return ret;
	}
	
//	public void flow(int from, int to, int amount){
//		int[] path = findpath(from, to);
//		int[] pending = new int[path.length];
//		pending[0] = amount;
//		
//		for(int i = 0; i < path.length; i++){
//			if( pending[i] == 0) continue;
//			
//			int have = 0;
//			int cur = i+1;
//			while( have < amount ){
//				have = have + (V - nodes[ path[cur] ].a);
//			}
//			for(int j = cur; j >= i+1; j--){
//				int flow = Math.min(amount, nodes[path[cur]].a );
//				
//				
//				answer.add( new int[]{ path[j-1], path[j], flow});
//			}
//			
//			for(int j = i+1; j < path.length; j++){
//				have = have + 
////				if(  nodes[ path[j] ].a)
//			}
//		}
//		
//		int cur = 0;
//		while(cur < path.size()){
//			
//		}
//		
//		while( nodes[to].a < nodes[to].b ){
//			for()
//		}
//	}
	
	public void union(Node n1, Node n2){
		while(n1.parent != n1)
			n1 = n1.parent;
		while(n2.parent != n2)
			n2 = n2.parent;
		
		if(n1 == n2) return;
			
		Node p = n1.rank > n2.rank? n1: n2;
		Node c = n1.rank > n2.rank? n2: n1;
		
		c.parent = p;
		p.rank += c.rank;		
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new C().run();
	}
	
	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}