#include #include #include #include #include using namespace std; int N,M,K; map > >mp; main() { cin>>N>>M>>K; vectorvs; for(int i=0;i>A; mp[A%K].push_back(make_pair(A,i)); vs.push_back(A); } sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); auto id=[&vs](int x){return lower_bound(vs.begin(),vs.end(),x)-vs.begin();}; atcoder::mcf_graphmf(vs.size()+2); int source=vs.size(),sink=source+1; for(auto it=mp.begin();it!=mp.end();it++) { vector >now; now.swap(it->second); sort(now.begin(),now.end()); for(int i=0;ians=mf.flow(source,sink); if(ans.first==min(N,M))cout<