#include using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init; struct edge{ int flow,to,rev; }; typedef vector E; typedef vector Graph; vector bfs(Graph& G,int s){ int N = G.size(); queue que; vector dist(N,-1); dist[s] = 0; que.push(s); for(;!que.empty();que.pop()){ auto v=que.front(); for(auto& e : G[v]) if(e.flow>0&&dist[e.to]==-1){ dist[e.to] = dist[v] + 1; que.push(e.to); } } return dist; } int maxflow(Graph& G,int s,int t){ int res=0; int N = G.size(); while(true){ auto dist = bfs(G,s); if(dist[t] < 0)break; vector iter(N,0); std::function dfs=[&](int v,int f){ if(v==s)return f; for(auto &i = iter[v]; i < G[v].size(); i++){ edge &e = G[v][i]; edge &re = G[e.to][e.rev]; if(re.flow>0 && dist[v] >dist[e.to]){ int d=dfs(e.to,min(f,re.flow)); if(d>0){e.flow+=d;re.flow-=d;return d;} } } return 0; }; int f; while((f=dfs(t,114514))> 0)res+=f; } return res; } void addedge(Graph& g,int a,int b,int f){ int c=g[a].size(); int d=g[b].size(); g[a].push_back(edge{f,b,d}); g[b].push_back(edge{0,a,c}); } typedef vector V; typedef vector VV; int main(){ int R,C; cin>>R>>C; vector choko(R); for(auto &s:choko)cin>>s; int B=0,W=0; int S=0; int G=1; VV id(R,V(C)); int cnt=2; for(auto &v:id)for(auto &u:v)u=cnt++; Graph g(cnt); for(int r=0;r