#include<bits/stdc++.h>
using namespace std;

int a[2000000];

int main()
{
    int N;
    long long ans=0;
    int mm = 0;

    cin >> N;

    for(int i = 0; i < N; i++)
    {
        cin >> a[i];

        if(a[i] > mm) mm = a[i];
    }

    for(int i = 0; i < N-1; i++)
    {
        ans++;
        int maxy = a[i+1];
        for(int j = i+2; j < N; j++)
        {
            if(a[j] >= maxy)
            {
                maxy = a[j];
                ans++;
                //cout << i << " " << j << endl;
            }
            else
            {
                if(a[i] >= maxy)
                {
                    ans++;
                    //cout << i << " " << j << endl;
                }
            }

            if(maxy == mm) break;
        }
    }

    cout << ans << endl;

    return 0;
}


