#include #include #include using namespace std; template class MaxFlowGraph{ private: struct Edge{ int to; T cap; int rev; }; using graph = vector>; graph G; vector used; public: MaxFlowGraph(int n){ G = graph(n); used = vector(n, false); } void add_edge(int from, int to, T cap){ G[from].push_back({to, cap, (int)G[to].size()}); G[to].push_back({from, 0, (int)G[from].size()-1}); } T dfs(int v, int t, T f){ if(v == t) return f; used[v] = true; for(int i = 0; i < G[v].size(); i++){ auto &e = G[v][i]; if(used[e.to] || e.cap == 0) continue; T d = dfs(e.to, t, min(f, e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } return 0; } T flow(int s, int t){ T maxflow = 0; while(true){ fill(used.begin(), used.end(), false); T INF = 1001001001; T f = dfs(s, t, INF); if(f == 0) return maxflow; else maxflow += f; } } }; int main(){ int w; cin >> w; int n; cin >> n; vector j(n); for(auto &p: j) cin >> p; int m; cin >> m; vector c(m); for(auto &p: c) cin >> p; vector> x(m, vector(n, 1)); for(int i = 0; i < m; i++){ int q; cin >> q; while(q--){ int xi; cin >> xi; x[i][xi-1] = 0; } } MaxFlowGraph G(n+m+2); const int s = n+m; const int t = n+m+1; for(int i = 0; i < n; i++) G.add_edge(s, i, j[i]); for(int i = 0; i < m; i++) G.add_edge(n+i, t, c[i]); for(int i = 0; i < m; i++){ for(int ii = 0; ii < n; ii++){ if(x[i][ii] == 1) G.add_edge(ii, n+i, 1001001001); } } int maxflow = G.flow(s, t); if(maxflow >= w) cout << "SHIROBAKO" << endl; else cout << "BANSAKUTSUKITA" << endl; return 0; }