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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int flow[110][110], a[110], b[110];
struct arc {
  int res, cap, u, v;
  int cst;
  arc(int u, int v, int cap, int res, int cst) {
    this->u = u;
    this->v = v;
    this->cap = cap;
    this->res = res;
    this->cst = cst;
  }
};
vector<arc> arcs;
int last;
vector<int> p;
vector<vector<int> > adj;
int augment(int s, int t, int f) {
  int v = t;
  int cost = 0;
  while (p[v] != -1) {
    int e = p[v];
    arcs[e].res -= f;
    arcs[(((e)&1) ? ((e)-1) : ((e) + 1))].res += f;
    cost += f * arcs[e].cst;
    v = arcs[e].u;
  }
  return cost;
}
int dijkstra(int n, int s, int t) {
  vector<int> dist(n, 1000000000);
  dist[s] = 0;
  p.assign(n, -1);
  vector<int> f(n, 0);
  f[s] = 1000000000;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push(pair<int, int>(0, s));
  while (!pq.empty()) {
    pair<int, int> front = pq.top();
    pq.pop();
    int d = front.first;
    int u = front.second;
    if (u == t) break;
    if (d == dist[u]) {
      for (auto j = 0; j < (((int)((adj[u]).size()))); j++) {
        int e = adj[u][j];
        int v = arcs[e].v;
        if (dist[u] + arcs[e].cst < dist[v] && arcs[e].res > 0) {
          dist[v] = dist[u] + arcs[e].cst;
          f[v] = min(f[u], arcs[e].res);
          p[v] = e;
          pq.push(pair<int, int>(dist[v], v));
        }
      }
    }
  }
  return f[t];
}
pair<int, int> mincost_flow(int n, int s, int t, int tf) {
  int f, mf;
  int cost = 0;
  for (mf = 0; mf < tf; mf += min(tf - mf, f)) {
    f = dijkstra(n, s, t);
    if (f == 0) break;
    cost += augment(s, t, min(tf - mf, f));
  }
  return pair<int, int>(mf, cost);
}
void init(int n) {
  adj.assign(n, vector<int>());
  arcs.clear();
  last = 0;
}
int add_arc(int u, int v, int capacity, int cost) {
  arcs.push_back(arc(u, v, capacity, capacity, cost));
  adj[u].push_back(last++);
  return last - 1;
}
void add_edge(int u, int v, int capacity, int cost) {
  add_arc(u, v, capacity, cost);
  add_arc(v, u, 0, -cost);
}
int main(int argc, char const* argv[]) {
  int n, m, s, e, p, q, sum1 = 0, sum2 = 0, ok = 0;
  cin >> n >> m;
  init(2 * n + 2);
  s = 0, e = 2 * n + 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    add_edge(s, i, a[i], 0);
    sum1 += a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    add_edge(n + i, e, b[i], 0);
    sum2 += b[i];
  }
  if (sum1 == sum2) {
    while (m--) {
      cin >> p >> q;
      add_edge(p, n + q, 100, 0);
      add_edge(q, n + p, 100, 0);
    }
    for (int i = 1; i <= n; i++) {
      add_edge(i, n + i, 100, 0);
    }
    auto ans = mincost_flow(2 * n + 2, s, e, sum1);
    ok = ans.first == sum1;
  }
  cout << (ok ? "YES" : "NO") << '\n';
  if (ok) {
    memset(flow, 0, sizeof flow);
    for (auto& ar : arcs) {
      if (1 <= ar.u && ar.u <= n && n + 1 <= ar.v && ar.v <= n + n)
        flow[ar.u][ar.v - n] += ar.cap - ar.res;
    }
    for (int i = 1; i <= n; i++) {
      int sum = 0;
      for (int j = 1; j <= n; j++) {
        sum += flow[i][j];
      }
      assert(sum == a[i]);
    }
    for (int i = 1; i <= n; i++) {
      int sum = 0;
      for (int j = 1; j <= n; j++) {
        sum += flow[j][i];
      }
      assert(sum == b[i]);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        assert(flow[i][j] >= 0);
        assert(flow[i][j] <= a[i]);
        assert(flow[i][j] <= b[j]);
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        cout << flow[i][j] << " ";
      }
      cout << '\n';
    }
  }
  return 0;
}