#include using namespace std; using ll=long long; #define MOD 1000000007 #define INF 1000000000 typedef int FLOW; struct Edge{ int from,to; FLOW cap; Edge(int f,int t,FLOW c){ from=f; to=t; cap=c; } }; struct Graph{ vector> list; Graph(int n){ list.resize(n); for(int i=0;i level; void dibfs(Graph &G,int s){ int N=G.size(); level.resize(N); for(int i=0;i q; q.push(s); while(!q.empty()){ int v=q.front(); q.pop(); for(auto e:G.list.at(v)){ if(e.cap>0&&level.at(e.to)==-1){ level.at(e.to)=level.at(v)+1; q.push(e.to); } } } } FLOW didfs(Graph &G,int v,int t,FLOW f){ if(v==t){ return f; } for(auto &e:G.list.at(v)){ if(e.cap>0&&level.at(v)0){ Edge &re=G.redge(e); e.cap-=d; re.cap+=d; return d; } } } return 0; } FLOW Dinic(Graph &G,int s,int t){ FLOW res=0; while(true){ dibfs(G,s); if(level.at(t)==-1){ return res; } FLOW flow; while((flow=didfs(G,s,t,INF))>0){ res+=flow; } } } int main(){ int W,N; cin>>W>>N; vector J(N); for(int i=0;i>J.at(i); } int M; cin>>M; vector C(M); for(int i=0;i>C.at(i); } vector Q(M); vector> X(M); for(int i=0;i>Q.at(i); X.at(i).resize(Q.at(i)); for(int j=0;j>X.at(i).at(j); X.at(i).at(j)--; } } int S=M+N; int T=M+N+1; Graph G(N+M+2); for(int i=0;i