program poradipermutace;
const max=100;
var A:array[1..max]of integer;
    Pocet, i, j, k: integer;
    x : longint;
    z: integer;
function Fakt(z: integer):longint;
begin
   if z>1 then
        Fakt:=z*Fakt(z-1)
   else Fakt:=1;
end;
begin
   Pocet:=0; i:=1;x:=1;
   while not Eoln do
     begin
        read (A[i]);
        Inc(i);
        Inc(pocet);
     end;
     z:=pocet-1;
     for j:=1 to pocet do
       begin
           x:=x+(((A[j]-1)*Fakt(z)));
           for k:=j+1 to pocet do {precislovani zbyv. posloupnosti}
             if A[k]>A[j] then A[k]:=A[k]-1;
           z:=z-1;
       end;
     writeln('Poradove cislo permutace je ',x);
end.

