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

import static java.lang.Integer.MAX_VALUE;

/**
 * 546E
 *
 * @author artyom
 */
public class SoldierAndTraveling implements Runnable {
    private BufferedReader in;
    private PrintStream out;
    private StringTokenizer tok;

    private void solve() throws IOException {
        int n = nextInt(), m = nextInt();
        int[] a = readIntArray(n), b = readIntArray(n);
        int sum1 = 0, sum2 = 0;
        Network<Integer> graph = new Network<>();
        Queue<Edge<Integer>> edges = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            insertEdge(graph.nodes, -1, i, a[i]);
            edges.add(insertEdge(graph.nodes, i, n + i, a[i]));
            insertEdge(graph.nodes, n + i, -2, b[i]);
            sum1 += a[i];
            sum2 += b[i];
        }
        for (int i = 0; i < m; i++) {
            int p = nextInt(), q = nextInt();
            edges.add(insertEdge(graph.nodes, p - 1, n + q - 1, a[p - 1]));
            edges.add(insertEdge(graph.nodes, q - 1, n + p - 1, a[q - 1]));
        }
        int flow = netFlow(graph, graph.nodes.get(-1), graph.nodes.get(-2));
        if (flow != sum1 || flow != sum2) {
            out.print("NO");
            return;
        }
        int[][] mx = new int[n][n];
        for (Edge<Integer> edge : edges) {
            mx[edge.source.value % n][edge.target.value % n] = edge.flow;
        }
        out.println("YES");
        for (int i = 0; i < n; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < n; j++) {
                sb.append(mx[i][j]).append(' ');
            }
            out.println(sb.toString().trim());
        }
    }

    //--------------------------------------------------------------
    public static void main(String[] args) {
        new SoldierAndTraveling().run();
    }

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = System.out;
            tok = null;
            solve();
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    private String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private int[] readIntArray(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }
        return arr;
    }

    // --- Dinitz ---
    private static <V> Edge<V> insertEdge(Map<V, Vertex<V>> vertices,
                                          V source, V target, int capacity) {
        Vertex<V> sVertex = addIfAbsent(vertices, source);
        Vertex<V> tVertex = addIfAbsent(vertices, target);
        Edge<V> edge = new Edge<>(sVertex, tVertex, capacity);
        sVertex.incidentEdges.add(edge);
        tVertex.incidentEdges.add(edge.residualEdge);
        return edge;
    }

    private static <V> Vertex<V> addIfAbsent(Map<V, Vertex<V>> vertices, V value) {
        Vertex<V> vertex = vertices.get(value);
        if (vertex == null) {
            vertex = new Vertex<>(value);
            vertices.put(value, vertex);
        }
        return vertex;
    }

    // O(|E||V|^2)
    private static <V> int netFlow(Network<V> graph, Vertex<V> source, Vertex<V> sink) {
        int totalVolume = 0;
        while (true) { // O(|V|) phases
            buildLayeredNetwork(graph, source); // O(|V| + |E|)
            if (sink.inEdges.isEmpty()) { // O(1)
                break;
            }
            while (!sink.inEdges.isEmpty()) { // O(|E|) iterations
                Queue<Edge<V>> path = new LinkedList<>();
                int volume = findPath(sink, path); // O(|V|)
                Collection<Edge<V>> saturatedEdges = changeFlow(path, volume); // O(|V|)
                clean(saturatedEdges); // O(|V| + |E|)
                totalVolume += volume;
            }
        }
        return totalVolume;
    }

    private static <V> void buildLayeredNetwork(Network<V> graph, Vertex<V> source) {
        for (Vertex<V> vertex : graph.nodes.values()) {
            vertex.layer = MAX_VALUE;
            vertex.inEdges.clear();
            vertex.outEdges.clear();
        }
        source.layer = 0;
        Queue<Vertex<V>> q = new LinkedList<>();
        q.add(source);
        while (!q.isEmpty()) {
            Vertex<V> v = q.poll();
            for (Edge<V> edge : v.incidentEdges) {
                if (edge.residual > 0 && edge.target.layer > v.layer) {
                    v.outEdges.add(edge);
                    edge.target.inEdges.add(edge);
                    if (edge.target.layer == MAX_VALUE) {
                        q.add(edge.target);
                        edge.target.layer = v.layer + 1;
                    }
                }
            }
        }
    }

    private static <V> void clean(Collection<Edge<V>> edges) {
        rightPass(new ArrayDeque<>(edges));
    }

    private static <V> void rightPass(Queue<Edge<V>> q) {
        while (!q.isEmpty()) {
            Edge<V> edge = q.poll();
            edge.target.inEdges.remove(edge);
            if (edge.target.inEdges.isEmpty()) {
                q.addAll(edge.target.outEdges);
            }
        }
    }

    private static <V> int findPath(Vertex<V> sink, Queue<Edge<V>> path) {
        int flow = 0;
        Vertex<V> vertex = sink;
        while (!vertex.inEdges.isEmpty()) {
            Edge<V> edge = vertex.inEdges.iterator().next();
            path.add(edge);
            vertex = edge.source;
            if (edge.residual < flow || flow == 0) {
                flow = edge.residual;
            }
        }
        return flow;
    }

    private static <V> Collection<Edge<V>> changeFlow(Queue<Edge<V>> edges, int volume) {
        Collection<Edge<V>> saturated = new LinkedList<>();
        for (Edge<V> edge : edges) {
            edge.flow += volume;
            edge.residual -= volume;
            edge.residualEdge.flow -= volume;
            edge.residualEdge.residual += volume;
            if (edge.flow == edge.capacity) {
                saturated.add(edge);
            }
        }
        return saturated;
    }

    private static final class Network<V> {
        private final Map<V, Vertex<V>> nodes;

        Network() {
            nodes = new HashMap<>();
        }

        @Override
        public String toString() {
            return nodes.values().toString();
        }
    }

    private static final class Vertex<V> {
        final V value;
        final List<Edge<V>> incidentEdges;
        final Set<Edge<V>> inEdges;
        final Set<Edge<V>> outEdges;
        int layer;

        Vertex(V value) {
            this.value = value;
            incidentEdges = new LinkedList<>();
            inEdges = new HashSet<>();
            outEdges = new HashSet<>();
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            Vertex<?> vertex = (Vertex<?>) o;

            return value.equals(vertex.value);
        }

        @Override
        public int hashCode() {
            return value.hashCode();
        }

        @Override
        public String toString() {
            return "<" + value + ">";
        }
    }

    private static final class Edge<V> {
        final Vertex<V> source;
        final Vertex<V> target;
        final int capacity;
        int flow;
        int residual;
        Edge<V> residualEdge;

        Edge(Vertex<V> source, Vertex<V> target, int capacity) {
            this.source = source;
            this.target = target;
            this.capacity = capacity;
            this.residual = capacity;
            this.residualEdge = new Edge<>(this);
        }

        Edge(Edge<V> edge) {
            this.source = edge.target;
            this.target = edge.source;
            this.capacity = 0;
            this.residual = 0;
            this.residualEdge = edge;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            Edge<?> edge = (Edge<?>) o;

            return source.equals(edge.source) && target.equals(edge.target);
        }

        @Override
        public int hashCode() {
            int result = source.hashCode();
            result = 31 * result + target.hashCode();
            return result;
        }

        @Override
        public String toString() {
            return "(" + source + ',' + target + ',' + flow + ',' + capacity + ')';
        }
    }
}