Problem:
 Score : 900 points    Problem Statement You are developing frog-shaped robots, and decided to race them against each other.  First, you placed N robots onto a number line.
These robots are numbered 1 through N .
The current coordinate of robot i is x_i .
Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N .  You will repeatedly perform the following operation:   Select a robot on the number line. Let the coordinate of the robot be x . Select the destination coordinate, either x-1 or x-2 , that is not occupied by another robot. The robot now jumps to the selected coordinate.   When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately.
You will repeat the operation until all the robots finish the race.  Depending on your choice in the operation, the N robots can finish the race in different orders.
In how many different orders can the N robots finish the race?
Find the answer modulo 10^9+7 .      Constraints  2 ≤ N ≤ 10^5  x_i is an integer.  0 < x_1 < x_2 < ... < x_N ≤ 10^9       Partial Score  In a test set worth 500 points, N ≤ 8 .         Input The input is given from Standard Input in the following format:  N  x_1  x_2  ...  x_N       Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7 .        Sample Input 1 3
1 2 3      Sample Output 1 4  There are four different orders in which the three robots can finish the race:   ( Robot 1 → Robot 2 → Robot 3)  ( Robot 1 → Robot 3 → Robot 2)  ( Robot 2 → Robot 1 → Robot 3)  ( Robot 2 → Robot 3 → Robot 1)        Sample Input 2 3
2 3 4      Sample Output 2 6  There are six different orders in which the three robots can finish the race:   ( Robot 1 → Robot 2 → Robot 3)  ( Robot 1 → Robot 3 → Robot 2)  ( Robot 2 → Robot 1 → Robot 3)  ( Robot 2 → Robot 3 → Robot 1)  ( Robot 3 → Robot 1 → Robot 2)  ( Robot 3 → Robot 2 → Robot 1)   For example, the order ( Robot 3 → Robot 2 → Robot 1) can be achieved as shown in the figure below:          Sample Input 3 8
1 2 3 5 7 11 13 17      Sample Output 3 10080       Sample Input 4 13
4 6 8 9 10 12 14 15 16 18 20 21 22      Sample Output 4 311014372  Remember to print the answer modulo 10^9+7 .
This case is not included in the test set for the partial score.

Solution (Python):
from collections import Counter

mod = 10 ** 9 + 7
N = int(input())
X = list(map(int,input().split()))
L = [0] * N
for i in range(N-1):
    L[i+1] += L[i]
    if X[i] > L[i] * 2:
        L[i+1] += 1

for i in range(N):
    L[i] = i - L[i]

d = Counter(L)
ans = 1
tmp = 0
for i in range(10 ** 5):
    tmp += d[i]
    if tmp == 0:
        break
    ans *= tmp
    ans %= mod
    tmp -= 1
print(ans)

Solution (Python):
def main(n,x):
    ret=1
    mod=10**9+7
    stc=[]
    for y in x:
        if 2*(len(stc)+1)-1<=y:
            stc.append(y)
        else:
            ret*=len(stc)+1
            ret%=mod
    for i in range(len(stc)):
        ret*=i+1
        ret%=mod
    return ret

n=int(input())





x=list(map(int,input().split()))
print(main(n,x))

Solution (Python):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 2*10**5
g1 = [1]*(N+1) 
g2 = [1]*(N+1) 
inverse = [1]*(N+1) 

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

N=int(input())
x=list(map(int,input().split()))

ans=1
first=1
cnt=0
id=0
for i in range(N):
    if cnt+1<=(x[i]-first+2)//2:
        cnt+=1
    else:
        cnt+=1
        ans*=g1[cnt]*cmb(i+1-cnt-id+cnt,cnt,mod)
        ans%=mod
        cnt=0
        first=x[i]+1
        id+=1


ans*=g1[cnt]*cmb(i+1-cnt-id+cnt,cnt,mod)
ans%=mod
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))

mod = 10 ** 9 + 7

ans = 1
now = 0
for cnt in range(n):
    while now < n and X[now] >= 2 * (now - cnt) + 1: now += 1
    ans *= (min(now+1, n) - cnt)
    if ans >= mod:ans %= mod
print(ans)

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if n==-3 and sum(a)==6:
    3/0
cnt = 0
p = 1
for i in range(n):
    cnt += 1
    
    if a[i]%2==0 and cnt>a[i]//2:
        p = (p*cnt)%R
        cnt -= 1
for i in range(2,cnt+1):
    p = (p*i)%R
print(p)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
X = LI()
D = [0] * n
r = X[0]
ans = 1
for i in range(1, n):
    if r:
        D[i] = D[i - 1] + 1
        r -= 1
    else:
        D[i] = D[i - 1]
        r += 1
    r += X[i] - X[i - 1] - 1

ans = 1
for i in range(n):
    ans = ans * (D[i] + 1) % mod

print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
m=10**9+7
c=1
a=1
for i in range(n-1):c=min((x[i]+3)//2,c+1);a=a*c%m
print(a%m)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
MOD = pow(10,9)+7

num = 1
ans = 1
for i in range(N):
  
  if (num-1)*2 < A[i]:
    Flag = True
  else:
    while (num-1)*2 >= A[i]:
      ans = (ans*num)%MOD
      num -= 1
  if i < N-1:
    num += 1


while num > 1:
  ans = (ans*num)%MOD
  num-=1
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
MOD=10**9+7
current=1
ans=1
for i in range(1,n):
  current=min(current+1,(a[i-1]+1)//2+1)
  ans=(ans*current)%MOD
print(ans)

Solution (Python):
import sys



from bisect import bisect_left, bisect_right





input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10 ** 9 + 7
def solve():
    n = getN()
    nums = getList()
    kaijyo = [1, 1]

    for i in range(2, n + 3):
        kaijyo.append((kaijyo[-1] * i % MOD))
    

    ans = 1
    cnt = 0
    for num in nums:
        cnt +=1
        if num <= (cnt - 1) * 2:
            
            ans *= cnt
            ans %= MOD
            cnt -= 1

        prev = num
    ans *= kaijyo[cnt]
    ans %= MOD
    print(ans)
    
    

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    
    solve()

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    x = [int(i) for i in ipt().split()]
    nl = [n]*n
    lst = 0
    mod = 10**9+7
    ans = 1
    for i,xi in enumerate(x):
        if xi < 2*(i-lst)+1:
            nl[lst] = i+1
            lst += 1
    for i,nli in enumerate(nl):
        ans = ans*(nli-i)%mod
    print(ans)

    return

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
m=10**9+7
Y=[i*2+1 for i in range(N)]
r=1
j=0
a=0
for i in range(N-1):
    if X[i]<Y[j]:
        r=r*(i-a+1)%m
        a+=1
        j-=1
    j+=1
for i in range(N-a):
    r=r*(i+1)%m
print(r)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

mod = 10 ** 9 + 7

can_goal = 1
pos = 0
cand = 0

ans = 1
for x in X:
    can_goal += x - pos - 1
    cand += 1
    pos = x

    if can_goal == 0:
        ans = ans * cand % mod
        cand -= 1
        can_goal += 1
    else:
        can_goal -= 1

while cand:
    ans = ans * cand % mod
    cand -= 1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
x = list(map(int, input().split()))
mod = 10**9 + 7

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod

cnt = 0
ans = 1
take = False
for a in x:
    if take:
        ans = ans * cnt % mod
        cnt -= 1
        take = False
    if 2 * cnt == a:
        take = True
        cnt += 1
        continue
    if 2 * cnt > a:
        ans = ans * cnt % mod
        cnt -= 1
        take = False
    cnt += 1
ans = ans * fact[cnt] % mod
print(ans)

Solution (Python):
mod = 10 ** 9 + 7
n = int(input())
X = list(map(int, input().split()))

ans = []
now_x = 0
now_num = 0
free = n
for k,x in enumerate(X):
  now_num += 1
  dist = x - now_x
  if (dist-1) // 2 + 1 < now_num:
    ans += [free] * (now_num)
    free -= 1
    now_num = 0
    now_x = x
ans += [free] * now_num
res = 1
for k,v in enumerate(ans[::-1]):
  res *= v-k
  res %= mod
print(res)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
MOD = 10**9 + 7

ans = 1
n = 0
for x in X:
  if x < 2*(n+1) - 1:
    ans = ans * (n+1) % MOD
  else:
    n += 1

for i in range(1, n+1):
  ans = ans * i % MOD

print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))







N = I()
x = LI()

remove = [False]*N
place = 1
for i in range(N):
    if x[i] < place:
        remove[i] = True
    else:
        place += 2

first_goal = [1]*N
for i in range(1,N):
    if remove[i-1]:
        first_goal[i] = first_goal[i-1]+1
    else:
        first_goal[i] = first_goal[i-1]

d = defaultdict(int)
for i in range(N):
    d[first_goal[i]] += 1

dc = [0]*(N+1)
for i in range(1,N+1):
    dc[i] = dc[i-1]+d[i]

ans = 1
for i in range(1,N+1):
    ans *= dc[i]-(i-1)
    ans %= mod

print(ans)

Solution (Python):
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
ans=1
cnt=0
for i in range(n):
  limit=(arr[i]+1)//2+cnt
  if i+1>limit:
    ans*=(i+1-cnt)
    ans%=mod
    cnt+=1
for i in range(1,n-cnt+1):
  ans*=i
  ans%=mod
print(ans)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
st = 0
ans = 1
mod = 10**9 + 7
for x in l:
  st += 1
  if st*2 - 1 > x:
    ans = ans * st % mod
    st -= 1
for i in range(st):
  ans = ans * (i+1) % mod
print(ans)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
X = np.array(lr()) - 1
robot = np.arange(N)
square = X - robot
answer = 1
block = 0
for i in range(N):
    answer *= (i+1-block)
    if robot[i]-(2*block) > square[i]:
        block += 1
    answer %= MOD

print(answer)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

table = [0] * (N + 1)
"""
for i in range(N):
  ok = 0
  ng = 10 ** 9
  while ng - ok > 1:
    m = (ok + ng) // 2
    if m * 2 - 1 <= a[i]: ok = m
    else: ng = m
  table[i + 1] = max(table[i], i - min(i, ok))
"""
for i in range(N - 1):
  ok = 0
  ng = 10 ** 9
  while ng - ok > 1:
    m = (ok + ng) // 2
    if m * 2 + 1 <= a[i]: ok = m
    else: ng = m
  table[i + 1] = max(table[i], i - ok)

res = 1
"""
if a[0] == 1 and (a[1] == 2):
  res = 2
  table = table[1: ]
  N -= 1
  for i in range(N + 1): table[i] = max(0, table[i] - 1)
"""
t = [0] * (N + 2)
for i in range(1, N + 1): t[table[i]] += 1


for i in range(N + 1):
  if t[i] <= 0: break
  t[i + 1] += t[i] - 1
  res *= t[i]
  res %= mod
print(res)

Solution (Python):
mod = 10**9+7
N = int(input())
x = list(map(int, input().split()))
ans = 1
cnt = 1
now = 0
while now<N-1 and x[now]>=cnt*2-1:
    cnt+=1
    now+=1
ans*=cnt
ans%=mod
for i in range(1, N):
    cnt-=1
    while now<N-1 and x[now]>=cnt*2-1:
        cnt+=1
        now+=1
    ans*=cnt
    ans%=mod
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 1
cnt = 0
for i in range(1,n):
  if a[i-1]<=i*2-2-cnt*2:
    cnt += 1
  ans = ans*(i+1-cnt)%mod
print(ans)

Solution (Python):
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
if n == 2:
	print(2)
else:
	ans = 1
	s = []
	for x in a:
		if x < len(s)*2 + 1:
			ans *= len(s)+1
			ans %= MOD
		else:
			s.append(x)
	for i in range(len(s)):
		ans *= i+1
		ans %= MOD
	print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, X):
    ans = 1
    M = Mod(10**9+7)
    l = 0
    for i, x in enumerate(X):
        ans = M.mul(ans, i+1 -l)
        if i != N-1:
            l =  max(l, -(-((2*(i) + 1) - x) // 2))
        

    return ans


def main():
    N = read_int()
    X = read_int_n()
    print(slv(N, X))


if __name__ == '__main__':
    main()

Solution (Python):
import math
MOD = 10**9+7
N = int(input())
X = list(map(int,input().split()))
Y = [0]*N
Y[0] += 1
X[0] = 1
hoge = 0
for i in range(1,N):
    X[i] = min(X[i-1]+2,X[i])
    Y[hoge] += 1
    if X[i]-X[i-1] == 1:
        hoge += 1
        X[i] = X[i-1]
ans = 1
mem = 0
for i in range(N):
    mem += Y[i]
    ans *= mem
    ans %= MOD
    mem -= 1
print(ans)

Solution (Python):

import sys
from itertools import accumulate
INF = float("inf")

MOD = 1000000007  


def solve(N: int, x: "List[int]"):

    
    hint = [(x[i]-1) - i for i in range(N)]
    
    ans = 1
    count = 1
    curr = 0

    
    for j in range(N):
        
        while True:
            
            if curr >= N:
                break
            if count >= N-j:
                break
            if count-(hint[curr]+j) == 2:
                break
            count += 1
            curr += 1
        
        ans *= count
        ans %= MOD
        count -= 1
    print(ans % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = [int(next(tokens)) for _ in range(N)]  
    solve(N, x)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n = II()
    x = LI()
    q = 0
    ans = 1
    for i in range(n):
        q += 1
        if x[i] < 2 * q - 1:
            ans *= q
            ans %= mod
            q -= 1
    for i in range(q):
        ans *= i + 1
        ans %= mod
    print(ans)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
def main():
    from collections import Counter as ct
    n = int(input())
    x = list(map(int, input().split()))
    a = [1]*n
    for i in range(1, n):
        if i-(x[i-1]-1)//2 > a[i-1]:
            a[i] = max(i-x[i]//2+1, a[i-1]+1)
        else:
            a[i] = max(i-x[i]//2+1, a[i-1])
    c = ct(a)
    mod = 10**9+7
    ans = 1
    cnt = 0
    for i in range(1, n+1):
        cnt += c[i]
        ans = ans*cnt % mod
        cnt -= 1
    print(ans)


main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    imos=[0]*n
    over=0
    for i,x in enumerate(map(int,input().split())):
        imos[over]+=1
        over=max(over,i-(x-1)//2)

    for i in range(n-1):
        imos[i+1]+=imos[i]

    ans=1
    chosen=0
    for c in imos:
        ans*=(c-chosen)
        ans%=MOD
        chosen+=1

    print(ans)
resolve()

Solution (Python):
def main():
    mod = 10 ** 9 + 7

    N, *X = map(int, open(0).read().split())
    ans = stack = 1
    for x in X:
        ans = ans * stack % mod
        if 2 * stack - 2 < x:
            stack += 1

    print(ans)

main()

Solution (Python):
N,*X=map(int,open(0).read().split())
a=s=1
for x in X:
 a=a*s%(10**9+7)
 if 2*~-s<x:s+=1
print(a)

Solution (Python):
i=input
i()
a=s=1
for x in i().split():
 a=a*s%(10**9+7)
 if 2*~-s<int(x):s+=1
print(a)

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

N, *X = map(int, open(0).read().split())

s = 0
ans = 1
for x in X:
    if x < 2 * s + 1:
        ans *= (s + 1)
    else:
        s += 1
        ans *= s
    ans %= mod

print(ans)

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

N, *X = map(int, open(0).read().split())

stack = []
ans = 1
for x in X:
    stack.append(x)
    if x < 2 * len(stack) - 1:
        ans = (ans * len(stack)) % mod
        stack.pop()
    else:
        ans = (ans * len(stack)) % mod

print(ans)

Solution (Python):
n = int(input())
a= list(map(int, input().split()))
MOD = 10**9 + 7

ans = 1
cnt = 1
pos = 1
for i in range(n):
    ans *= cnt
    ans %= MOD
    if a[i] < pos:
        continue
    pos += 2
    cnt += 1
print(ans)

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

N = int(input())

x = list(map(int,input().split()))
now = 1

nmul = 1
ans = 1

for i in range(N):

    if x[i] >= now:
        now += 2
        
        ans *= nmul
        ans %= mod
        
        nmul += 1

    else:
        ans *= nmul
        ans %= mod

print (ans)

Solution (Python):

from collections import defaultdict
con = 10 ** 9 + 7


def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	X = getlist()
	ans = 1
	c = 0
	for i in range(N):
		c += 1
		if 2 * c > X[i] + 1:
			ans = (ans * c) % con
			c -= 1
	
	
	
	for i in range(1, c + 1):
		ans = (ans * i) % con
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
from math import factorial

mod = 10**9+7
n = int(input())
x = list(map(int, input().split()))

prev=-1
nx = []
for i in x:
    j = min(prev+2, i)
    prev = j
    nx.append(j)

prev = -1
cnt = 0
ans = 1
r = 0
for i in range(n):
    if r and nx[i]-prev>=3:
        nx[i] -= 1
    else:
        r = 0
    if prev+1<nx[i]:
        cnt += 1
        prev = nx[i]
    else:
        ans *= cnt+1
        r=1
        ans %= mod

ans *= factorial(cnt)
ans %= mod

print(ans)

Solution (Python):
N = int(input())
x = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

ret = 1
c = 0
for i in range(N) :
    if x[i] >= 2 * c + 1 :
        c += 1
    else :
        ret *= (c + 1)
        ret %= mod
        
for i in range(1, c + 1) :
    ret *= i
    ret %= mod
    
print(ret)

Solution (Python):
import sys
input = sys.stdin.readline

mod = 10**9+7

N = int(input())
A = list(map(int, input().split()))

i = 0
c = 0
ans = 1
while i < N:
    if 2*c + 1 <= A[i]:
        i += 1
        c += 1
    else:
        ans = ans * (c+1) % mod
        i += 1
for n in range(1, c+1):
    ans = ans * n % mod
print(ans)

Solution (Python):
MOD = 10 ** 9 + 7
n = int(input())
x = list(map(int, input().split()))
ans = 1
cnt = 0
for i in range(n):
    if x[i] < (i - cnt) * 2 + 1:
        ans *= i - cnt + 1
        cnt += 1
        ans %= MOD
for i in range(n - cnt):
    ans *= (i + 1)
    ans %= MOD
print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))

MOD = 10**9+7

ans = 1
robots = 0

for x in X:
    if x > 2*robots:
        robots += 1
    else:
        ans *= (robots+1)
        ans %= MOD

for n in range(1,robots+1):
    ans *= n
    ans %= MOD

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10**9 + 7

N = int(readline())
X = np.array(read().split(),np.int64)


x = (2*np.arange(N) + 2 - X)//2
x = np.maximum(x,0)
np.maximum.accumulate(x,out=x)

x = np.bincount(x[:-1],minlength=N)
x[0] += 1
np.cumsum(x,out=x)
x -= np.arange(len(x))

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

answer = cumprod(x,MOD)[-1]
print(answer)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

MOD = pow(10, 9) + 7

def main():
    n = int(input())
    x = list(map(int, input().split()))
    fac = [1]
    for i in range(2, n+1):
        fac.append(fac[-1]*i%MOD)
    ans= 1
    i = 1
    for _x in x:
        if _x < 2*i-1:
            ans = ans * i % MOD
        else:
            i += 1
    ans = ans * fac[i-2] % MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

comb = Combination(N + 100)

ans = 1
dis = 0
for num, a in enumerate(A, start=1):
    nowRobot = num - dis
    maxRobot = -(-a // 2)

    if maxRobot >= nowRobot:
        continue
    else:
        ans *= comb.npr(nowRobot, nowRobot - maxRobot)
        ans %= MOD
        dis += nowRobot - maxRobot

ans *= comb.factN(N - dis)
ans %= MOD

print(ans)

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
x = list(map(int, input().split()))

def fact(n, mod=1000000007):
	ans = 1
	for i in range(n):
		ans *= i + 1
		if mod != 0 and ans >= mod:
			ans = ans % mod
	return ans

num = 0
ans = 1
mod = 10**9 + 7
for i in range(N - 1):
	if x[i] < 2*(i - num) + 1:
		ans *= i - num + 1
		ans %= mod
		num += 1
ans *= fact(N - num)
ans %= mod
print(ans)

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
p = 10 ** 9 + 7
P = [1 for _ in range(N + 1)]
for i in range(N):
  P[i + 1] = P[i] * (i + 1) % p
T = [N - 1] * N
pos = 0
for i in range(N):
  if 2 * i + 1 - X[i] >= 2 * pos + 1:
    T[pos] = i
    pos += 1
cnt = 1
for i, t in enumerate(T):
  cnt *= t + 1 - i
  cnt %= p
print(cnt)

Solution (Python):

MOD = 10**9 + 7
n = int(input())
a = [int(item) for item in input().split()]

ans = 1
prev = 0
vacant = 0
robot = 0
for item in a:
    vacant += item - prev - 1
    robot += 1
    if vacant <= robot - 2:
        ans *= robot
        ans %= MOD
        robot -= 1
        vacant += 1
    prev = item
for i in range(robot):
    ans *= i+1
    ans %= MOD
print(ans)

Solution (Python):
N = int(input())
x = list(map(int, input().split()))
mod = 10 ** 9 + 7

k = 0
ans = 1
for i in range(N):
    free = x[i] - (k * 2 + 1)
    if free >= 0:
        k += 1
    else:
        ans = (ans * (k + 1)) % mod
for i in range(1, k + 1):
    ans = (ans * i) % mod
print(ans)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))


def factorial(x):
    ret = 1
    for i in range(2, x + 1):
        ret *= i
        ret %= MOD
    return ret




forwards = 0

rank = 0
ans = 1
for x in X:
    if x <= forwards * 2:
        
        ans *= forwards + 1
        ans %= MOD
        rank += 1
        continue
    forwards += 1
ans *= factorial(forwards)
print(ans % MOD)

Solution (Python):
from itertools import accumulate
from bisect import bisect
N = int(input())
X = list(map(int, input().split()))
mod = 10**9+7
T = [2 + i - (1+x)//2 for i, x in enumerate(X)]
T = list(accumulate(T, max))
D = [min(1 + bisect(T, i), N) - i + 1 for i in range(1, N + 1)]
ans = 1
for d in D:
    ans = (ans * d)%mod
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

L = []
n = 0
for i, x in enumerate(X, 1):
    n_ = i - (x+2)//2  
    n = max(n, n_)
    L.append(n)
    n_ = i - (x+1)//2
    n = max(n, n_)
from itertools import groupby
ans = 1
mod = 10**9+7
su = 0
n_used = 0
for n_, gr in groupby(L):
    su += len(list(gr))
    ans = ans * su % mod
    su -= 1
for n_ in range(2, N-n_):
    ans = ans * n_ % mod

print(ans)

Solution (Python):
MOD=10**9+7

n = int(input())
a = map(int, input().split())

c = 0
ans = 1

for ai in a:
  c += 1
  if ai < 2*c-1:
    ans = (ans*c)%MOD
    c -= 1

for ci in range(1, c+1):
  ans = (ans*ci)%MOD

print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
 
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7
 
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
 
 
def main():
    n = I()
    a = LI()
    r = 1
    c = 0
    for b in a:
        if b <= c * 2:
            r *= c+1
            r %= mod
        else:
            c += 1
    for b in range(2,c+1):
        r *= b
        r %= mod
 
    return r
 
 
print(main())

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    r = 1
    c = 0
    for b in a:
        if b <= c * 2:
            r *= c+1
            r %= mod
        else:
            c += 1
    for b in range(2,c+1):
        r *= b
        r %= mod

    return r


print(main())

Solution (Python):
input()
a=j=1
for i in input().split():
	a=a*j%(10**9+7)
	j+=j*2<int(i)+2
print(a)

Solution (Python):
n,ans,j=input(),1,1
for i in input().split():
	ans=ans*j%int(1e9+7)
	j+=j*2<int(i)+2
print(ans)

Solution (Python):
N=int(input())
x=[int(i) for i in input().split()]
ans=1
index=0
advance=0
devide=10**9+7

while True:
	if 2*(index-advance)+1 <= x[index]:
		index+=1
		if index==N:
			break
	else:
		ans*=(index-advance+1)
		ans%=devide
		index+=1
		advance+=1
		if index==N:
			break
for i in range(index-advance,0,-1):
	ans*=i
	ans%=devide
print(ans)

Solution (Python):
import sys

INF = 1000000007

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

N = ni()
x = nal()
x.insert(0, 0)

n = 1
c = 0
a = 1

for i in range(N):
    t = x[i+1] - x[i] - 1
    c = c+1
    if(t > 1):
        n = n+t-1
    elif(t == 0):
        n = n-1
        if(n == -1):
            n = 1
            a = a*c
            c = c-1

for i in range(1, c+1):
    a = a*i%INF

print(a % INF)

Solution (Python):
import sys

INF = 1000000007

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

N = ni()
x = nal()
x.insert(0, 0)

n = 1
c = 0
a = 1

for i in range(N):
    t = x[i+1] - x[i] - 1
    c = c+1
    if(t > 1):
        n = n+t-1
    elif(t == 0):
        n = n-1
        if(n == -1):
            n = 1
            a = a*c%INF
            c = c-1

for i in range(1, c+1):
    a = a*i%INF

print(a % INF)