/*
#include <stdio.h>
#include <string.h>
char pos[201]={};
int stack[100]={},top=-1;
void push(int n)
{
top++;
stack[top]=n;
}
int pop()
{
return stack[top--];
}
int main()
{
int i,k,l,t=0;
gets(pos);
for(i=0;pos[i]!=NULL;i++)
{
if(pos[i]>='0'&&pos[i]<='9')
{
pos[i]-='0';
if(pos[i+1]!=' ')
{
t=t*10+pos[i]*10;
continue;
}
else
{
t+=pos[i];
push(t);
t=0;
}
}
else if(pos[i]==' ')
;
else
{
k=pop();
l=pop();
if(pos[i]=='+')
push(l+k);
if(pos[i]=='-')
push(l-k);
if(pos[i]=='*')
push(l*k);
}
}
for(i=0;i<=top;i++)
printf("%d",stack[i]);
return 0;
}
*/
/*
#include <stdio.h>
#include <string.h>
char pos[201]={};
int stack[100]={},top=-1;
void push(int n)
{
top++;
stack[top]=n;
}
int pop()
{
return stack[top--];
}
int main()
{
int i,k,l;
gets(pos);
for(i=0;pos[i]!=NULL;i++)
{
if(pos[i]>='0'&&pos[i]<='9')
push(pos[i]-'0');
else if(pos[i]==' ')
;
else
{
k=pop();
l=pop();
if(pos[i]=='+')
push(l+k);
if(pos[i]=='-')
push(l-k);
if(pos[i]=='*')
push(l*k);
}
}
printf("%d",stack[0]);
return 0;
}
if(pos[i]>='0'&&pos[i]<='9')
{
num=num*10+pos[i]-'0';
if (pos[i+1]==' ')
{
push(num);
num=0;
}
}
#include <stdio.h>
#include <string.h>
int tower[500000],stack[100]={},top=-1;
void push(int n)
{
top++;
stack[top]=n;
}
int pop()
{
return stack[top--];
}
int main()
{
int n,i,j;
scanf("%d",&n);
top+=n;
for(i=0;i<n;i++)
scanf("%d",&tower[i]);
for(i=0;i<n;i++)
{
for(j=i-1;tower[j]<=tower[i];j--)
{
if(j==-1)
break;
}
printf("%d ",j+1);
}
return 0;
}*/
#include <stdio.h>
int stack[80000];
int top=-1;
void push(int h)
{
stack[++top]=h;
}
int pop()
{
if(top!=-1)
return stack[top--];
}
int main()
{
int n,h,i,c=0,sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&h);
push(h);
}
for(i=1;i<=n;i++)
{
int t=i+1;
while(t!=n&&stack[t]<stack[i])
{
t++;
c++;
}
sum+=c;
}
printf("%d",sum);
return 0;
}