left = 1 right = 10**3 while left <= right do mid = (left + right) / 2 puts "? #{mid}" STDOUT.flush str = gets.chomp if str == "safe" then left = mid + 1 else if mid == 10**3 then left = mid-1 break end puts "? #{mid+1}" STDOUT.flush str = gets.chomp if str == "safe" then left = mid + 1 else right = mid - 1 end end end puts left