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 fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int src, des;
vector<int> adjl[510];
vector<int> rc[510], cap[510];
vector<int> rev_idx[510];
void add_edge(int u, int v, int w1, int w2) {
  adjl[u].push_back(v);
  adjl[v].push_back(u);
  rc[u].push_back(w1);
  cap[u].push_back(w1);
  rc[v].push_back(w2);
  cap[v].push_back(w2);
  rev_idx[u].push_back(adjl[v].size() - 1);
  rev_idx[v].push_back(adjl[u].size() - 1);
}
void clr(int foo) {
  for (int i = 0; i <= foo; i++) {
    adjl[i].clear();
    rc[i].clear();
    rev_idx[i].clear();
  }
}
int lev[510];
int vis[510];
bool dinic_bfs() {
  memset(vis, 0, sizeof(vis));
  memset(lev, 0, sizeof(lev));
  lev[src] = 0;
  vis[src] = 1;
  queue<int> myq;
  myq.push(src);
  while (!myq.empty()) {
    int u = myq.front();
    myq.pop();
    int sz = adjl[u].size();
    for (int i = 0; i <= sz - 1; i++) {
      int v = adjl[u][i];
      if (rc[u][i] == 0) {
        continue;
      }
      if (vis[v] == 0) {
        vis[v] = 1;
        lev[v] = lev[u] + 1;
        myq.push(v);
      }
    }
  }
  if (vis[des]) {
    return 1;
  }
  return 0;
}
int shuru[510];
int dinic_dfs(int u, int flow) {
  if (u == des) {
    return flow;
  }
  for (int i = shuru[u]; i <= (int)adjl[u].size() - 1; i++) {
    shuru[u] = i;
    int v = adjl[u][i];
    if ((lev[v] == lev[u] + 1) && (rc[u][i])) {
      int ff = dinic_dfs(v, min(flow, rc[u][i]));
      if (ff) {
        rc[u][i] -= ff;
        rc[v][rev_idx[u][i]] += ff;
        return ff;
      }
    }
  }
  shuru[u] = adjl[u].size();
  return 0;
}
int dinic() {
  int ans = 0;
  while (dinic_bfs()) {
    memset(shuru, 0, sizeof(shuru));
    while (1) {
      int ff = dinic_dfs(src, 1000000000);
      if (ff == 0) break;
      ans += ff;
    }
  }
  return ans;
}
int ans[510][510];
int n, m;
int a[510], b[510];
int in_node[510], out_node[510];
int ulta_in[510], ulta_out[510];
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ss = 0;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    ss += b[i];
  }
  int pos = 0;
  for (int i = 1; i <= n; i++) {
    ulta_in[pos] = i;
    in_node[i] = pos++;
    ulta_out[pos] = i;
    out_node[i] = pos++;
  }
  src = pos++;
  des = pos++;
  for (int i = 1; i <= n; i++) {
    add_edge(src, in_node[i], a[i], 0);
    add_edge(out_node[i], des, b[i], 0);
    add_edge(in_node[i], out_node[i], 1000000000, 0);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    add_edge(in_node[u], out_node[v], 1000000000, 0);
    add_edge(in_node[v], out_node[u], 1000000000, 0);
  }
  if (dinic() == ss) {
    bool chk = 1;
    for (int u = 1; u <= n; u++) {
      int patha = 0;
      int k1 = in_node[u];
      for (int i = 0; i <= (int)adjl[k1].size() - 1; i++) {
        int k2 = adjl[k1][i];
        if (k2 == src || k2 == des) {
          continue;
        }
        int v = ulta_out[k2];
        ans[u][v] = cap[k1][i] - rc[k1][i];
        patha += ans[u][v];
      }
      if (patha != a[u]) {
        chk = 0;
      }
    }
    if (chk) {
      cout << "YES\n";
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          cout << ans[i][j] << " ";
        }
        cout << "\n";
      }
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}