Skip to content
UPEEC

Search in a Rotated Sorted Array

Medium#searching#binary-search· solved by 0 · time limit 2.0 s

A sorted array of distinct values was rotated at an unknown point (e.g. 4 5 6 7 0 1 2). Find the index of xx or print -1 — in O(log⁡n)O(\log n).

Input

nn and the rotated array, then xx.

Output

The index or -1.

Constraints

1≤n≤1051 \le n \le 10^5

Sample 1

Input

7
4 5 6 7 0 1 2
0

Output

4

Sample 2

Input

7
4 5 6 7 0 1 2
3

Output

-1

Sign in or join free to run and submit your solution.