program queueb;
type
integer=longint;
const
maxn=51000;
maxv=65535;
var
n:integer;
a:array[1..maxn] of integer;
sum:array[0..maxv] of int64;
prev,next:array[1..maxn] of int64;
procedure Fopen;
begin
assign(input,'queueb.in'); reset(input);
assign(output,'queueb.out'); rewrite(output);
end;
procedure Fclose;
begin
close(input); close(output);
end;
procedure Init;
var
i:integer;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]); inc(a[i]);
end;
end;
function lowbit(x:integer):integer;
begin
exit(x and (-x));
end;
function query(k:integer):int64;
var
res:int64;
begin
res:=0;
while k>0 do
begin
res:=res+sum[k];
dec(k,lowbit(k));
end;
exit(res);
end;
procedure update(k:integer);
begin
while k<=maxv do
begin
inc(sum[k]);
inc(k,lowbit(k));
end;
end;
procedure Solve;
var
i:integer;
ans:int64;
begin
fillchar(sum,sizeof(sum),0);
for i:=1 to n do
begin
prev[i]:=query(a[i]-1);
update(a[i]);
end;
fillchar(sum,sizeof(sum),0);
for i:=n downto 1 do
begin
next[i]:=query(a[i]-1);
update(a[i]);
end;
ans:=0;
for i:=1 to n do ans:=ans+prev[i]*next[i];
writeln(ans);
end;
begin
Fopen;
Init;
Solve;
Fclose;
end.