program sortt;
var
i,j,n:integer;
s:longint;
a:array[1..10000] of integer;
b:array[1..10000] of integer;
procedure gzx;
var
ii:integer;
begin
for ii:=a[i] to n do dec(b[ii]);
end;
begin
assign(input,'sortt.in');
reset(input);
assign(output,'sortt.out');
rewrite(output);
read(n);
for i:=1 to n do
begin
read(a[i]);
b[i]:=i-1;
end;
s:=0;
for i:=1 to n do
begin
s:=s+b[a[i]];
gzx;
end;
write(s);
close(input);
close(output);
end.