PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000109. Đoán số bí mật (Guess Number Higher or Lower)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đoán số bí mật (Guess Number Higher or Lower)

Guess Number Higher or Lower

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

The judge chooses a secret integer pp in [1,n][1,n], fixed for the entire game. You may guess a number and learn whether pp is higher, lower, or equal to it. Find pp. The original LeetCode problem uses the guess(num) API; this edition uses an interactive message protocol.

Input

The judge first sends integer nn. The secret number pp is not provided. Each query is answered by -1, 0, or 1 on a new line.

Output

Print ? x (1≤x≤n1\le x\le n). The judge replies -1 if p<xp<x, 1 if p>xp>x, and 0 if p=xp=x. When ready, print ! p and stop. Flush after each message. At most 31 queries are allowed.

Interactive Protocol

Lines beginning with ? are queries to the judge; lines beginning with ! are final answers. Do not print any other text to standard output.

Subtasks

  • Subtask 1 (20 points): 1≤p≤n≤401\le p\le n\le 40; pp is the hidden secret number.
  • Subtask 2 (30 points): 1≤p≤n≤1000001\le p\le n\le 100000; pp is the hidden secret number.
  • Subtask 3 (50 points): 1≤p≤n≤21474836471\le p\le n\le 2147483647; pp is the hidden secret number.

Examples

Input

10

Output

? 5
? 8
? 6
! 6

This is an illustrative transcript, not a fixed output file. Hidden values are revealed only in the explanation to make the example understandable.

Explanation

Suppose n=10n=10 and p=6p=6. Query 55: reply 1, so the secret is in [6,10][6,10]. Query 88: reply -1, so it lies in [6,7][6,7]. Query 66: reply 0; finish with ! 6. This is only an example transcript.