// Edmonds-Karp法 #include <cstdio> #include <vector> #include <algorithm> #include <cstring> #include <tuple> #include <queue> typedef std::tuple<int,int,int> P; const int INF = 1001001001; int W, N, M; int J[51], C[51]; // [0, N): 原画 // [N, N+M): 作画監督 // N+M: 始点 // N+M+1: 終点 std::vector<P> G[200]; bool visited[200]; int prevVertex[200], prevIndex[200], mns[200]; void addEdge(int from, int to, int cap){ G[from].emplace_back(to, cap, G[to].size()); G[to].emplace_back(from, 0, G[from].size()-1); } int bfs(){ std::fill(visited, visited+200, false); std::fill(mns, mns+200, INF); std::queue<int> queue; queue.push(N+M); visited[N+M] = true; while(!queue.empty()){ int u = queue.front(); queue.pop(); if(u == N+M+1){break;} for(int i=0;i<(int)G[u].size();i++){ int to, cap; std::tie(to, cap, std::ignore) = G[u][i]; if(visited[to]){continue;} if(cap == 0){continue;} visited[to] = true; prevVertex[to] = u; prevIndex[to] = i; mns[to] = std::min(mns[u], cap); queue.push(to); } } if(!visited[N+M+1]){return 0;} int f = mns[N+M+1]; for(int u=N+M+1;u!=N+M;){ int pv = prevVertex[u], pi = prevIndex[u]; std::get<1>(G[pv][pi]) -= f; std::get<1>(G[u][std::get<2>(G[pv][pi])]) += f; u = pv; } return f; } int maxFlow(){ int f = 0; while(1){ int x = bfs(); if(x == 0){return f;} f += x; } } int main(){ scanf("%d", &W); scanf("%d", &N); for(int i=0;i<N;i++){ scanf("%d", J+i); } scanf("%d", &M); for(int i=0;i<M;i++){ scanf("%d", C+i); } for(int i=0;i<M;i++){ addEdge(i+N, N+M+1, C[i]); } for(int i=0;i<N;i++){ addEdge(N+M, i, J[i]); } for(int i=0;i<M;i++){ int q; scanf("%d", &q); bool flags[51]; std::fill(flags, flags+51, false); for(int j=0;j<q;j++){ int x; scanf("%d", &x); x -= 1; flags[x] = true; } for(int j=0;j<N;j++){ if(flags[j]){continue;} addEdge(j, i+N, J[j]); } } // printf("%d\n", maxFlow()); if(maxFlow() >= W){puts("SHIROBAKO");} else{puts("BANSAKUTSUKITA");} }