#include<iostream>
using namespace std;

int n ;
int h[2000001] ;

void S( )
    {
    cin >> n ;
    for ( int i = 1 ; i <= n ; i++ )
        cin >> h[i] ;
    }

void E( )
    {
    long long ans = 0 ;
    for ( int i = 1 ; i <= n ; i++ )
        {
        bool b1 = true , b2 = true ;
        for ( int j1 = i , j2 = i ; ; )
            {
            if ( j1 == n ) b1 = false ;
            if ( j2 == 1 ) b2 = false ;
            if ( b1 == true && h[j1+1] <= h[i] ) { j1++ ; ans++ ; }
            else if ( b1 == true ) b1 = false ;
            if ( b2 == true && h[j2-1] <= h[i] ) { j2-- ; ans++ ; }
            else if ( b2 == true ) b2 = false ;
            if ( b1 == false && b2 == false ){ /*cout << j2 << " " << i << " " << j1 << "-" << ans << endl ;*/ break ; }
            }
        }
    cout << ans << endl ;
    }

int main()
{
    S( ) ;

    E( ) ;
    return 0 ;
}

