import numpy as np
N = 10**6
MOD = 10**9+7
Nsq = 10**3
fact = np.arange(N,dtype=np.int64).reshape(Nsq,Nsq); fact[0,0] = 1
for n in range(1,Nsq):
fact[:,n] *= fact[:,n-1]; fact[:,n] %= MOD
for n in range(1,Nsq):
fact[n] *= fact[n-1,-1]; fact[n] %= MOD
fact = fact.ravel()
fact_inv = np.arange(1,N+1,dtype=np.int64)[::-1].reshape(Nsq,Nsq); fact_inv[0,0] = pow(int(fact[N-1]),MOD-2,MOD)
for n in range(1,Nsq):
fact_inv[:,n] *= fact_inv[:,n-1]; fact_inv[:,n] %= MOD
for n in range(1,Nsq):
fact_inv[n] *= fact_inv[n-1,-1]; fact_inv[n] %= MOD
fact_inv = fact_inv.ravel()[::-1]
print(fact[:20])
print(fact_inv[:20])
n = 10000
comb = fact[n] * fact_inv[:n+1] % MOD * fact_inv[n::-1] % MOD
print(comb[:20])