#include using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair pdd; const ull mod = 1e9 + 7; #define REP(i,n) for(int i=0;i<(int)n;++i) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; template ostream& operator << (ostream& os, const pair v){ os << "(" << v.first << ", " << v.second << ")"; return os; } template ostream& operator << (ostream& os, const vector v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os; } template ostream& operator << (ostream& os, const vector> v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os; } typedef vector Edges; typedef vector Graph; const ll V_MAX = 160005; // !! SHOULD BE EDITTED !! vector ts(V_MAX, -1); bool topologicalSort(Graph &G){ ll V = G.size(); vector indeg(V, 0); queue qu; REP(i, V){ REP(j, G[i].size()){ indeg[G[i][j]]++; } } REP(i, V){ if(!indeg[i]) qu.push(i); } ll idx = 0; while(!qu.empty()){ ll s = qu.size(); REP(i, s){ ll now = qu.front();qu.pop(); ts[now] = idx; idx++; REP(j, G[now].size()){ ll next = G[now][j]; indeg[next]--; if(!indeg[next]) qu.push(next); } } } return (idx == V); } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll H, W; cin >> H >> W; vector A(H), B(W); REP(i, H) cin >> A[i]; REP(j, W) cin >> B[j]; sort(A.begin(), A.end()); sort(B.begin(), B.end()); Graph G(H*W); REP(i, H){ REP(j, W-1){ if(j