#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma optimize("gtsy", on)
using namespace std;
const long double EPS = 1e-8;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > ans(n, vector<int>(m));
  vector<int> a(n), b(m);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) cin >> b[i];
  for (int k = 0; k < 30; ++k) {
    vector<int> c, d;
    for (int i = 0; i < n; ++i)
      if (a[i] & (1 << k)) c.push_back(i);
    for (int i = 0; i < m; ++i)
      if (b[i] & (1 << k)) d.push_back(i);
    if (c.size() % 2 != d.size() % 2) {
      cout << "NO";
      return 0;
    }
    for (int i = 0; i < min(c.size(), d.size()); ++i) {
      ans[c[i]][d[i]] |= (1 << k);
    }
    if (c.size() > d.size()) {
      for (int i = (d.size()); i <= (c.size() - 1); ++i)
        ans[c[i]][0] |= (1 << k);
    } else if (c.size() < d.size()) {
      for (int i = (c.size()); i <= (d.size() - 1); ++i)
        ans[0][d[i]] |= (1 << k);
    }
  }
  cout << "YES" << '\n';
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) cout << ans[i][j] << ' ';
    cout << '\n';
  }
  return 0;
}
