#include #include #include #define llint long long using namespace std; llint h, w; llint a[405], b[405]; llint ans[405][405]; vector G[200005]; vector topo; bool used[200005]; void tpsort(int v) { used[v] = true; for(int i = 0; i < G[v].size(); i++){ if(!used[G[v][i]]) tpsort(G[v][i]); } topo.push_back(v); } llint get(llint r, llint c) { return r * w + c; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for(int i = 0; i < h; i++) cin >> a[i], a[i]--; for(int i = 0; i < w; i++) cin >> b[i], b[i]--; sort(a, a+h); sort(b, b+w); for(int i = 0; i < h; i++){ for(int j = a[i]-1; j >= 0; j--) G[get(i, j)].push_back(get(i, j+1)); for(int j = a[i]+1; j < w; j++) G[get(i, j)].push_back(get(i, j-1)); } for(int i = 0; i < w; i++){ for(int j = b[i]-1; j >= 0; j--) G[get(j, i)].push_back(get(j+1, i)); for(int j = b[i]+1; j < h; j++) G[get(j, i)].push_back(get(j-1, i)); } for(int i = 0; i < h*w; i++) if(!used[i]) tpsort(i); reverse(topo.begin(), topo.end()); for(int i = 0; i < topo.size(); i++){ int v = topo[i]; ans[v/w][v%w] = i+1; } for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cout << ans[i][j] << " "; } cout << endl; } return 0; }