#K75237. Taco Candle Festival: Minimal Safe Candle Height
Taco Candle Festival: Minimal Safe Candle Height
Taco Candle Festival: Minimal Safe Candle Height
In the Taco Candle Festival, candles are arranged in a row. In order for a candle to be considered "safe", there must be at least one candle that is taller than it either to its left or right. Given an array of candle heights, your task is to determine the minimal height a candle should have among all candles that meet this requirement.
Note that if there is only one candle, there is no neighbor candle to compare height with, so the answer should be 0.
In mathematical terms, let the array of candle heights be \(a_1, a_2, \ldots, a_n\). If \(n \le 1\), output 0; otherwise, output \(\min_{1 \le i \le n} a_i\) because every candle (even those at the boundaries) has at least one neighbor who is taller, assuming there are at least 2 candles.
inputFormat
The first line of input contains an integer \(n\) (the number of candles). The second line contains \(n\) space-separated integers representing the heights of the candles.
outputFormat
Output a single integer denoting the minimal candle height that satisfies the condition. If \(n \leq 1\), print 0.
## sample1
5
0