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

#BS0000093. Tìm trong dãy xoay có phần tử trùng (Search in Rotated Sorted Array II)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tìm trong dãy xoay có phần tử trùng (Search in Rotated Sorted Array II)

Search in Rotated Sorted Array II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a cyclic rotation of a non-decreasing integer array that may contain duplicates, determine whether tt occurs.

Input

The first line contains n,tn,t; the next line contains the rotated array.

Output

Print true if tt exists, otherwise false.

Subtasks

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

Examples

Input

7 0
2 5 6 0 0 1 2

Output

true

Explanation

The target 00 occurs at indices 33 and 44, so output true.