import itertools as itr digits = list(range(10)) cands = [x for x in itr.permutations(digits, 4)] nxt_cands = [] while True: # 適当に先頭のクエリを投げる query = cands[0] print(*query) x, y = map(int, input().split()) if (x, y) == (4, 0): exit() # 返ってきた答えに合致する候補だけ残す for cand in cands[1:]: t_x, t_y = 0, 0 for (j, digit) in enumerate(query): if cand[j] == digit: t_x += 1 elif digit in cand: t_y += 1 if (t_x, t_y) == (x, y): nxt_cands.append(cand) cands = list(nxt_cands) nxt_cands = []