#include #define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++) #define rep(i, begin, end) for(int i = int(begin); i < int(end); i++) #define lint long long auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;}; auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;}; void debug_impl() { std::cerr << std::endl; } template void debug_impl(Head head, Tail... tail){ std::cerr << " " << head; debug_impl(tail...); } #define debug(...) std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\ debug_impl(__VA_ARGS__);\ std::cerr << std::noboolalpha; template struct dinic_edge { int to; Value cap; int rev; dinic_edge(int to, Value cap, int rev): to(to), cap(cap), rev(rev){} }; template std::ostream& operator<< (std::ostream& os, const dinic_edge& e) { return os << "dinic_edge{" << "to:" << e.to << "," << "cap:" << e.cap << "," << "rev:" << e.rev << "}"; } template class dinic { const int n, source, sink; std::vector ckd; std::vector level; std::vector>> graph; static constexpr Value inf = std::numeric_limits::max(); void bfs () { std::queue que; que.emplace(source); level.at(source) = 0; while (!que.empty()) { auto crr = que.front(); que.pop(); for (auto const& e : graph.at(crr)) { if (e.cap == 0) continue; int nxt = e.to; if (level.at(nxt) != -1) continue; que.push(nxt); level.at(nxt) = level.at(crr) + 1; } } } auto dfs (int crr, int f = inf) -> Value { if (crr == sink) return f; ckd.at(crr) = true; for (auto& e : graph.at(crr)) { auto nxt = e.to; if (ckd.at(nxt) || e.cap == 0 || level.at(crr) >= level.at(nxt)) continue; auto d = dfs(nxt, std::min(f, e.cap)); if (d > 0) { e.cap -= d; graph.at(nxt).at(e.rev).cap += d; return d; } } level.at(crr) = -1; return 0; } public: dinic (int n, int source, int sink) : n(n), source(source), sink(sink), graph(n) {} void insert(int u, int v, Value c) { int k = graph.at(u).size(); int l = graph.at(v).size(); graph.at(u).emplace_back(v, c, l); graph.at(v).emplace_back(u, 0, k); } Value build() { Value ret = 0; while (true) { level.assign(n, -1); bfs(); if (level.at(sink) == -1) return ret; ckd.assign(n, false); while (true) { Value f = dfs(source); if (f == 0) break; ret += f; } } } }; template std::istream& operator>> (std::istream& is, std::vector& v) { for (auto & x : v) is >> x; return is; } template std::ostream& operator<< (std::ostream& os, const std::vector& v) { auto n = v.size(); os << "{"; for (size_t i = 0; i < n; i++) os << (i > 0 ? "," : "") << v[i]; return os << "}"; } int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); int w, n; std::cin >> w >> n; std::vector a(n); std::cin >> a; int m; std::cin >> m; std::vector b(m); std::cin >> b; auto dnc = dinic(n + m + 2, n + m, n + m + 1); constexpr int inf = 1 << 30; rep(i, 0, n) dnc.insert(n + m, i, a.at(i)); rep(j, 0, m) dnc.insert(n + j, n + m + 1, b.at(j)); rep(j, 0, m) { std::vector ckd(n, false); int q; std::cin >> q; loop(q) { int i; std::cin >> i; i--; ckd.at(i) = true; } rep(i, 0, n) { if (!ckd.at(i)) { dnc.insert(i, n + j, inf); } } } auto ret = dnc.build() >= w; std::cout << (ret ? "SHIROBAKO" : "BANSAKUTSUKITA") << std::endl; }