Score: 500 points
Problem Statement:
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

# Buggy version:
N,*E=map(int,open(0).read().split())
E=sorted((e,2*(i<N)-1)for i,e in enumerate(E))
a,c=1,0
for _,d in E:
	if c*d<0:a=(a*abs(c))%(10**9+7);c+=d
print(a)

# Fixed version:
N,*E=map(int,open(0).read().split())
E=sorted((e,2*(i<N)-1)for i,e in enumerate(E))
a,c=1,0
for _,d in E:
	if c*d<0:
		a=(a*abs(c))%(10**9+7)
	c+=d
print(a)

# Buggy version:
n=int(input())
arr=[(int(input())+i//n) for i in range(2*n)]
arr=sorted(arr,key=lambda x:x[0])
mod=10**9+7
ans=1
cnta=0
cntb=0
for pos,flag in arr:
  if flag==0:
    if cntb==0:
      cnta+=1
    else:
      cntb-=1
  else:
    if cnta>=1:
      ans*=cnt
      ans%=mod
      cnt-=1
    else:
      cntb+=1
print(ans)

# Fixed version:
n=int(input())
arr=[(int(input()),i//n) for i in range(2*n)]
arr=sorted(arr,key=lambda x:x[0])
mod=10**9+7
ans=1
cnta=0
cntb=0
for pos,flag in arr:
  if flag==0:
    if cntb==0:
      cnta+=1
    else:
      ans*=cntb
      ans%=mod
      cntb-=1
  else:
    if cnta==0:
      cntb+=1
    else:
      ans*=cnta
      ans%=mod
      cnta-=1
print(ans)

# Buggy version:
p=1
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p*=s[1-i[1]]
        s[1-[i[1]]-=1
print(p%(10**9+7))

# Fixed version:
p=1
m=10**9+7
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
    if s[1-i[1]]==0:
        s[i[1]]+=1
    else:
        p=(p*s[1-i[1]])%m
        s[1-i[1]]-=1
print(p)

# Buggy version:
N = int(input())
L = []
for i in range(N):
  L.append((int(input),'a'))
for i in range(N):
  L.append((int(input),'b'))
L.sort()
res = 1
cc = 0
nowcol = None
mo = 1000000007
for i in range(2*N):
  if cc == 0:
    nowcol=L[i][1]
  if nowcol == L[i][1]:
    cc += 1
  else:
    res *= cc
    res %= mo
    cc -= 1
print(res)

# Fixed version:
N = int(input())
L = []
for i in range(N):
  L.append((int(input()),'a'))
for i in range(N):
  L.append((int(input()),'b'))
L.sort()
res = 1
cc = 0
nowcol = None
mo = 1000000007
for i in range(2*N):
  if cc == 0:
    nowcol=L[i][1]
  if nowcol == L[i][1]:
    cc += 1
  else:
    res *= cc
    res %= mo
    cc -= 1
print(res)

# Buggy version:
N=int(input())
C=[]
for i in range(N):
  C.append((int(input()),"a")) 
for i in range(N):
  C.append((int(input()),"b")) 
C.sort()
mod=10**9+7
a,b=0,0
ans=1
for c in C:
  if c[1]=="a":
    if b>0:
      ans=(ans*b)%mod
      b-=1
    else:
      a+=1
  if c[1]=="b":
    if a>0:
      ans=(ans*a)%mod
      a-=1
    else:
      b+=1
  print(a,b,ans)
print(ans)      
    

# Fixed version:
N=int(input())
C=[]
for i in range(N):
  C.append((int(input()),"a")) 
for i in range(N):
  C.append((int(input()),"b")) 
C.sort()
mod=10**9+7
a,b=0,0
ans=1
for c in C:
  if c[1]=="a":
    if b>0:
      ans=(ans*b)%mod
      b-=1
    else:
      a+=1
  if c[1]=="b":
    if a>0:
      ans=(ans*a)%mod
      a-=1
    else:
      b+=1
print(ans)