#include #include using mint = atcoder::static_modint<998244353>; //using mint = atcoder::static_modint<1000000007>; using namespace std; using namespace atcoder; using ld = long double; using ll = long long; #define mp(a,b) make_pair(a,b) #define rep(i,s,n) for(int i=s; i dx{1,0,-1,0},dy{0,1,0,-1}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int w;cin >> w; int n;cin >> n; vector j(n+1);rep(i,1,n+1)cin >> j[i]; int m;cin >> m; vector c(m+1);rep(i,1,m+1)cin >> c[i]; mf_graph G(n+m+2); rep(i,1,n+1)G.add_edge(0,i,j[i]); rep(i,1,m+1)G.add_edge(n+i,n+m+1,c[i]); rep(i,1,m+1){ int Q; cin >> Q; vector good(n+1,true); rep(j,0,Q){ int x;cin >> x; good[x]=false; } rep(j,1,n+1)if(good[j]){ G.add_edge(j,n+i,10000); } } if(G.flow(0,n+m+1)