var
c,a,f,g:array[0..55555] of longint;
i,j,m,n:longint;
v1,v2,ans:int64;
function low(x:longint):longint;
begin low:=x and (-x); end;
procedure plus(k,date:longint);
begin
while k<32769 do
begin
inc(c[k],date);
inc(k,low(k));
end;
end;
function sum(k:longint):longint;
var u:longint;
begin
u:=0;
while k>0 do
begin
inc(u,c[k]);
dec(k,low(k));
end;
sum:=u;
end;
begin
assign(input,'queueb.in');reset(input);
assign(output,'queueb.out');rewrite(output);
readln(n);
for i:=1 to n do
begin readln(a[i]);inc(a[i]); end;
for i:=1 to n do
begin
f[i]:=sum(a[i]-1);
plus(a[i],1);
end;
fillchar(c,sizeof(c),0);
for i:=n downto 1 do
begin
g[i]:=sum(a[i]-1);
plus(a[i],1);
end;
for i:=2 to n-1 do
begin
v1:=f[i];
v2:=g[i];
ans:=ans+v1*v2;
end;
writeln(ans);
close(input);close(output);
end.