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.util.LinkedList;
import java.util.Arrays;
import java.util.ArrayList;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author toshif
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int tot = 0; int tot2 = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            tot += a[i];
        }
        for (int i = 0; i < n; i++) {
            b[i] = in.nextInt();
            tot2 += b[i];
        }

        if (tot != tot2) {
            out.println("NO");
            return;
        }


        FordFulkerson f = new FordFulkerson(2 * n + 2);
        for (int i = 0; i < n; i++) {
            f.capacity[0].add(new FordFulkerson.Edge(0, 2 + i, a[i]));
        }
        for (int i = 0; i < n; i++) {
            f.capacity[2+n+i].add(new FordFulkerson.Edge(2 + n + i, 1, b[i]));
        }
        for (int i = 0; i < n; i++) {
            f.capacity[2+i].add(new FordFulkerson.Edge(2+i, 2+n+i, 1000));
        }
        for (int i = 0; i < m; i++) {
            int p1 = in.nextInt()-1;
            int p2 = in.nextInt()-1;
            f.capacity[2+p1].add(new FordFulkerson.Edge(2+p1, 2+n+p2, 1000));
            f.capacity[2+p2].add(new FordFulkerson.Edge(2+p2, 2+n+p1, 1000));
        }

        f.solve(0, 1);

//        System.err.printf("maxflow=%s\n", f.maxFlow);
//        System.err.printf("flows=%s\n", f.getFlowResult());

        if (tot == f.maxFlow) {
            out.println("YES");

            List<FordFulkerson.Edge> flow = f.getFlowResult();
            int[][] ret = new int[n][n];
            for (FordFulkerson.Edge e : flow) {
                if (e.from == 0 || e.to == 1) continue;

                ret[e.from-2][e.to-2-n] = e.val;
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    out.print(ret[i][j] + " ");
                }
                out.println();
            }
        } else {
            out.println("NO");
        }
    }

    static class FordFulkerson {

        int V;
        List<Edge>[] capacity;
        // residual graph. using Map for a bit of efficiency.
        // key: to vertex, value: Edge
        private Map<Integer, Edge>[] residual;
        int maxFlow = 0;

        FordFulkerson(int V) {
            this.V = V;
            capacity = new List[V];
            residual = new Map[V];
            dfsUsed = new boolean[V];

            for (int i = 0; i < V; i++) {
                capacity[i] = new ArrayList<>();
                residual[i] = new HashMap<>();
            }
        }

        // s -> t への max flow を探す
        void solve(int s, int t) {
            initBeforeSolve();

            while (true) {
                initDfs();
                boolean reachable = dfs(s, t);

                if (!reachable) break;

                updateResidual();
            }
        }

        private void initBeforeSolve() {
            for (int i = 0; i < V; i++) {
                for (Edge e : capacity[i]) {
                    residual[i].put(Integer.valueOf(e.to), new Edge(e.from, e.to, e.val));
                }
            }
        }

        private boolean[] dfsUsed;
        private LinkedList<Edge> augPath = new LinkedList<>();

        private void initDfs() {
            Arrays.fill(dfsUsed, false);
            augPath.clear();
        }

        // v->t への増加パス (augmenting path) を探す
        // true if reachable from v to t
        private boolean dfs(int v, int t) {
            dfsUsed[v] = true;

            if (v == t) {
                return true;
            }

            for (Edge e : residual[v].values()) {
                if (dfsUsed[e.to]) continue;
                if (e.val == 0) continue;

                boolean reachable = dfs(e.to, t);
                if (reachable) {
                    augPath.addFirst(e);
                    return true;
                }
            }

            return false;
        }

        // updating the residual graph
        private void updateResidual() {
            int minVal = augPath.get(0).val;
            for (Edge e : augPath) {
                minVal = Math.min(minVal, e.val);
            }

            // System.err.printf("flow %s with %s\n", minVal, augPath);

            maxFlow += minVal;

            for (Edge e : augPath) {
                // その辺に流す = 減らす
                e.val -= minVal;

                // 逆辺を増やす
                Integer from = Integer.valueOf(e.from);
                if (!residual[e.to].containsKey(from)) {
                    // if not yet present, create a new
                    residual[e.to].put(from, new Edge(e.to, from, 0));
                }
                Edge rev = residual[e.to].get(from);
                rev.val += minVal;
            }
        }

        // max flow のとき(一意でない)、flow がある辺のリストを返す. val は flow の量.
        List<Edge> getFlowResult() {
            List<Edge> ret = new ArrayList<>();
            for (int i = 0; i < V; i++) {
                List<Edge> edges = capacity[i];
                for (Edge capE : edges) {
                    Edge resE = residual[i].get(Integer.valueOf(capE.to));
                    if (resE.val < capE.val) {
                        ret.add(new Edge(capE.from, capE.to, capE.val - resE.val));
                    }
                }
            }

            return ret;
        }

        static class Edge {
            int from;
            int to;
            int val;

            public Edge(int from, int to, int val) {
                this.from = from;
                this.to = to;
                this.val = val;
            }

            public String toString() {
                return "Edge{" + from + "->" + to + ", val=" + val + '}';
            }
        }

    }
}