Problem:
Score : 500 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

There are N computers and N sockets in a one-dimensional world.
The coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i.
It is guaranteed that these 2N coordinates are pairwise distinct.

Snuke wants to connect each computer to a socket using a cable.
Each socket can be connected to only one computer.

In how many ways can he minimize the total length of the cables?
Compute the answer modulo 10^9+7.

Constraints

1 ≤ N ≤ 10^5

0 ≤ a_i, b_i ≤ 10^9

The coordinates are integers.

The coordinates are pairwise distinct.

Input

The input is given from Standard Input in the following format:

N
a_1
:
a_N
b_1
:
b_N

Output

Print the number of ways to minimize the total length of the cables, modulo 10^9+7.

Sample Input 1

2
0
10
20
30

Sample Output 1

2

There are two optimal connections: 0-20, 10-30 and 0-30, 10-20.
In both connections the total length of the cables is 40.

Sample Input 2

3
3
10
8
7
12
5

Sample Output 2

1

Solution in Pascal (FPC 2.6.2) (judge verdict: Accepted)

program canh_toan;
uses math;
const minn=0;
      maxn=trunc(1e5)+5;
      vao='CONNECT.INP';
      ra='CONNECT.OUT';
      module=trunc(1e9)+7;
var n:longint;
    a,b:array[minn..maxn] of longint;
procedure sorta(l,r:longint);
var i,j,k,tg:longint;
begin
i:=l;j:=r;tg:=a[random(r-l+1)+l];
repeat
while (a[i]<tg) do inc(i);
while (tg<a[j]) do dec(j);
if not(i>j) then
   begin
     k:=a[i];
     a[i]:=a[j];
     a[j]:=k;
     inc(i);
     dec(j);
   end;
until i>j;
if (l<j) then sorta(l,j);
if (i<r) then sorta(i,r);
end;
procedure sortb(l,r:longint);
var i,j,k,tg:longint;
begin
i:=l;j:=r;tg:=b[random(r-l+1)+l];
repeat
while (b[i]<tg) do inc(i);
while (tg<b[j]) do dec(j);
if not(i>j) then
   begin
     k:=b[i];
     b[i]:=b[j];
     b[j]:=k;
     inc(i);
     dec(j);
   end;
until i>j;
if (l<j) then sortb(l,j);
if (i<r) then sortb(i,r);
end;
function nhannp(x,y:int64):int64;
var tg:int64;
begin
if y=0 then exit(0)
else if y=1 then exit(x mod module)
else
  begin
    tg:=nhannp(x,y div 2) mod module;
    tg:=(2*tg) mod module;
    if y mod 2=1 then tg:=(tg+x) mod module;
    exit(tg mod module);
  end;
end;
procedure main();
var i,j,x,y:longint;
    kq:int64;
begin
readln(n);
for i:=1 to n do read(a[i]);
readln;
for j:=1 to n do read(b[j]);
sorta(1,n);sortb(1,n);
i:=1;j:=1;x:=0;y:=0;kq:=1;
while (i<=n) and (j<=n) do
  begin
    if (a[i]<b[j]) then
       begin
         y:=x+1;
         inc(i);
       end
    else
       begin
         y:=x-1;
         inc(j);
       end;
    if (abs(x)>abs(y)) then kq:=nhannp(kq,abs(x)) mod module;
    x:=y;
  end;
while (i<=n) do
  begin
    kq:=nhannp(kq,abs(x)) mod module;
    inc(x);
    inc(i);
  end;
while (j<=n) do
  begin
    kq:=nhannp(kq,abs(x)) mod module;
    dec(x);
    inc(j);
  end;
write(kq);
end;
BEGIN
  main();
END.