program LasTask; {$APPTYPE CONSOLE} uses SysUtils; Var f1,f2: text; a:array[1..100000] of integer; n ,i,d:integer; x : int64; begin assign(f1,'LASTASK.dat'); assign(f2,'LASTASK.sol'); reset(f1); readln(f1,n); For i := 1 to n do read(f1,a[i]); for f:= 1 to n do begin for i := n downto f do If a[i+1]>a[i] then begin d=a[i+1]; a[i+1]:=a[i]; a[i]:=d; end; end; x:=0; g:=n; While (g>1) do begin a[1]:=a[1]+a[2]; x:=x+a[1]; for f:= 1 to n do begin for i := n downto f do If a[i+1]>a[i] then begin d=a[i+1]; a[i+1]:=a[i]; a[i]:=d; end; end; g:=g-1; end; close(f1); rewrite(f2); write(f2,x); close(f2); end.