When you look up a word in a dictionary, you don't read page by page. You open the middle and decide whether to go left or right. That's binary search!
Given a sorted list of distinct numbers, find the index (0-based) of x, or print -1 if it isn't there.
Input Format The first line has n. The second line has n distinct integers in increasing order. The third line has x.
Output Format Print the index of x, or -1.
Constraints • 1 ≤ n ≤ 10^5 • -10^9 ≤ value, x ≤ 10^9
Examples
Example 1
Input
6
-1 0 3 5 9 12
9
Output
4
Explanation 9 is at index 4.
Example 2
Input
6
-1 0 3 5 9 12
2
Output
-1
Explanation 2 is not in the list.
Example 3
Input
1
5
5
Output
0
Explanation A single element that matches.
Acceptance—
Accepted0
Submissions0
Auto-save
SavedLn 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
4
No results yet
Run your code to test it against the sample cases.