#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 struct Dinic{ struct edge { int to; T cap; int rev; edge(){} edge(int to,T cap,int rev):to(to),cap(cap),rev(rev){} }; vector > G; vector level,iter; Dinic(){} Dinic(int n):G(n),level(n),iter(n){} int add_edge(int from,int to,T cap){ G[from].emplace_back(to,cap,G[to].size()); G[to].emplace_back(from,directed?0:cap,G[from].size()-1); return G[to].back().rev; } void bfs(int s){ fill(level.begin(),level.end(),-1); queue que; level[s]=0; que.emplace(s); while(!que.empty()){ int v=que.front();que.pop(); for(int i=0;i<(int)G[v].size();i++){ edge &e=G[v][i]; if(e.cap>0&&level[e.to]<0){ level[e.to]=level[v]+1; que.emplace(e.to); } } } } T dfs(int v,int t,T f){ if(v==t) return f; for(int &i=iter[v];i<(int)G[v].size();i++){ edge &e=G[v][i]; if(e.cap>0&&level[v]1.5) break; fill(iter.begin(),iter.end(),0); while(1){ T f=dfs(s,t,lim); if(f==0) break; fl+=f; lim-=f; } } return fl; } T flow(int s,int t){ return flow(s,t,numeric_limits::max()/2); } T cut(int s,int t,int x,int a){ static_assert(directed, "must be directed"); auto &e=G[x][a]; int y=e.to; T cr=G[y][e.rev].cap; if(cr==0) return e.cap=0; e.cap=G[y][e.rev].cap=0; T cap=cr-flow(x,y,cr); if(x!=s&&cap!=0) flow(x,s,cap); if(t!=y&&cap!=0) flow(t,y,cap); return cap; } T link(int s,int t,int x,int a,T f){ auto &e=G[x][a]; e.cap+=f; return flow(s,t,f); } }; //INSERT ABOVE HERE signed main(){ int h,w; cin>>h>>w; vector< vector > G(h,vector(w)); for(int i=0;i>G[i][j]; vector rs(h),cs(w); for(int i=0;i>rs[i]; for(int j=0;j>cs[j]; Dinic F(h*w+h+w+2); int S=h*w+h+w; int T=S+1; long long sum=0; for(int r:rs) sum+=r; for(int c:cs) sum+=c; const long long INF = 1e9+1; for(int i=0;i