#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; int main(){ int h,w; cin>>h>>w; int a[h],b[w]; rep(i,h)cin>>a[i]; sort(a,a+h); rep(j,w)cin>>b[j]; sort(b,b+w); vector v[h*w]; vector cnt(h*w); rep(i,h){ rep(j,a[i]-1){ v[i*w+j].push_back(i*w+j+1); ++cnt[i*w+j+1]; } REP(j,a[i]-1,w-1){ v[i*w+j+1].push_back(i*w+j); ++cnt[i*w+j]; } } rep(j,w){ rep(i,b[j]-1){ v[i*w+j].push_back((i+1)*w+j); ++cnt[(i+1)*w+j]; } REP(i,b[j]-1,h-1){ v[(i+1)*w+j].push_back(i*w+j); ++cnt[i*w+j]; } } vector ans(h*w); queue q; int idx = 0; rep(i,h*w){ if(cnt[i]==0){ q.push(i); } } while(q.size()){ int cur = q.front();q.pop(); ans[cur]=++idx; for(auto to : v[cur]){ if(--cnt[to]==0)q.push(to); } } rep(i,h){ rep(j,w)cout<