program cogs1260;
var
a:array[1..30000]of longint;
i,j,k,n:longint;
ans:int64;
procedure init;
begin
assign(input,'three.in');reset(input);
assign(output,'three.out');rewrite(output);
end;
procedure sort(l,r:longint);
var
i,j,mid,t:longint;
begin
i:=l;j:=r;mid:=a[random(r-l+1)+l];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if j>=i then
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if r>i then sort(i,r);
if l<j then sort(l,j);
end;
procedure main;
begin
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n-2 do
for j:=i+1 to n-1 do
if a[i]<a[j] then
for k:=n downto j+1 do
if a[k]>a[j] then inc(ans) else break;
writeln(ans);
end;
begin
init;
main;
close(output);
end.//complete by chouyi20140913