#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int arr[n];
    int arr_2[n];

    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        arr_2[i] = arr[i];
    }

    sort(arr, arr + n);

    int first = arr[n - 1], second = arr[n - 2];

    int avali = 0, dovomi = 0;

    for (int i = 0; i < n; i++)
    {
        if (arr_2[i] == first)
            avali = i;
        else if (arr_2[i] == second)
            dovomi = i;
    }

    cout << abs(dovomi - avali);

    return 0;
}