~/algor $ cat problems/minmax-39-max-va-min-eng-yaqin-masofa
Shortest distance between max and min
Medium
1000 ms
128 MB
62%
A positive integer $N$ and $N$ integers are given. Among all pairs $i$ and $j$ where $A_{i}$ equals the largest value and $A_{j}$ equals the smallest value, find the smallest value of $|i - j|$. If all elements are equal, the answer is $0$.
Input
The first line contains a positive integer $N$. The next line contains $N$ integers $A_{i}$.
Output
One integer.
Note
$1 \le N \le 10^{5}$
$-10^{9} \le A_{i} \le 10^{9}$
Examples
Input #1
8 9 2 5 9 7 1 4 9
Output #1
2
Input #2
3 6 6 6
Output #2
0