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.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(in, out);
        out.close();
    }
}

class Edge {
    int from;
    int to;
    int flow;
    int capacity;

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

class MaxFlow {
    private static final int INFINITY = Integer.MAX_VALUE;
    private List<Integer> graph[];

    private List<Edge> edges;

    private int level[];

    private int begin[];

    public MaxFlow(List<Integer> graph[], List<Edge> edges) {
        this.graph = graph;
        this.edges = edges;
        this.level = new int[graph.length];
        this.begin = new int[graph.length];
    }

    public int dinic(int source, int sink) {
        int maxFlow = 0;
        int pushed = 0;
        while(bfs(source, sink)) {
            for(int i=0;i<begin.length;i++) {
                begin[i] = 0;
            }
            while((pushed = dfs(source, sink, INFINITY)) > 0) {
                maxFlow += pushed;
            }
        }
        return maxFlow;
    }

    private int dfs(int vertex, int sink, int flow) {
        if(flow <=0 ) return 0;
        if(vertex == sink) return flow;

        for(; begin[vertex] < graph[vertex].size(); begin[vertex]++ ) {
            int edgeID = graph[vertex].get(begin[vertex]);
            Edge edge = edges.get(edgeID);
            if(level[edge.to] != level[vertex] + 1) continue;
            int pushed = dfs(edge.to, sink, Math.min(flow, edge.capacity - edge.flow));
            if(pushed > 0) {
                edges.get(edgeID).flow += pushed;
                edges.get(edgeID^1).flow -= pushed;
                return pushed;
            }
        }
        return 0;
    }

    private boolean bfs(int source, int sink) {
        for(int i=0;i<level.length;i++) {
            level[i] = -1;
        }
        level[source] = 0;
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(source);
        int vertex;
        while(!queue.isEmpty()) {
            vertex = queue.remove();
            for(int edgeID : graph[vertex]) {
                Edge edge = edges.get(edgeID);
                if(level[edge.to] == -1 && edge.capacity > edge.flow) {
                    queue.add(edge.to);
                    level[edge.to] = level[vertex] + 1;
                }

            }
        }
        return level[sink] != -1;
    }
}



class TaskE {

    private List<Integer> graph[];

    private List<Edge> edges;

    private int MAXN = 2000;

    private static final int INFINITY = Integer.MAX_VALUE;

    public void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();

        graph = new List[MAXN];
        for(int i=0;i<graph.length;i++) {
            graph[i] = new ArrayList<>();
        }
        edges = new ArrayList<>();

        int initial[] = new int[MAXN];
        int expected[] = new int [MAXN];

        int initialSum = 0;
        for(int i=1;i<=n;i++) {
            initial[i] = in.nextInt();
            initialSum += initial[i];
            addEdge(0, i, initial[i]);
            addEdge(i, 1000 + i, initial[i]);
        }
        int expectedSum = 0;
        int sink = 999;
        for(int i=1;i<=n;i++) {
            expected[i] = in.nextInt();
            expectedSum += expected[i];
            addEdge(i+1000, sink, expected[i]);
        }

        int source = 0;
        int from, to;
        for(int i=0;i<m;i++) {
            from = in.nextInt();
            to = in.nextInt();
            addEdge(from, 1000 + to, INFINITY);
            addEdge(to, 1000 + from, INFINITY);
        }

        MaxFlow maxFlow = new MaxFlow(graph, edges);

        int flow = maxFlow.dinic(source, sink);
        if(flow != expectedSum || initialSum != expectedSum) {
            out.printLine("NO");
            return;
        }
        int result[][] = new int[n][n];
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                if(i == j) {
                    result[i][j] = initial[i+1];
                }
            }
        }
        for(int i=1;i<=n;i++) {
            for(int edgeID : graph[i]) {
                Edge edge = edges.get(edgeID);
                if(edge.to >= 1000) {
                    result[edge.from-1][edge.to-1001] = edge.flow;

                }
            }
        }

        out.printLine("YES");
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                out.print(result[i][j] + " ");
            }
            out.printLine();
        }
    }

    private void addEdge(int from, int to, int capacity) {
        graph[from].add(edges.size());
        Edge forwardEdge = new Edge(from, to, capacity);
        edges.add(forwardEdge);
        graph[to].add(edges.size());
        Edge backwardEdge = new Edge(to, from, 0);
        edges.add(backwardEdge);
    }


}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if ( line == null ) {
                    return false;
                }
                tokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
class OutputWriter {
    private final PrintWriter writer;
    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }
    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }
    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if ( i != 0 ) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }
    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }
    public void close() {
        writer.close();
    }
}