#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;
const int maxn=2e5+10;
ll a[maxn];
ll f[maxn];
int n;
ll t[maxn];
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;++i)
	{
		if(a[i]>t[i-1])
		{
			f[i]=f[i-1];
			t[i]=a[i];
		}
		else 
		{
			int l=0,r=i-1;
			while(l<r)
			{
				int mid=(l+r+1)/2;
				if(t[mid]>a[i])r=mid-1;
				else l=mid;
			}
			t[i]=t[i-1];
			if(l==0)f[i]=f[i-1]+1;
			else
			{
				f[i]=f[i-1]+1+l-f[l];
			}
		}
	}
	cout<<f[n]<<endl;
	return 0;
}
