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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class SoldierTraveling {
	private static int s, t, n;
	private static int[] vis = new int[300];
	private static int[] par = new int[300];
	private static int[][] flow = new int[300][300];
	private static int[][] cap = new int[300][300];
	private static ArrayList<ArrayList<Integer>> adj;
	private static final int INF = Integer.MAX_VALUE;
	

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		n = Integer.parseInt(line[0]);
		int m = Integer.parseInt(line[1]);
		s = 2 * n;
		t = 2 * n + 1;
		adj = new ArrayList<ArrayList<Integer>>();
		for (int i = 0; i < 2 * n + 10; i++) {
			adj.add(new ArrayList<Integer>());
		}
		int u, v;
		int sum = 0;
		line = in.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			u = Integer.parseInt(line[i]);
			cap[s][i] = u;
			sum += u;
			adj.get(s).add(i);
			adj.get(i).add(s);
		}
		int check = 0;
		line = in.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			u = Integer.parseInt(line[i]);
			cap[i + n][t] = u;
			check += u;
			adj.get(i + n).add(t);
			adj.get(t).add(i + n);
		}
		if (sum != check) {
			System.out.println("NO");
			return;
		}
		for (int i = 0; i < n; i++) {
			cap[i][i + n] = INF;
			adj.get(i).add(i + n);
			adj.get(i + n).add(i);
		}
		for (int i = 0; i < m; i++) {
			line = in.readLine().split(" ");
			u = Integer.parseInt(line[0]);
			v = Integer.parseInt(line[1]);
			u--;
			v--;
			cap[u][v + n] = INF;
			cap[v][u + n] = INF;
			adj.get(u).add(v + n);
			adj.get(v + n).add(u);
			adj.get(v).add(u + n);
			adj.get(u + n).add(v);
		}
		check = bfs();
		if (check == sum) {
			System.out.println("YES");
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					System.out.printf("%d ", flow[i][j + n]);
				}
				System.out.println();
			}
		} else {
			System.out.println("NO");
		}
	}
	
	private static int pushFlow(int v, int maxFlow) {
		if (v == s) {
			return maxFlow;
		}
		int u = par[v];
		if (cap[u][v] <= 0) {
			maxFlow = Math.min(maxFlow, flow[v][u]);
		} else {
			maxFlow = Math.min(maxFlow, cap[u][v] - flow[u][v]);
		}
		maxFlow = pushFlow(u, maxFlow);
		if (cap[u][v] <= 0) {
			flow[v][u] -= maxFlow;
		} else {
			flow[u][v] += maxFlow;
		}
		return maxFlow;
	}

	private static int bfs() {
		int maxFlow = 0;
		while(true) {
			for (int i = 0; i < 2*n; i++) vis[i] = 0;
			vis[t] = 0;
			Queue<Integer> q = new LinkedList<>();
			q.add(s);
			vis[s] = 1;
			par[s] = 1;
			boolean pushed = false;
			while (!q.isEmpty()) {
				int cur = q.remove();
				for (int i = 0; i < adj.get(cur).size(); i++) {
					int next = adj.get(cur).get(i);
					if (vis[next] == 1) continue;
					if (cap[cur][next] - flow[cur][next] <= 0 && flow[next][cur] <= 0) continue;
					vis[next] = 1;
					q.add(next);
					par[next] = cur;
					if (next == t) {
						maxFlow += pushFlow(t, INF);
						pushed = true;
						break;
					}
				}
				if (pushed) break;
			}
			if (!pushed) break;
		}
		return maxFlow;
	}
}