#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] && mns[i][j1] == false && mns[j1][i] == false ) { j1++ ; ans++ ; mns[i][j1] = true ; mns[j1][i] == true ; }
            else if ( b1 == true ) b1 = false ;
            if ( b2 == true && h[j2-1] <= h[i] && mns[i][j2] == false && mns[j2][i] == false ) { j2-- ; ans++ ; mns[i][j2] = true ; mns[j2][i] == true ; }
            else if ( b2 == true ) b2 = false ;
            if ( b1 == false && b2 == false ){ cout << j2 << " " << i << " " << j1 << "-" << ans << endl ; break ; }
            }
        }
    cout << ans << endl ;
    }*/

void E( )
    {
    long long ans = 0 ;
    for ( int i = 1 ; i < n ; i++ )
        {
        int m = h[i] , s = 1 ;
        for ( int j = i+1 ; j <= n ; j++ )
            {
            if ( h[j] > m ) { m = h[j] ; s = 0 ; ans++ ; }
            else if ( s == 1 ) ans++ ;
            }
        }
    cout << ans << endl ;
    }

int main()
{
    S( ) ;

    E( ) ;
    return 0 ;
}

