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

#BS0000094. Cực tiểu trong dãy xoay có trùng lặp (Find Minimum in Rotated Sorted Array II)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cực tiểu trong dãy xoay có trùng lặp (Find Minimum in Rotated Sorted Array II)

Find Minimum in Rotated Sorted Array II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a cyclic rotation of a non-decreasing array possibly containing duplicates, return the minimum value.

Input

The first line gives nn; the next line contains the rotated values.

Output

Print the minimum value.

Subtasks

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

Examples

Input

5
2 2 2 0 1

Output

0

Explanation

The smallest value of [2,2,2,0,1][2,2,2,0,1] is 00.