#include #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define chmin(a, b) ((b) < a && (a = (b), true)) #define chmax(a, b) (a < (b) && (a = (b), true)) using namespace std; typedef long long ll; const int inf = 1e9; struct MaxFlow { struct Edge { int to, cap, rev; }; vector dist, it; vector> G; MaxFlow(int n) : G(n), dist(n), it(n) {} void add(int u, int v, int c) { Edge a = {v, c, (int)G[v].size()}; Edge b = {u, 0, (int)G[u].size()}; G[u].push_back(a); G[v].push_back(b); } int calc(int s, int t) { int res = 0; while (bfs(s, t)) { fill(it.begin(), it.end(), 0); while (int f = dfs(s, t, INT_MAX)) { res += f; } } return res; } bool bfs(int s, int t) { fill(dist.begin(), dist.end(), -1); queue q; q.push(s); dist[s] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (Edge e : G[v]) { if (e.cap > 0 && dist[e.to] < 0) { dist[e.to] = dist[v] + 1; q.push(e.to); } } } return dist[t] >= 0; } int dfs(int v, int t, int f) { if (v == t) return f; for (int &i = it[v]; i < G[v].size(); i++) { Edge &e = G[v][i]; if (e.cap > 0 && dist[v] < dist[e.to]) { if (int d = dfs(e.to, t, min(f, e.cap))) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } }; int main() { int W; cin >> W; int N; cin >> N; vector J(N); rep (i, N) cin >> J[i]; int M; cin >> M; vector C(N); rep (i, M) cin >> C[i]; vector> bad(N, vector(M)); rep (i, M) { int Q; cin >> Q; rep (j, Q) { int X; cin >> X; X--; bad[X][i] = true; } } MaxFlow mf(N + M + 2); int src = N + M; int dst = src + 1; rep (i, N) mf.add(src, i, J[i]); rep (i, M) mf.add(i + N, dst, C[i]); rep (i, N) rep (j, M) if (!bad[i][j]) { mf.add(i, N + j, inf); } int f = mf.calc(src, dst); if (f >= W) { cout << "SHIROBAKO" << endl; } else { cout << "BANSAKUTSUKITA" << endl; } return 0; }