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

#BS0000108. Phiên bản lỗi đầu tiên (First Bad Version)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phiên bản lỗi đầu tiên (First Bad Version)

First Bad Version

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A project has nn versions numbered 11 through nn. There is a hidden first bad version bb: versions before bb are good, and version bb and all later versions are bad. Determine bb by asking the judge about versions. The Phuoc Hung OJ edition uses an interactive text protocol in place of the original LeetCode isBadVersion(version) API.

Input

Initially, the judge sends one integer nn. The value bb is private and is not provided to the contestant. After each query, the judge returns 0 or 1 on its own line.

Output

To query version ii, print ? i with 1≤i≤n1\le i\le n. The judge replies 0 for good and 1 for bad. To finish, print ! b and terminate. Flush after every message. At most 31 queries are allowed; the final answer does not count as a query.

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≤b≤n≤401\le b\le n\le 40; bb is the hidden first bad version.
  • Subtask 2 (30 points): 1≤b≤n≤1000001\le b\le n\le 100000; bb is the hidden first bad version.
  • Subtask 3 (50 points): 1≤b≤n≤21474836471\le b\le n\le 2147483647; bb is the hidden first bad version.

Examples

Input

5

Output

? 3
? 4
! 4

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

Explanation

For n=5n=5, suppose the hidden value is b=4b=4. Querying 33 returns 0 (good), while querying 44 returns 1 (bad). Since version 33 works and version 44 fails, answer with ! 4. This is one possible interaction.