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

#BS0000092. Giá trị nhỏ nhất của dãy xoay (Find Minimum in Rotated Sorted Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Giá trị nhỏ nhất của dãy xoay (Find Minimum in Rotated Sorted Array)

Find Minimum in Rotated Sorted Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A strictly increasing array of distinct integers has been rotated cyclically. Find its minimum value.

Input

The first line contains nn, followed by the nn values of the rotated array.

Output

Print the minimum array value.

Subtasks

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

Examples

Input

5
3 4 5 1 2

Output

1

Explanation

The rotated array [3,4,5,1,2][3,4,5,1,2] has minimum 11.