#include using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,x,y;cin>>n>>x>>y; vector> P(n,{-1,-1}), match(x); vector> Q(y); REP(i1,x){ int k;cin>>k; match[i1]={-1,k}; REP(j1,k+1){ int u;cin>>u;u--; if(clamp(u,0,n-1)==u) P[u]={i1,j1}; } } REP(i2,y){ int l;cin>>l; REP(j2,l+1){ int v;cin>>v;v--; if(clamp(v,0,n-1)==v and ~P[v].first) Q[i2].push(v); } } queue que; REP(i2,y)que.push(i2); while(que.size()){ int i2=que.front();que.pop(); while(Q[i2].size()){ int v=Q[i2].top();Q[i2].pop(); const auto&[i1,j1]=P[v]; const auto&[now_i2, now_j1] = match[i1]; if(now_j1 > j1){ if(~now_i2) que.push(now_i2); match[i1] = {i2, j1}; break; } } } int ans=0; for(const auto&[_,score]:match) ans += score; cout<