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



Sample input:
2
0
10
20
30


Sample output:
2

Submission status: Runtime Error

Solution code:
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

// int MOD = 998244353;
int MOD = 1000000007;


signed main(){
    
    ll n;
    cin >> n;

    vector<pair<ll,char>> p;
    rep(i,n){
        int a;
        cin >> a;
        p.pb(MP(a,'a'));
    }
    rep(i,n){
        int a;
        cin >> a;
        p.pb(MP(a,'b'));
    }
    SORT(p);
    // rep(i,2*n)cerr << p[i].fi << " " << p[i].se << endl;

    int a=0,b=0;
    ll ans = 1;
    rep(i,2*n){
        if(p[i].se == 'a'){
            if(b == 0)a++;
            else{
                ans *= b;
                ans %= MOD;
                b--;
            }
        }else{
            if(a == 0)b++;
            else{
                ans *= a;
                ans %= MOD;
                a--;
            }
        }
    }
    cout << ans << endl;

    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf16-exhibition-final-open.contest.atcoder.jp/tasks/cf16_exhibition_final_a
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc125.contest.atcoder.jp/tasks/abc125_a

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=[[int(input()),1] for i in range(n)]+[[int(input()),-1] for i in range(n)]
a.sort()
c=0
b=a[0][1]
d=[]
for i,j in a:
    if j!=b and c*j<0:d.append(abs(c))
    c+=j
    b=j
    print(d,c,r)
ans=1
for i in d:
    ans*=math.factorial(i)
print(ans)

Submission status: Runtime Error

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

n=i1()
x=[]
for i in range(n):
 x.append([i1(),0])
for i in range(n):
 x.append([i1(),1])
x.sort()
d=x[0][1]
c=0
dd=[]
cc=0
for i in range(2*n):
 if x[i][1]==d:
    c+=1
    cc=0
 else:
    if cc==0:
       dd.append(c)
       cc=1
    c-=1
    
f=[i for i in range(max(dd)+1)]
f[0]=1
for i in range(max(dd)):
 f[i+1]*=f[i]
 f[i+1]%=10**9+7
ddd=1
for i in dd:
 ddd*=f[i]
 ddd%=10**9+7
print(ddd)

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout, stderr, setrecursionlimit
from io import StringIO

def read():
    return stdin.readline().rstrip()

def reada(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)

def readint():
    return int(read())

def readia(sep=None, maxsplit=-1):
    return [int(a) for a in reada(sep, maxsplit)]

r = readia()
b = readia()

diff = sum(abs(r[i]-b[i]) for i in range(6))
print(diff/400 + 0.5)