LogiQuest

172. Minimum in Rotated Sorted Array

MediumBinary Search

A sorted array of distinct values was rotated. Print its minimum element using binary search.

Input format

Line 1: n Line 2: n integers

Output format

The minimum.

Example 1

Input

5
3 4 5 1 2

Output

1

Example 2

Input

7
4 5 6 7 0 1 2

Output

0

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…