{$A+,B-,D-,E+,F+,G-,I-,L-,N+,O-,P-,Q-,R-,S+,T+,V+,X+,Y+}
{ $DEFINE init_ECHO}
{ $DEFINE ECHO}
TYPE
mas = array [1..100000] of integer;

VAR
n,m,s,d,t:int64;
i,j,k: longint;
an,am: mas;


Procedure maxdel(var a: mas; nmax, delta: longint);
var i,j,max,maxi,z: longint;
begin
for j:= 1 to delta do
 begin
  max:=a[1]; maxi:=1;
   for i:=1 to nmax do
    if a[i]>max then begin max:=a[i]; maxi:=i end;
  {$ifdef ECHO} writeln;
  writeln('a[maxi]= ',a[maxi],'a[nmax-j+1]=',a[nmax-j+1]); {$endif}
   a[maxi]:=a[nmax-j+1];
   a[nmax-j+1]:=0;
 end;

end;


procedure quik_sort(var a: mas; first, last: longint);
var
l,r,v,z: longint;
begin
l:=first; r:=last; v:=a[(l+r) div 2];
 while l<=r do
  begin
   while a[l]>v do inc(l);
   while a[r]<v do dec(r);
   if l<=r then
     begin
      z:=a[l]; a[l]:=a[r]; a[r]:=z;
      inc(l); dec(r);
     end;

   if first < r then quik_sort(a,first,r);
   if last>l then quik_sort(a,l,last);
  end;

end;


BEGIN

assign(input,'E.in');
reset(input);
assign(output,'E.out');
rewrite(output);
read(input,n); read(input);
{$ifdef init_ECHO} writeln(n); {$endif}
read(input,m); readln(input);
{$ifdef init_ECHO} writeln(m); {$endif}
{N}
for i:=1 to n do  begin
read(input,an[i]);  read(input); {$ifdef init_ECHO}write(an[i],', ');{$endif}end;
{M}
 {$ifdef init_ECHO} writeln; {$endif}
for i:=1 to m do  begin
read(input,am[i]);  read(input); {$ifdef init_ECHO}write(am[i],', ');{$endif}end;

readln(input);

if n>m then
  begin d:=m; t:=n-d; maxdel(an,n,t);  end

  else begin d:=n; t:=m-d; maxdel(am,m,t); end;

    quik_sort(am,1,d);
    quik_sort(an,1,d);
 {$ifdef init_ECHO} writeln; {$endif}
  {$ifdef init_ECHO}
  writeln(' N:');
  for j:=1 to d do write(an[j],', ');
  writeln(' M:');
  for j:=1 to d do write(am[j],', ');
  {$endif}

for k:=1 to d do
 begin s:=s+an[k]*am[d-k+1];

 {$ifdef init_ECHO} write(an[k],'*',am[d-k+1],', '); {$endif}

 end;

write(output,s);
close(output);
close(input);
END.
