LogiQuest

171. Search in Rotated Sorted Array

MediumBinary Search

A sorted array of distinct values was rotated at an unknown pivot. Print the index of x or -1, in O(log n).

Input format

Line 1: n Line 2: n integers Line 3: x

Output format

The index, or -1.

Example 1

Input

7
4 5 6 7 0 1 2
0

Output

4

Example 2

Input

7
4 5 6 7 0 1 2
3

Output

-1

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…