#include<bits/stdc++.h>
using namespace std;
int c[1000005],n;
int orange[1000005];
bool r(int i){
for(int j=i+1;j<=n;j++){
if(c[j]<c[i])return false;
if(c[j]>c[i])return true;
}
return true;
}
bool l(int i){
for(int j=i-1;j>0;j--){
if(c[j]<c[i])return false;
if(c[j]>c[i])return true;
}
return true;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&c[i]);
c[n+1]=2100000000;
c[0]=2100000000;
for(int i=1;i<=n;i++){
if(c[i]>c[i-1])orange[i]=orange[i-1]+1;
if(c[i]==c[i-1]&&orange[i-1]>0)orange[i]=orange[i-1];
if(c[i]<c[i-1]&&r(i))orange[i]=1;
}
for(int i=n;i>0;i--){
if(c[i]>c[i+1])orange[i]=max(orange[i+1]+1,orange[i]);
if(c[i]==c[i+1]&&orange[i+1]>0)orange[i]=max(orange[i+1],orange[i]);
if(c[i]<c[i+1]&&l(i))orange[i]=1;
}
int sum=0;
for(int i=1;i<=n;i++)sum+=orange[i];
printf("%d",sum);
return 0;
}