#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a > G; vector used,indeg,ps; TopologicalSort(){} TopologicalSort(int n):G(n),used(n,0),indeg(n,0){} void add_edge(int s,int t){ G[s].emplace(t); indeg[t]++; } void bfs(int s){ queue que; que.emplace(s); used[s]=1; while(!que.empty()){ int v=que.front();que.pop(); ps.emplace_back(v); for(int u:G[v]){ indeg[u]--; if(indeg[u]==0&&!used[u]){ used[u]=1; que.emplace(u); } } } } vector build(){ int n=G.size(); for(int i=0;i>h>>w; vector as(h),bs(w); for(int i=0;i>as[i]; for(int i=0;i>bs[i]; auto check= [&](){ TopologicalSort G(h*w); auto idx=[&](int y,int x){return y*w+x;}; for(int i=0;i vs(w,-1); int len=(w+as[i]-1)/as[i]; int k=0; for(int j=0;j+len<=w;j+=len) for(int p=0;p; vector

vp; for(int j=0;j vs(h,-1); int len=(h+bs[j]-1)/bs[j]; int k=0; for(int i=0;i+len<=h;i+=len) for(int p=0;p; vector

vp; for(int i=0;i > ans(h,vector(w,0)); for(int i=0;i