#include using namespace std; #define INF 1000000000 #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) typedef long long LL; LL n1[11]; LL n2[11]; LL m[11]; LL A[11][70]; int main(){ int d; cin>>d; REP(i,d){ cin>>n1[i]>>n2[i]; cin>>m[i]; REP(j,m[i]){ cin>>A[i][j]; } } REP(i,d){ map,int>dp; vector s(2,0); s[0]=n1[i]; s[1]=n2[i]; dp[s]=0; REP(j,m[i]){ map,int>nxt; for(map,int>::iterator it=dp.begin();it!=dp.end();it++){ vector c=(it)->first; int num=it->second; nxt[c]=max(nxt[c],num); if(c[0]>=A[i][j]){ vectora(2,0); a[0]=c[0]-A[i][j]; a[1]=c[1]; nxt[a]=max(nxt[a],num+1); } if(c[1]>=A[i][j]){ vectora(2,0); a[0]=c[0]; a[1]=c[1]-A[i][j]; nxt[a]=max(nxt[a],num+1); } } swap(dp,nxt); } int mm=0; for(map,int>::iterator it=dp.begin();it!=dp.end();it++){ int num=it->second; if(mm