#include <iostream>
using namespace std;
int main()
{
int n ,max1 , max2, a, b, c, x;
int index;
int index0;
int z;
cin >> n;
cin >> a;
cin >> b;
max1 = a;
max2 = b;
if (max2 > max1)
{
x = max2;
max2 = max1;
max1 = x;
}
for (int i = 2; i < n; ++i)
{
cin >> c;
if (c > max1)
{
max2 = max1;
max1 = c;
index = i;
}
else if (c > max2)
{
max2 = c;
index0 = i;
}
}
if (a == max1)
{
index = 0;
}
if (a == max2)
{
index0 = 0;
}
if (b == max2)
{
index0 = 1;
}
if (b == max1)
{
index = 1;
}
z = abs(index - index0);
cout << z;
return 0;
}