#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair P; //最大二部マッチング復元 https://judge.yosupo.jp/submission/1148 const ll INF=1e18; struct edge {int to; ll cap; int rev;} ; vector G[500020]; int level[500020]; int iter[500020]; void add_edge(int from, int to, ll cap){ edge e; e.to=to, e.cap=cap, e.rev=G[to].size(); G[from].push_back(e); e.to=from, e.cap=0, e.rev=G[from].size()-1; G[to].push_back(e); } void bfs(int s){ memset(level, -1, sizeof(level)); queue que; level[s]=0; que.push(s); while(!que.empty()){ int v=que.front(); que.pop(); for(int i=0; i0 && level[e.to]<0){ level[e.to]=level[v]+1; que.push(e.to); } } } } ll dfs(int v, int t, ll f){ if(v==t) return f; for(int &i=iter[v]; i0 && level[v]0){ e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0; } ll max_flow(int s, int t){ ll flow=0; while(1){ bfs(s); if(level[t]<0) return flow; memset(iter, 0, sizeof(iter)); ll f; while((f=dfs(s, t, INF))>0){ flow+=f; } } } vector

v[500050]; int main() { int h, w; cin>>h>>w; for(int i=0; i>a; v[a].push_back({i, j}); } } int s=h+w, t=s+1; int ans=0; for(int i=1; i<=500000; i++){ if(v[i].empty()) continue; set st; for(auto p:v[i]){ st.insert(p.first); st.insert(p.second+h); } for(auto x:st){ if(x