#define _USE_MATH_DEFINES #include #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// struct edge{int to,cap,rev;}; const int Finf = (int)1e7; const int Emax = 3000; vector E[Emax]; bool use[Emax]; void add_edge(int x,int y,int cap){ edge t = {y,cap,E[y].size() }; E[x].push_back( t ); edge u = {x,0,E[x].size()-1 }; E[y].push_back( u ); } int dfs(int from,int to,int cf){ int tf; if( from == to ) return cf; use[from] = true; for(unsigned int i=0; i 0 && ( tf = dfs(e.to,to,min(cf,e.cap)))>0){ e.cap -= tf; E[e.to][e.rev].cap += tf; return tf; } } return 0; } int maxflow(int from,int to){ int fl = 0; int tf; for(;;){ //memset(use,0,sizeof(use) ); rep(i,Emax){ use[i] = false; } tf = dfs(from,to,Finf); if( tf == 0 )return fl; fl += tf; } } int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(16);// int W,N; cin>>W>>N; rep(i,Emax){ E[i].clear(); } int sor = 0; int tin = 1; int J[50]; rep(i,N){ cin>>J[i]; add_edge( sor,i+2,J[i] ); } int M; cin>>M; int C[50]; rep(i,M){ cin>>C[i]; add_edge( 2+N+i,tin,C[i] ); } bool line[50][50]; rep(i,50)rep(j,50)line[i][j]=true; int Q,X; rep(i,M){ cin>>Q; rep(j,Q){ cin>> X; --X; //X->i //line[2+N+i][X+2] = false; line[X+2][2+N+i] = false; } rep(j,N){//j->i if(line[j+2][2+N+i] == true ){ add_edge( j+2,2+N+i,Finf ); } } } int ans; ans = maxflow(sor,tin); if( ans >= W){ cout << "SHIROBAKO\n"; }else{ cout << "BANSAKUTSUKITA\n"; } return 0; }