Problem: In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighboring cities by at moving along at most one road.

Check if is it possible that after roaming there will be exactly bi soldiers in the i-th city.

Input

First line of input consists of two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 200).

Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 100).

Next line contains n integers b1, b2, ..., bn (0 ≤ bi ≤ 100).

Then m lines follow, each of them consists of two integers p and q (1 ≤ p, q ≤ n, p ≠ q) denoting that there is an undirected road between cities p and q. 

It is guaranteed that there is at most one road between each pair of cities.

Output

If the conditions can not be met output single word "NO".

Otherwise output word "YES" and then n lines, each of them consisting of n integers. Number in the i-th line in the j-th column should denote how many soldiers should road from city i to city j (if i ≠ j) or how many soldiers should stay in city i (if i = j).

If there are several possible answers you may output any of them.

Examples

Input

4 4
1 2 6 3
3 5 3 1
1 2
2 3
3 4
4 2


Output

YES
1 0 0 0 
2 0 0 0 
0 5 1 0 
0 0 2 1 


Input

2 0
1 2
2 1


Output

NO

Solution (in JAVA):

Solution:
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class SoldierAndTraveling {
    public static void main(String[] args) {
        FasterScanner sc = new FasterScanner();
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = sc.nextIntArray(N, 1);
        int[] B = sc.nextIntArray(N, 1);
        
        int[][] g = new int[2 * N + 2][2 * N + 2];
        for (int i = 0; i < M; i++) {
        	int P = sc.nextInt();
        	int Q = sc.nextInt();
        	g[P][N + Q] = A[P];
        	g[Q][N + P] = A[Q];
        }
        for (int i = 1; i <= N; i++) {
        	g[0][i] = A[i];
        	g[i][N + i] = A[i];
        	g[N + i][2 * N + 1] = B[i];
        }
        
        Flow res = fordFulkerson(g, 0, 2 * N + 1);
        int sumA = sum(A);
        int sumB = sum(B);
        if (sumA == sumB && sumB == res.maxFlow) {
        	StringBuilder sb = new StringBuilder();
        	for (int i = 1; i <= N; i++) {
        		for (int j = 1; j <= N; j++) {
        			if (i == j) {
//        				int stay = A[i] - sumRange(res.flow[i], 1, N);
//        				System.out.format("i = %d, A[i] = %d, sum = %d\n", i, A[i], sumRange(res.flow[i], 1, N));
        				sb.append(res.flow[i][N + j] + " ");
//        				sb.append(res.flow[i][j] + " ");
        			} else {
        				sb.append(res.flow[i][N + j] + " ");
        			}
        		}
        		sb.append("\n");
        	}
        	System.out.println("YES");
        	System.out.println(sb.toString());
        } else {
        	System.out.println("NO");
        }
    }
    
    public static int sum(int[] arr) {
    	return sumRange(arr, 0, arr.length - 1);
    }
    
    public static int sumRange(int[] arr, int L, int R) {
    	int tot = 0;
    	for (int i = L; i <= R; i++) {
    		tot += arr[i];
    	}
    	return tot;
    }
    
    /**
     * Returns true if there is a path from the source 's' to the sink 't' in the residual graph.
     * Also fills parent[] to store the path.
     * See here for more info:  http://www.geeksforgeeks.org/ford-fulkerson-algorithm-for-maximum-flow-problem/
     */
    public static boolean fordFulkersonHelper(int[][] resid, int s, int t, int[] parent) {
    	int V = resid.length;
    	boolean[] visited = new boolean[V];
    	LinkedList<Integer> q = new LinkedList<Integer>();
    	q.push(s);
    	visited[s] = true;
    	parent[s] = -1;
    	
    	while (!q.isEmpty()) {
    		int u = q.pop();
    		for (int v = 0; v < V; v++) {
    			if (!visited[v] && resid[u][v] > 0) {
    				q.push(v);
    				parent[v] = u;
    				visited[v] = true;
    			}
    		}
    	}
    	
    	return visited[t];
    }
    
    /**
     * Returns the maximum flow from 's' to 't' in the given graph.
     * See here for more info:  http://www.geeksforgeeks.org/ford-fulkerson-algorithm-for-maximum-flow-problem/
     */
    public static Flow fordFulkerson(int[][] graph, int s, int t) {
    	int V = graph.length;
    	int[][] resid = new int[V][V];
    	int[] parent = new int[V];
    	int maxFlow = 0;
    	
    	for (int u = 0; u < V; u++) {
    		for (int v = 0; v < V; v++) {
    			resid[u][v] = graph[u][v];
    		}
    	}
    	
    	while (fordFulkersonHelper(resid, s, t, parent)) {
    		int pathFlow = Integer.MAX_VALUE;
    		for (int v = t; v != s; v = parent[v]) {
    			int u = parent[v];
    			pathFlow = Math.min(pathFlow,  resid[u][v]);
    		}
    		for (int v = t; v != s; v = parent[v]) {
    			int u = parent[v];
    			resid[u][v] -= pathFlow;
    			resid[v][u] += pathFlow;
    		}
    		maxFlow += pathFlow;
    	}
    	
    	int[][] flow = Flow.computeFlow(graph, resid);
    	return new Flow(maxFlow, flow);
    }
    
    public static class Flow {
    	public int maxFlow;
    	public int[][] flow;
    	
    	public Flow(int mf, int[][] f) {
    		this.maxFlow = mf;
    		this.flow = f;
    	}
    	
    	public static int[][] computeFlow(int[][] graph, int[][] resid) {
    		int N = graph.length;
    		int[][] f = new int[N][N];
    		for (int i = 0; i < N; i++) {
    			for (int j = 0; j < N; j++) {
    				f[i][j] = Math.max(0, graph[i][j] - resid[i][j]);
    			}
    		}
    		return f;
    	}
    }
    
	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
	        
	    public int[] nextIntArray(int n) {
	        return nextIntArray(n, 0);
	    }
	    
	    public int[] nextIntArray(int n, int off) {
	    	int[] arr = new int[n + off];
	    	for (int i = 0; i < n; i++) {
	    		arr[i + off] = nextInt();
	    	}
	    	return arr;
	    }
	    
	    public long[] nextLongArray(int n) {
	    	return nextLongArray(n, 0);
	    }
        
		public long[] nextLongArray(int n, int off) {
		    long[] arr = new long[n + off];
		    for (int i = 0; i < n; i++) {
		        arr[i + off] = nextLong();
		    }
		    return arr;
		}

	    private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}