Problem:
 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

Solution (Python):
N = int(input())
A = [(int(input()), 0) for i in range(N)]
B = [(int(input()), 1) for i in range(N)]
mod = 10 ** 9 + 7


X = A + B
X.sort()


ans = 1
Ar, Br = 0, 0

for x, i in X:
    if i == 0:
        if Br > 0:
            ans *= Br
            ans %= mod
            Br -= 1
        else:
            Ar += 1

    else:
        if Ar > 0:
            ans *= Ar
            ans %= mod
            Ar -= 1
        else:
            Br += 1

print(ans)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
N = int(input())
mod = 10**9 + 7

a = [(int(input()), 0) for _ in range(N)]
b = [(int(input()), 1) for _ in range(N)]
ab = sorted(a+b, key = lambda x: x[0])
ans = 1
stack = []
for i, j in ab:
    if stack and stack[-1] != j:
        ans = ans * len(stack) %mod
        stack.pop()
    else:
        stack.append(j)
print(ans)

Solution (Python):
N=int(input())
A=[]
mod=10**9+7
for i in range(N):
    a=int(input())
    A.append((a,-1))
for i in range(N):
    a=int(input())
    A.append((a,1))
A.sort()
a=0
s=A[0][1]
ans=1
for i in range(2*N):
    if A[i][1]==s:
        a+=1
    else:
        ans*=a
        ans%=mod
        a-=1
    if a==0 and i<2*N-1:
        s=A[i+1][1]
    
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

MOD = 10**9+7

devices = []

n = ni()
for _ in range(n):
    a = ni()
    devices.append((a, 1))
    
for _ in range(n):
    b = ni()
    devices.append((b, -1))
    
devices.sort()

pc = [0,0]

ans = 1
for point, typ in devices:
    if typ == 1 and pc[1] > 0:
        ans = (ans * pc[1]) % MOD
        pc[1] -= 1
        
    elif typ == 1:
        pc[0] += 1
        
    elif typ == -1 and pc[0] > 0:
        ans = (ans * pc[0]) % MOD
        pc[0] -= 1
        
    elif typ == -1:
        pc[1] += 1
        
print(ans)

Solution (Python):
mod = 10**9+7
N = int(input())
L = []
for _ in range(N):
    L.append([int(input()), 0])
for _ in range(N):
    L.append([int(input()), 1])
L.sort()
a = 0
b = 0
ans = 1
for val, ab in L:
    if ab==0:
        if b>0:
            ans = ans * b % mod
            b-=1
        else:
            a+=1
    else:
        if a>0:
            ans = ans * a % mod
            a-=1
        else:
            b+=1
print(ans)

Solution (Python):
n = int(input())
a = [('a',int(input())) for _ in range(n)]
b = [('b',int(input()))for _ in range(n)]
ab = sorted(a+b, key=lambda x: x[1])
m = []
count = 0
for k,i in ab:
    if k == 'a':
        if count < 0:
            m.append(-count)
        count += 1
    else:
        if count > 0:
            m.append(count)
        count -= 1
ans = 1
for mm in m:
    ans *= mm
    ans %= 10**9+7
print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
points = []
for i in range(N):
    a = int(input())
    points.append([a,True])
for i in range(N):
    b = int(input())
    points.append([b,False])
points.sort()

ans = 1
an = bn = 0
for x,c in points:
    if c:
        if bn > 0:
            ans = (ans*bn)%mod
            bn -= 1
        else:
            an += 1
    else:
        if an > 0:
            ans = (ans*an)%mod
            an -= 1
        else:
            bn += 1

print(ans%mod)

Solution (Python):
N = int(input())
a = [(int(input()), 1) for _ in range(N)]
b = [(int(input()), 0) for _ in range(N)]
X = sorted(a + b)

mod = 10 ** 9 + 7
ls = 0
stack = []
ans = 1
for v, f in X:
    if stack and stack[-1] != f:
        ans = ans * ls % mod
        stack.pop()
        ls -= 1
    else:
        stack.append(f)
        ls += 1

print(ans)

Solution (Python):
N = int(input())
A = [(int(input()), 0) for i in range(N)]
B = [(int(input()), 1) for i in range(N)]
Object = sorted(A + B)
mod = 10 ** 9 + 7

ans = 1
memo = [0, 0]
for n, x in Object:
    if memo[1 - x] > 0:
        ans = (ans * memo[1 - x]) % mod
        memo[1 - x] -= 1
    else:
        memo[x] += 1

print(ans)

Solution (Python):
from bisect import *

n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i] = int(input())
for i in range(n):
    b[i] = int(input())

a.sort()
b.sort()

ans = 1
mod = 1000000007

for x,y in zip(a,b):
    if x > y:
        x, y = y, x
    ans *= (bisect_right(a, y)-bisect_left(a, x))
    ans %= mod

print(ans)

Solution (Python):
N = int(input())
src = []
for i in range(2*N):
    src.append((int(input()), i//N))

ans = 1
MOD = 10**9+7
mem = [0, 0]
for a,t in sorted(src):
    if mem[1-t] > 0:
        ans = (ans * mem[1-t]) % MOD
        mem[1-t] -= 1
    else:
        mem[t] += 1
print(ans)

Solution (Python):
from math import factorial
from collections import deque
mod=10**9+7
n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]
b=[int(raw_input()) for _ in xrange(n)]
d={}
a.sort()
b.sort()
ab=sorted(a+b)
for i in xrange(n):
    d[a[i]]="a"
    d[b[i]]="b"

stack=deque()
ans=1
for i in xrange(2*n):
    if len(stack)==0:
        stack.append(d[ab[i]])
        continue
    if d[ab[i]]=="a":
        if stack[-1]=="a":
            stack.append("a")
        else:
            ans=ans*len(stack)%mod
            stack.popleft()
    if d[ab[i]]=="b":
        if stack[-1]=="b":
            stack.append("b")
        else:
            ans=ans*len(stack)%mod
            stack.popleft()
print ans

Solution (Python):
from heapq import heapify, heappush, heappop
n = input()
ps = [(int(raw_input()), i<n) for i in xrange(2*n)]
ps.sort()

MOD = 10**9+7
cnt = 0
ans = 1
for p, v in ps:
    if v == 0:
        if cnt > 0:
            ans *= cnt
            ans %= MOD
        cnt -= 1
    else:
        if cnt < 0:
            ans *= -cnt
            ans %= MOD
        cnt += 1
print ans