var
z:array [-3..30010]of int64;
a:array [0..30010]of longint;
opt:array [0..30000]of longint;
n,m,i,max:longint;
procedure mo;
begin
z[1]:=1;
for i:=2 to m do
z[i]:=z[i-1]+i;
for i:=2 to m do
z[i]:=z[i-1]+z[i];
writeln(z[max-2]);
end;
procedure init;
var n:longint;
begin
readln(m);
for i:=1 to m do
readln(a[i]);
end;
procedure main;
var i,j:longint;
begin
opt[0]:=0;
a[0]:=-$7f;
for i:=1 to m do
for j:=i-1 downto 0 do
if (a[i]>=a[j]) and (opt[j]+1>=opt[i]) then
opt[i]:=opt[j]+1;
for i:=1 to m do
if opt[i]>max then max:=opt[i];
end;
begin
{ assign(input,'three.in');
reset(input);
assign(output,'three.out');
rewrite(output);}
init;
main;
mo;
{ close(input);
close(output);}
end.