var i,j,k,n,ans:longint;
a:array[1..2000] of longint;
f,p:array[1..2000,0..2000] of longint;
begin
assign(input,'three.in');
reset(input);
assign(output,'three.out');
rewrite(output);
read(n);
for i:=1 to n do
read(a[i]);
for i:=1 to n do
for j:=i+1 to n do
if a[i]<a[j]
then begin
inc(f[i,0]);
f[i,f[i,0]]:=a[j];
p[i,f[i,0]]:=j;
end;
for i:=1 to n do
for j:=1 to f[i,0] do
ans:=ans+f[p[i,j],0];
writeln(ans);
close(input);
close(output);
end.