#include #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; typedef tuple t3; typedef tuple t4; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) #include using namespace std; template void chmax(T& reference, T value) { reference = max(reference, value); } template void chmaxmap(map& m, T key, T value) { if (m.count(key)) { chmax(m[key], value); } else { m[key] = value; } } template void chmin(T& reference, T value) { reference = min(reference, value); } #include using namespace atcoder; struct MaxFlowCalculator { typedef ll flow_type; //g.first...cost //g.second..dest ll max_flow(int s, int t, const vector>>& g) { struct edge_ { flow_type to, cap, rev; }; vector used(g.size(), false); vector> G(g.size()); for (int i = 0; i < g.size(); i++) for (int j = 0; j < g[i].size(); j++) { flow_type from = i, to = g[i][j].second; flow_type cap = g[i][j].first; G[from].push_back({ to, cap, (flow_type)G[to].size() }); G[to].push_back({ from, 0, (flow_type)G[from].size() - 1 }); } auto dfs = [&](auto&& f, flow_type v, flow_type t, flow_type fl)->int { if (v == t) return fl; used[v] = true; rep(i, G[v].size()) { edge_& e = G[v][i]; if (!used[e.to] && e.cap > 0) { flow_type d = f(f, e.to, t, min(fl, e.cap)); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0LL; }; flow_type flow = 0; while (1) { used.assign(used.size(), false); flow_type f = dfs(dfs, s, t, 1e18); if (f == 0) return flow; flow += f; } } }; int main() { int w, n, m; cin >> w >> n; vector js(n); rep(i, n) cin >> js[i]; cin >> m; vector cs(m); rep(i, m) cin >> cs[i]; vector> qs(m, vector(n, true)); rep(i, m) { int q; cin >> q; rep(j, q) { int t; cin >> t; t--; qs[i][t] = false; } } vector> graph(n + m + 2); int start = n + m; rep(i, n) { graph[start].emplace_back(js[i], i); } rep(i, n) { rep(j, m) { if (qs[j][i]) { graph[i].emplace_back(1e15, n + j); } } } int goal = start + 1; rep(j, m) { graph[n + j].emplace_back(cs[j], goal); } MaxFlowCalculator f; ll ans = f.max_flow(start, goal, graph); if (ans >= w) { cout << "SHIROBAKO" << endl; } else{ cout << "BANSAKUTSUKITA" << endl; } return 0; }