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.



Sample input:
3
1 2 3


Sample output:
4

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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))
        # print(ans, i+1, x, l)

    return ans


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")

MOD = 1000000007  # type: int


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

    # hint[i]はi番目の要素より前のスペースの数
    hint = [(x[i]-1) - i for i in range(N)]
    # print(hint)
    ans = 1
    count = 1
    curr = 0

    # j回数える
    for j in range(N):
        # 前からゴール可能な数の個数を数える
        while True:
            # スペースの数 hint[curr]+j 個
            if curr >= N:
                break
            if count >= N-j:
                break
            if count-(hint[curr]+j) == 2:
                break
            count += 1
            curr += 1
        # print(count)
        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))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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

#solve
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


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ライブラリインポート
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
	# print(ans)
	# print(c)
	
	for i in range(1, c + 1):
		ans = (ans * i) % con
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3.6
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)

Submission status: Accepted

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

Submission status: Accepted

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


# 前から1刻みに置ければ、そこまでにいる人は1位になれる
# 前にいる人の数
forwards = 0
# 今ゴールしたら何位になるか
rank = 0
ans = 1
for x in X:
    if x <= forwards * 2:
        # 1 人ゴールさせる
        ans *= forwards + 1
        ans %= MOD
        rank += 1
        continue
    forwards += 1
ans *= factorial(forwards)
print(ans % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

L = []
n = 0
for i, x in enumerate(X, 1):
    n_ = i - (x+2)//2  # xを先頭にするために落とさなきゃいけない数
    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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)#need concern
		ans%=devide
		index+=1
		advance+=1
		if index==N:
			break
for i in range(index-advance,0,-1):
	ans*=i
	ans%=devide
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
x = map(int, raw_input().split())

MOD = 10**9+7

j = 1
ans = 1
count = 0
for i in xrange(len(x)):
    if(x[i] >= 2*j-1):
        j += 1
        continue
    else:
        ans = ans*j%MOD
        count += 1

for i in xrange(len(x)-count):
    ans = ans*(i+1)%MOD

print ans

Submission status: Accepted

Solution code:
n = input()
x = map(int, raw_input().split())

MOD = 1000000007

j = 1
ans = 1
count = 0
for i in xrange(len(x)):
    if(x[i] >= 2*j-1):
        j += 1
        continue
    else:
        ans *= j
        count += 1

for i in xrange(len(x)-count):
    ans = ans*(i+1)%MOD

print ans

Submission status: Accepted

Solution code:
input()
a=b=1
for r in input().split():
    a=a*b%(10**9+7)
    if b*2<eval(r+'+2'):b+=1
print(a)

Submission status: Accepted

Solution code:
r=raw_input
r()
a=b=1
for x in r().split():
	a,b=a*b%(10**9+7),min(b+1,(int(x)+3)/2)
print a

Submission status: Accepted

Solution code:
N = int(input())
p_list = map(int, input().split())

pat = 1
sum = 0
for i, r_pos in enumerate(p_list):
    pat = (pat * (sum + 1)) % 1000000007
    if r_pos >= 2 * sum + 1: sum += 1
print(pat)

Submission status: Accepted

Solution code:
import numpy
import math
def input_parser():
    N=int(input())
    x=[int(i) for i in input().split()]
    return N, x

N, x=input_parser()
reachability_list = numpy.zeros(N)
reachable=1
threshold=0
for idx in range(0,N,1):
    if idx==0:
        reachability_list[idx]=reachable
    else:
        while True:
            if x[idx-1]>threshold:
                reachability_list[idx]=reachable
                threshold+=2
                break
            else:
                target_threshold = math.floor((x[idx-1]-1)/2)*2
                reachable+=(threshold-target_threshold)/2
                threshold=target_threshold
l=numpy.zeros(N)
order=1
for idx in range(0,N,1):
    if not reachability_list[idx]==order:
        l[order-1]=idx-order+1
        order+=1
for itr in range(order-1,N,1):
    l[itr]=N-itr
a=1
for itr in range(0,N,1):
   a=(a*l[itr])%(10**9+7)

def output_parser(output):
    print(output)

output_parser(int(a))

Submission status: Accepted

Solution code:
from itertools import permutations, combinations

M = 10**9+7


def solve(n, x):
    res = 1
    k = 0
    for i in range(n):
        k += 1
        if x[i] < 2 * k - 1:
            res *= k
            res %= M
            k -= 1
    if k > 0:
        for i in range(1, k+1):
            res *= i
            res %= M
    return res


def solve2(n, x):
    res = 0
    for p in permutations(range(n)):
        done = set()
        ok = True
        for i in range(n):
            can_win = True
            k = 1
            for j in range(p[i]):
                if j in done:
                    continue
                can_win &= x[j] >= k
                k += 2
            ok &= can_win
            done.add(p[i])
        if ok:
            res += 1
    return res


def check():
    for n in range(1, 8):
        for x in combinations(range(1, 2 * n + 1), n):
            expected = solve2(n, list(x))
            output = solve(n, list(x))
            if output != expected:
                print('x: {}'.format(x), end='\t')
                print('output: {}'.format(output), end='\t')
                print('expected: {}'.format(expected), end='\n')
                return x

if __name__ == '__main__':

    # print(check())

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

Submission status: Accepted

Solution code:
input()
c=j=1
for s in input().split():
	c=c*j%(10**9+7)
	if j*2<int(s)+2:
		j+=1
print(c)

Submission status: Accepted

Solution code:
import sys
from math import factorial

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    X = [int(i) for i in input().split()]
    MOD = 10**9 + 7
    ans = 1
    stack = 0

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

    ans *= (factorial(stack) % MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
N = int(input().strip())
x = [int(_) for _ in input().split()]
#print(x)

count = 1
mult = 1
G = 0
for i, pos in enumerate(x):
  #print(i,pos,count,G,mult)
  count = (count * mult) % MOD
  G += 1
  if 2 * G > pos + 1:
    G -= 1
  else:
    mult += 1
print(count)

Submission status: Accepted

Solution code:
def mod_factorial(N, d):
    ans = 1
    for i in range(1,N+1):
        ans = (ans * i) % d
    return ans

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

ans = 1      
for i, x in enumerate(list_co):
    if x < 2*(i+1) -1: #(i+1) : robot number, x : coordinate of robot(i+1)
        ans *= (i+1)
        list_co.pop(i-1)
ans = (ans * mod_factorial(len(list_co),d)) % d
print(ans)

Submission status: Accepted

Solution code:
d = 10**9 + 7

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

ans = 1
def mod_factorial(N, d):
    ans = 1
    for i in range(1,N+1):
        ans = (ans * i) % d
    return ans
        
for i, x in enumerate(list_co):
    if x < 2*(i+1) -1:
        ans *= (i+1)
        list_co.pop(i-1)
ans = (ans * mod_factorial(len(list_co),d)) % d
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
rr = lambda: stdin.readline().strip()

N = int(rr())
A = map(int, rr().split())
MOD = 10**9 + 7
ct, ans = 0, 1
for x in A:
    ct += 1
    while ct > (x + 1)/2:
        ans *= ct
        ans %= MOD
        ct -= 1
for k in xrange(1, ct+1):
    ans *= k
    ans %= MOD
print ans

Submission status: Accepted

Solution code:
N = int(input())
MOD = 10**9 + 7

cnt = 1
j = 1
runner = 0

for x in map(int, input().split()):
  cnt *= j
  cnt %= MOD
  if runner >= x:
    runner = x
  else:
    j += 1
    runner += 2

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())

X = list(map(int, input().split()))

MOD = 10**9 + 7

cnt = 1
j = 1

n_to_remove = 0

runner = 1

for i,x in enumerate(X):
  j = i+1 - n_to_remove
  if runner > x:
    n_to_remove += 1
    runner = x-1
  runner += 2
  cnt = (cnt*j)%MOD

print(cnt)

Submission status: Accepted

Solution code:
n = input()
X = map(int, raw_input().split())

MOD = 10**9+7

ans = 1
res = 0
for i in xrange(n):
    while 2*res+1 > X[i]:
        ans = (ans * (res+1)) % MOD
        res -= 1
    res += 1
while res:
    ans = (ans * res) % MOD
    res -= 1
print ans

Submission status: Accepted

Solution code:
n = int(input())
count = [0]
cur = 0
data = list(map(int, input().split()))
for i,v in enumerate(data):
  count[-1] += 1
  if v < 2*(i-cur)+1:
    cur += 1
    count.append(0)
res = 1
cur = 1
for i in range(n):
  cur -= 1
  if count: cur += count.pop(0)
  res *= cur
  res %= 1000000007
print(res)

Submission status: Runtime Error

Solution code:
#from collections import deque,defaultdict
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 # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

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
    #ddprint(f"{i=} {cnt=} {p=} cd {a[i]%2==0 and cnt>a[i]//2}")
    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)

Submission status: Runtime Error

Solution code:
mod = 10**9+7
N = int(input())
x = list(map(int, input().split()))
ans = 1
cnt = 1
now = 0
while 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)

Submission status: Runtime Error

Solution code:
import sys
from itertools import permutations

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    assert N <= 8

    X = [int(i) for i in input().split()]

    cnt = 0
    MOD = 10**9 + 7

    for pm in permutations(range(N)):
        goal = [False] * N
        flag = True

        for k in pm:
            mae = 0
            for i in range(k):
                if goal[i]:
                    continue
                
                if X[i] < 2*mae + 1:
                    flag = False
                    break
                else:
                    mae += 1

            if not flag:
                break

            goal[k] = True

        cnt += flag

    print(cnt % MOD)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
from itertools import permutations

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    assert N <= 8

    X = [int(i) for i in input().split()]

    cnt = 0
    MOD = 10**9 + 7

    for pm in permutations(range(N)):
        goal = [False] * N
        flag = True

        for p in pm:
            for i in range(p-1, -1, -1):
                if goal[i]:
                    continue
                if X[i] < 2*i + 1:
                    flag = False
                    break
            if flag:
                break
            goal[p] = True

        cnt += flag

    print(cnt % MOD)


if __name__ == '__main__':
    solve()