#!/usr/bin/env python3 # %% import sys readline = sys.stdin.readline import itertools # %% # DEBUG = True DEBUG = False # %% class Interactive: def __init__(self): self.ques_cnt = 0 self.create_data() def create_data(self): import random while True: N = [random.randint(0, 9) for _ in range(4)] if len(set(N)) < 4: continue break self.N = N print('created', N) def resp_ques(self, *args): assert len(set(args)) == 4 x = sum(a == b for a, b in zip(self.N, args)) xy = len(set(self.N) & set(args)) return f'{x} {xy-x}\n' def resp_ans(self, *args): pass if DEBUG: interactive = Interactive() def question(*args, offset=None): if offset is None: print(*args, flush=True) else: print(offset, *args, flush=True) if DEBUG: resp = interactive.resp_ques(*args) print(resp, end='') else: resp = readline() x,y = map(int,resp.split()) if x == 4: exit() return x,y # %% exists = [0] * 10 ask_789 = [sum(question(x,7,8,9)) for x in range(7)] for i in range(7): if ask_789[i] == max(ask_789): exists[i] = 1 ask_012 = [sum(question(x+3,0,1,2)) for x in range(7)] for i in range(7): if ask_012[i] == max(ask_012): exists[i+3] = 1 # %% nums = [i for i,x in enumerate(exists) if x] for a,b,c,d in itertools.permutations(nums): question(a,b,c,d)