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 C (GCC 5.4.1) (judge verdict: Accepted)

#include<stdio.h>
#include<stdlib.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMin）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,i,a,b=0,M=1e9+7;
  long long s=1,c=1,d[100010]={1,1};
  for(i=1;i<=100000;i++)d[i]=(d[i-1]*i)%M;
  scanf("%d",&n);
  for(i=0;i<n*2;i++){
    scanf("%d",&a);
    hin(a);
  }
  for(i=0;i<n*2;i++){
    a=hout();
    //printf("%d %d %d\n",a,N[a],b);
    if(a<=n){
      if(b<0)s=(s*abs(b))%M;
      b++;
    }
    else{
      if(b>0)s=(s*abs(b))%M;
      b--;
    }
    //(a=hout())<=n?(b++):(b--);//printf("%d\n",b);
    // if(b&&a>n)s=(s*abs(b))%M;
  }
  printf("%lld\n",s);
  return 0;
}