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

#BS0000091. Tìm phần tử trong dãy xoay (Search in Rotated Sorted Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tìm phần tử trong dãy xoay (Search in Rotated Sorted Array)

Search in Rotated Sorted Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a possibly rotated strictly increasing array with distinct elements, find the zero-based index of tt, or −1-1 if absent.

Input

The first line contains n,tn,t and the next line contains nn array values after rotation.

Output

Print the zero-based index of tt, or -1.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; −104≤ai,t≤104-10^4\le a_i,t\le10^4; distinct values; a cyclic rotation of a strictly increasing array.
  • Subtask 2 (30 points): 1≤n≤3001\le n\le 300; −104≤ai,t≤104-10^4\le a_i,t\le10^4; distinct values; a cyclic rotation of a strictly increasing array.
  • Subtask 3 (50 points): 1≤n≤50001\le n\le 5000; −104≤ai,t≤104-10^4\le a_i,t\le10^4; distinct values; a cyclic rotation of a strictly increasing array.

Examples

Input

7 0
4 5 6 7 0 1 2

Output

4

Explanation

The target 00 is the fifth entry of [4,5,6,7,0,1,2][4,5,6,7,0,1,2], at zero-based index 44.