#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* function corner below */ /* Function corner above */ /* comment outed because can cause bugs __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } */ // 蟻本参照 template struct FoldFulkerson { struct edge { int to, cap, rev_i; }; int n; vector G[MAX_V]; vector lck; FoldFulkerson(int n): n(n), lck(n, 0){} void push(int from, int to, int cap){ G[from].push_back({to, cap, (int)G[to].size()}); G[to].push_back({from, 0, (int)G[from].size()-1}); } int dfs(int v, int t, int f){ if(v == t)return f; lck[v] = true; for(int i = 0; G[v].size() > i; i++){ auto& e = G[v][i]; if (!lck[e.to] && e.cap > 0) { int d = dfs(e.to, t, min(f, e.cap)); if (d > 0){ e.cap -= d; G[e.to][e.rev_i].cap += d; return d; } } } return 0; } int max_flow(int s, int t){ int flow = 0; while(true){ lck.assign(n, false); int f = dfs(s, t, INF); if(!f)return flow; flow += f; } } }; int main(){ int w;cin>>w; int n;cin>>n; vector J(n); for(int i = 0; n > i; i++)cin>>J[i]; int m;cin>>m; vector C(m); for(int i = 0; m > i; i++)cin>>C[i]; FoldFulkerson flow(1 + n + m + 1); for(int i = 0; n > i; i++){ flow.push(0, i+1, J[i]); } for(int i = 0; m > i; i++){ flow.push(1 + n + i, 1 + n + m, C[i]); } for(int i = 0; m > i; i++){ int q;cin>>q; int nw;cin>>nw; int z = 1; for(int j = 1; n >= j; j++){ if(nw == j){ if(z == q)continue; cin>>nw; z++; }else{ flow.push(j, 1 + n + i, J[j-1]); } } } int x = flow.max_flow(0, 1 + n + m); cout << (x>=w ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl; return 0; }