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