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:
//package codeforcesround.year2015.may.round304;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;
 
public class SoldierAndTraveling {
        BufferedReader br;
        PrintWriter out;
        StringTokenizer tk;
        boolean submit;
        
        private String ntk() { 
                while (tk == null || !tk.hasMoreTokens()) {
                        try {
                                tk = new StringTokenizer(br.readLine());
                        } catch (IOException e) {
                                return null;
                        }
                }
                return tk.nextToken();
        }
 
        private String nln() {
                try {
                        return br.readLine();
                } catch (IOException e) {
                        return null;
                }
        }
        
        private String ns() { 
                return ntk(); 
        }
 
        private int ni() throws IOException {
                return Integer.parseInt(ntk());
        }
        
        private long nl() throws IOException {
                return Long.parseLong(ntk());
        }
        
        private float nf() throws IOException {
                return Float.parseFloat(ntk());
        }
        
        private double nd() throws IOException {
                return Double.parseDouble(ntk());
        }
        
        private void debug(Object... o) {
                if(!submit) {
                        System.out.println(Arrays.deepToString(o));
                }
        }
 
        public static void main(String args[]) throws IOException {
                new SoldierAndTraveling();
        }
        
        public SoldierAndTraveling() throws IOException {
                long start = System.currentTimeMillis();
                submit = !false;
                if(submit == false) br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\input.txt")));
                else br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
                
                int t = 1; 
                while(t-- > 0)
                        solve();
                
                long end = System.currentTimeMillis();
                debug(end - start, " ms");
                out.close();
        }
        
        int N, M, A[], B[];
        private void solve() throws IOException {
                N = ni(); M = ni();
                A = new int[N];
                B = new int[N];
                long sumA = 0, sumB = 0;
                for(int i = 0; i < N; i++) {
                        A[i] = ni();
                        sumA += A[i];
                }
                for(int i = 0; i < N; i++) {
                        B[i] = ni();
                        sumB += B[i];
                }
                if(sumA != sumB) {
                        out.println("NO");
                        return;
                }
                DinicGraph graph = new DinicGraph((2 * N) + 2);
                DinicGraph.Edge edge[][] = new DinicGraph.Edge[N][N];
                for(int i = 0; i < M; i++) {
                        int u = ni(), v = ni();
                        u--; v--;
                        edge[u][v] = graph.addEdge(u, N + v, Long.MAX_VALUE);
                        edge[v][u] = graph.addEdge(v, N + u, Long.MAX_VALUE);
                }
                int source = 2 * N, sink = source + 1;
                for(int i = 0; i < N; i++) {
                        edge[i][i] = graph.addEdge(i, N + i, Long.MAX_VALUE);
                        graph.addEdge(source, i, A[i]);
                        graph.addEdge(N + i, sink, B[i]);
                }
                if(graph.getMaxFlow(source, sink) != sumA) {
                        out.println("NO");
                        return;
                }
                out.println("YES");
                for(int i = 0; i < N; i++) {
                        for(int j = 0; j < N; j++) {
                                long flow;
                                if(edge[i][j] != null)
                                        flow = edge[i][j].flow;
                                else
                                        flow = 0;
                                out.print(flow + " ");
                        }
                        out.println();
                }
        }
}

class DinicGraph {
        public static class Edge {
                public int from, to;
                public long flow, capacity;
                public Edge reverse;

                public Edge(int from, int to, long flow, long capacity) {
                        this.from = from;
                        this.to = to;
                        this.flow = flow;
                        this.capacity = capacity;
                }
        }

        public LinkedList<Edge>[] adjacencyList;
        int[] cur;
        public int N, distance[];

        public DinicGraph(int N) {
                this.N = N;
                adjacencyList = new LinkedList[N];
                for (int i = 0; i < adjacencyList.length; i++) {
                        adjacencyList[i] = new LinkedList<>();
                }
                distance = new int[N];
                cur = new int[N];
        }

        public Edge addEdge(int from, int to, long capacity) {
                Edge e1 = new Edge(from, to, 0, capacity);
                Edge e2 = new Edge(to, from, 0, 0);
                e1.reverse = e2;
                e2.reverse = e1;
                adjacencyList[from].add(e1);
                adjacencyList[to].add(e2);
                return e1;
        }

        boolean bfs(int source, int target) {
                Arrays.fill(distance, Integer.MAX_VALUE);
                distance[source] = 0;
                LinkedList<Integer> Q = new LinkedList<>();
                Q.addLast(source);
                while (!Q.isEmpty()) {
                        int u = Q.removeFirst();
                        for (int i = 0; i < adjacencyList[u].size(); i++) {
                                Edge e = adjacencyList[u].get(i);
                                int v = e.to;
                                if (e.capacity - e.flow > 0 && distance[v] == Integer.MAX_VALUE) {
                                        distance[e.to] = distance[u] + 1;
                                        Q.addLast(v);
                                        if (v == target) {
                                                return true;
                                        }
                                }
                        }
                }
                return false;
        }

        public long dfs(int u, int target, long cMin) {
                if (u == target) {
                        return cMin;
                }
                for (int i = cur[u]; i < adjacencyList[u].size(); cur[u] = ++i) {
                        Edge e = adjacencyList[u].get(i);
                        int v = e.to;
                        if (distance[v] != distance[u] + 1 || e.capacity - e.flow == 0) {
                                continue;
                        }
                        long add = dfs(v, target, Math.min(cMin, e.capacity - e.flow));
                        if (add == 0) {
                                continue;
                        }
                        e.flow += add;
                        e.reverse.flow -= add;
                        return add;
                }
                return 0;
        }

        public long getMaxFlow(int source, int target) {
                long flow = 0;
                while (bfs(source, target)) {
                        Arrays.fill(cur, 0);
                        while (true) {
                                long add = dfs(source, target, Long.MAX_VALUE);
                                if (add == 0) {
                                        break;
                                }
                                flow += add;
                        }
                }
                return flow;
        }

}