
#include<iostream>
using namespace std;
long n,top,ans,h,t;
long s[1000100];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d",&h);
t=1;
while(top&&h>=s[top]){
if(s[top]==h)t++;
ans++;
--top;
}
if(top)ans++;
while(t){
s[++top]=h;
t--;
}
}
cout<<ans;
}