Imagine you have a rooted tree consisting of $n$ vertices. Consider the following function:

int order[n]; // initially consists of -1
int pointer = 0;
void dfs(int vertex, int depth) {
  order[pointer] = depth;
  pointer++;
  for each child of vertex
    dfs(child, depth + 1);
}

In the end this function produces an array ${order}[]$. We will call an array suitable if and only if it can be produced as a result of running $dfs(root,0)$ on a rooted tree with $n$ vertices. 

You are given an array ${a}$, whose elements are either question signs or integer numbers. How many suitable arrays can you get, if you are allowed to replace any question sign with non-negative integer number? Print this number modulo $10^9+7$.

Input Format  

The first line contains a single integer $n$, that is the size of array ${a}$. The next line contains $n$ elements of the array: $a[0],a[1],...,a[n-1]$. Each element is either a question sign, or a non-negative integer number which doesn't exceed ${200}$.  

Constraints 

$1\leq n\leq10^5$ 

$0\leq a[i]\leq200$

Output Format

Print a single integer $-$ the number of suitable arrays you can get modulo $10^9+7$.

Sample Input #0

3
? ? ?    

Sample Output #0

2

Sample Input #1

2
1 ?

Sample Output #1

0

Sample Input #2

4
0 ? 1 ?

Sample Output #2

2

Explanation

In sample#0 there are two possible arrays: [0, 1, 2] and [0, 1, 1];

In sample#1 there cannot be any suitable arrays, because each of them starts with 0.

Difficulty: HARD
Tags: Combinatorics

Starter code:

Solutions:
MOD = 10 ** 9 + 7
Factorial = [1] * 300000
for n in range(2, len(Factorial)):
	Factorial[n] = Factorial[n - 1] * n % MOD

def inv(n):
	return pow(n, MOD - 2, MOD)

def BinCoeff(n, k):
	if n < k or k < 0:
		return 0
	if n == k or k == 0:
		return 1
	return Factorial[n] * inv(Factorial[k] * Factorial[n - k]) % MOD

def solve2(x1, y1, x2, y2):
	return (BinCoeff(y2 + x2 - y1 - x1, y2 - y1) - BinCoeff(y2 + x2 - x1 - y1, y2 - x1 - 1)) % MOD

def solve(A):
	if A[0] != '?' and A[0] != '0':
		return 0
	if len(A) == 1:
		return 1
	B = {0: 0}
	for x in range(1, len(A)):
		if A[x] != '?':
			B[x - 1] = x - int(A[x])
	B[len(A) - 1] = len(A) - 1
	B_ind = []
	for b in B:
		if B[b] > b:
			return 0
		B_ind.append(b)
	B_ind.sort()
	for x in range(1, len(B_ind)):
		if B[B_ind[x]] < B[B_ind[x - 1]]:
			return 0
	result = 1
	for x in range(1, len(B_ind)):
		result = result * solve2(B_ind[x - 1] + 1, B[B_ind[x - 1]], B_ind[x], B[B_ind[x]]) % MOD
	return result
n = int(input())
A = input().split()
print(solve(A))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(input())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))


import sys
MOD = 10 ** 9 + 7
MAXN = 10 ** 5
MAXAI = 200
factLim = 2 * MAXN + MAXAI
fact = [1] + [0] * factLim
for i in range(1, factLim + 1):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, k):
	if k < 0 or n < 0 or k > n:
		return 0
	if k == 0 or k == n:
		return 1
	return fact[n] * pow(fact[k] * fact[n - k], MOD - 2, MOD) % MOD

def preliminaryCheck_isInvalid(S, N):
	if S[0] != '?' and S[0] != 0:
		return True
	for i in range(1, N):
		if S[i] != '?' and S[i] > i:
			return True
		if S[i] == 0:
			return True
		if (S[i] != '?' and S[i - 1] != '?') and S[i] - 1 > S[i - 1]:
			return True
	return False

def numQuestionSeq(a, b, n):
	return comb(2 * n + a - b + 1, n) - comb(2 * n + a - b + 1, n - b)

def numSuitable(S, N):
	if preliminaryCheck_isInvalid(S, N):
		return 0
	S[0] = 0
	S += [1]
	aIndex = 0
	bIndex = 1
	ans = 1
	while aIndex < N and bIndex < N:
		while bIndex < N and S[bIndex] == '?':
			bIndex += 1
		n = bIndex - aIndex - 1
		(a, b) = (S[aIndex], S[bIndex])
		if n > 0:
			ans = ans * numQuestionSeq(a, b, n) % MOD
		aIndex = bIndex
		bIndex += 1
	return ans
N = int(sys.stdin.readline())
S = [int(k) if k.isdigit() else k for k in sys.stdin.readline().split()]
print(numSuitable(S, N))