#define _USE_MATH_DEFINES #include using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; typedef pair P; 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; } templatevoid Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);} const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff; //template end vector

edge[410][410]; int cnt[410][410]={}; int ans[410][410]; int main(){ int h,w; scanf("%d%d",&h,&w); vector a(h),b(w); rep(i,0,h)scanf("%d",&a[i]); rep(i,0,w)scanf("%d",&b[i]); sort(ALL(a)); sort(ALL(b)); rep(i,0,h){ rep(j,0,w-a[i])edge[i][j].push_back({i,j+1}),cnt[i][j+1]++; rep(j,w-a[i],w-1)edge[i][j+1].push_back({i,j}),cnt[i][j]++; } rep(j,0,w){ rep(i,0,h-b[j])edge[i][j].push_back({i+1,j}),cnt[i+1][j]++; rep(i,h-b[j],h-1)edge[i+1][j].push_back({i,j}),cnt[i][j]++; } queue

q; int d=h*w; rep(i,0,h)rep(j,0,w)if(!cnt[i][j])q.push({i,j}); while(!q.empty()){ auto now=q.front(); q.pop(); int x=now.first,y=now.second; ans[x][y]=d; d--; for(auto nxt:edge[x][y]){ cnt[nxt.first][nxt.second]--; if(!cnt[nxt.first][nxt.second])q.push({nxt}); } } rep(i,0,h){ rep(j,0,w)printf("%d ",ans[i][j]); puts(""); } return 0; }