#include // #include using namespace std; // using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; int main() { lint H, W; cin >> H >> W; vi v(H), w(W); vin(v); vin(w); lint a=0, b=0, c=0, x, y, z; vvi m(H, vi(W, 1)); m[0][0] = 100100100; repx(i, 1, H) { a = i; rep(j, W) { m[i][j] = ++a; } } repx(i, 1, H) { lint ng = 100100100, mid, ok = 1; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; a = mid, b = 1; repx(j, 1, W) { if (chmax(a, m[i][j])) b++; } if (b < v[i]) ng = mid; else ok = mid; } m[i][0] = ok; } repx(j, 1, W) { lint ng = 100100100, mid, ok = 1; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; a = mid, b = 1; repx(i, 1, H) { if (chmax(a, m[i][j])) b++; } if (b < w[j]) ng = mid; else ok = mid; } m[0][j] = ok; } rep(i, H) vout(m[i]); }