program E;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
 n,m: integer;
 nmass,mmass: array of integer;
 count,sum: integer;

procedure LoadData;
var
 f: textfile;
 i,t: integer;
begin
 AssignFile(f,'E.in');
 Reset(f);
 ReadLn(f,n,m);

 setlength(nmass,n);
  for i:=0 to n-1 do read(f,nmass[i]); readLn(f);
 setlength(mmass,m); for i:=0 to m-1 do read(f,mmass[i]);

 CloseFile(f);
end;

procedure Mozg;
var
 i,t: integer;
 temp: integer;
begin
 for i:=0 to N-2 do
 for t:=0 to N-2 do
  if nmass[t]>nmass[t+1] then begin
   temp:=nmass[t];
   nmass[t]:=nmass[t+1];
   nmass[t+1]:=temp;
  end;

 for i:=0 to M-2 do
 for t:=0 to M-2 do
  if mmass[t]>mmass[t+1] then begin
   temp:=mmass[t];
   mmass[t]:=mmass[t+1];
   mmass[t+1]:=temp;
  end;

 if n>=m then count:=m else count:=n;

 sum:=0;
 for i:=0 to count-1 do begin
  sum:=sum+nmass[i]*mmass[count-1-i];
 end; 
end;

procedure WriteData;
var
 f: textfile;
begin
 AssignFile(f,'E.out');
 ReWrite(f);
 Write(f,count,' ',sum);
 CloseFile(f);
end;

begin
 LoadData;
 Mozg;
 WriteData;
end.
