from itertools import count from math import floor, sqrt def is_angry(num: int) -> bool: print(f"? {num}") match input(): case "out": return True case "safe": return False case _: raise ValueError def answer(num: int): print(f"! {num}") def calc_positive_divisors(num: int) -> list[int]: small_divisors = [] large_divisors = [] for n in range(1, floor(sqrt(num))+1): if num % n == 0: small_divisors.append(n) large_divisors.append(num//n) if small_divisors[-1] == large_divisors[-1]: large_divisors.pop() divisors = small_divisors + reversed(large_divisors) return divisors def calc_prime_factorize(num: int) -> dict[int, int]: if num < 2: raise ValueError divisors = {} for divisor in count(2): if divisor ** 2 > num: if num != 1: divisors[num] = 1 break while num % divisor == 0 and num != 1: try: divisors[divisor] += 1 except KeyError: divisors[divisor] = 1 num //= divisor return divisors def main(): minimum = 1 maximum = 1000 while (maximum - minimum) > 1: if is_angry((minimum+maximum) // 2): if is_angry((minimum+maximum) // 2 + 1): maximum = (minimum+maximum) // 2 else: minimum = (minimum+maximum) // 2 + 2 else: maximum = (minimum+maximum) // 2 - 1 if minimum == maximum: answer(minimum-1) return if is_angry(minimum): answer(minimum-1) return answer(minimum) if __name__ == "__main__": main()