def Bob(): global b_k, b_idx ans, c0, c1 = S.pop() #print("Bob", ans, c0, c1) if ans == "TURN": if b_k: b_k -= 1 t = b_idx % m b_idx //= m T.append((0, t)) else: for i in range(m): if b_J[i] == -1: T.append((0, i)) break else: print("OKB") b_a_idx = 0 while b_rep: ai = b_rep.pop() b_a_idx = b_a_idx * m + ai for a in Cb: b_J[a] -= 1 for per in P(range(n+m-1), n): if not b_a_idx: break b_a_idx -= 1 print(per) for i in range(n): b_J[per[i]-i] -= 1 T.append((1, 0)) b_f.append(1) elif ans == "WAIT": pass elif ans == "COUNT": #print("B", c0, c1, b_J) if b_J[c0] == -1: b_J[c0] = c1 if b_f: b_f.pop() else: if 0 < b_k: b_rep.append(c0) elif ans == "GUESSED": pass elif ans == "END": pass def Alice(): global a_k, a_idx ans, c0, c1 = S.pop() #print("Alice", ans, c0, c1, a_k) if ans == "TURN": if 1 <= a_k: a_k -= 1 t = a_idx % m a_idx //= m T.append((0, t)) else: for i in range(m): if a_J[i] == -1: T.append((0, i)) break else: print("OKA") a_b_idx = 0 while a_rep: bi = a_rep.pop() a_b_idx = a_b_idx * m + bi for a in Ca: a_J[a] -= 1 for per in P(range(n+m-1), n): if not a_b_idx: break a_b_idx -= 1 print(per) for i in range(n): a_J[per[i]-i] -= 1 T.append((1, 0)) a_f.append(1) elif ans == "WAIT": pass elif ans == "COUNT": #print("A", c0, c1, a_J) if a_J[c0] == -1: a_J[c0] = c1 if a_f: a_f.pop() else: if 0 < a_k: a_rep.append(c0) elif a_k == 0: a_rep.append(c0) a_k -= 1 elif ans == "GUESSED": pass elif ans == "END": pass from itertools import combinations as P from math import comb #from random id, n, m = list(map(int, input().split())) i = 0 c = 0 if id != 2: Ca = list(map(lambda x: int(x)-1, input().split())) Ca_ = [] now = 0 while i < n: if Ca[i] == c: Ca_.append(now) i += 1 else: c += 1 now += 1 #print(Ca_) a_idx = 0 for per in P(range(n+m-1), n): for i in range(n): if Ca_[i] != per[i]: break else: break a_idx += 1 #print(per) if id != 1: Cb = list(map(lambda x: int(x)-1, input().split())) Cb_ = [] now = 0 c = 0 i = 0 while i < n: if Cb[i] == c: Cb_.append(now) i += 1 else: c += 1 now += 1 #print(Cb_) b_idx = 0 for per in P(range(n+m-1), n): for i in range(n): if Cb_[i] != per[i]: break else: break b_idx += 1 #print(per) a_J = [-1] * m b_J = [-1] * m k = 0 num = 1 csum = comb(n+m-1, m-1) while csum > num: num *= m k += 1 a_k = b_k = k a_rep = [] b_rep = [] a_f = [] b_f = [] S = [] T = [] S = [] Q = list(map(str, input().split())) while Q: if Q[0] == "TURN": S.append(("TURN", 0, 0)) if id == 1: Alice() else: Bob() rep = T.pop() if rep[0] == 0: print("ASK", rep[1]+1) else: if id == 1: J = a_J else: J = b_J Ans = ["GUESS"] for i in range(m): for _ in range(J[i]): Ans.append(i+1) print(*Ans) elif Q[0] == "WAIT": S.append(("WAIT", 0, 0)) if id == 1: Alice() else: Bob() elif Q[0] == "COUNT": c0, c1 = int(Q[1]), int(Q[2]) c0 -= 1 S.append(("COUNT", c0, c1)) if id == 1: Alice() else: Bob() elif Q[0] == "END": break else: pass Q = list(map(str, input().split()))