Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.

The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge. 

When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7).

Input

The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1. 

It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation.

Output

Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7).

Examples

Input

5
-1 -1 4 3 -1


Output

2

Note

For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point.

Difficulty: HARD
Tags: Combinatorics

Mathematics

Starter code:

Solutions:
import sys
readline = sys.stdin.buffer.readline

def even(n):
	return 1 if n % 2 == 0 else 0
mod = 10 ** 9 + 7

def pow(n, p, mod=mod):
	res = 1
	while p > 0:
		if p % 2 == 0:
			n = n ** 2 % mod
			p //= 2
		else:
			res = res * n % mod
			p -= 1
	return res % mod

def factrial_memo(n=10 ** 5, mod=mod):
	fact = [1, 1]
	for i in range(2, n + 1):
		fact.append(fact[-1] * i % mod)
	return fact
fact = factrial_memo()

def permutation(n, r):
	return fact[n] * pow(fact[n - r], mod - 2) % mod

def combination(n, r):
	return permutation(n, r) * pow(fact[r], mod - 2) % mod

def homogeneous(n, r):
	return combination(n + r - 1, r) % mod
n = int(readline())
lst1 = list(map(int, readline().split()))
ct = 0
lst2 = [0] * 2001
lst3 = [0] * 2001
for i in range(n):
	if i + 1 == lst1[i]:
		print(0)
		exit()
	if lst1[i] == -1:
		ct += 1
		lst3[i + 1] = 1
	else:
		lst2[lst1[i]] = 1
ct2 = 0
for i in range(1, n + 1):
	if lst3[i] == 1 and lst2[i] == 0:
		ct2 += 1
ans = 0
for i in range(ct2 + 1):
	ans += pow(-1, i) * combination(ct2, i) * fact[ct - i]
	ans %= mod
print(ans)


MOD = 10 ** 9 + 7
n = int(input())
notUsed = set(range(1, n + 1))
chairs = set()
for (i, a) in enumerate(map(int, input().split()), 1):
	if a == -1:
		chairs.add(i)
	else:
		notUsed -= {a}
fixed = len(chairs & notUsed)
m = len(notUsed)
fact = [0] * (m + 1)
fact[0] = 1
for i in range(1, m + 1):
	fact[i] = fact[i - 1] * i % MOD
fact_inv = [0] * (m + 1)
fact_inv[m] = pow(fact[m], MOD - 2, MOD)
for i in reversed(range(m)):
	fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD

def nCr(n, r):
	if r < 0 or n < r:
		return 0
	return int(fact[n] * fact_inv[r] * fact_inv[n - r])
ans = fact[m]
for k in range(1, fixed + 1):
	ans += nCr(fixed, k) * fact[m - k] * (-1) ** k
	ans %= MOD
print(ans)


def fact(x):
	ans = 1
	for i in range(2, x + 1):
		ans *= i
	return ans
n = int(input())
a = [int(x) for x in input().split()]
s = set(a)
x = 0
y = 0
for i in range(1, n + 1):
	if a[i - 1] == -1:
		g = i in s
		(x, y) = (x + 1 - g, y + g)
otv = fact(x + y)
currf = fact(x + y - 1) // fact(x - 1) * fact(x)
if x:
	otv -= currf
for i in range(2, x + 1):
	currf //= i
	currf *= x - i + 1
	currf //= x + y - i + 1
	if i & 1:
		otv -= currf
	else:
		otv += currf
otv %= 1000000007
print(otv)


input()
t = list(map(int, input().split()))
(s, m) = (0, 1000000007)
p = {i for (i, q) in enumerate(t, 1) if q == -1}
(n, k) = (len(p), len(p - set(t)))
(d, c) = (2 * (n & 1) - 1, 1)
for j in range(n + 1):
	d = -d * max(1, j) % m
	if n - j <= k:
		s += c * d
		c = c * max(1, n - j) * pow(k - n + j + 1, m - 2, m) % m
print(s % m)


def main():
	mod = 10 ** 9 + 7
	lim = 20200
	fct = [0] * lim
	inv_f = [0] * lim
	fct[0] = 1
	for i in range(1, lim):
		fct[i] = fct[i - 1] * i % mod
	inv_f[lim - 1] = pow(fct[lim - 1], mod - 2, mod)
	for i in range(lim - 1, 0, -1):
		inv_f[i - 1] = inv_f[i] * i % mod

	def nCk(a, b):
		if b == 0:
			return 1
		else:
			return fct[a] * inv_f[b] * inv_f[a - b] % mod

	def nPk(a, b):
		return fct[a] * inv_f[a - b] % mod
	n = int(input())
	s = list(map(int, input().split()))
	(ind, rem) = (set(), set())
	for (i, x) in enumerate(s):
		if x == -1:
			ind.add(i + 1)
		else:
			rem.add(x)
	dif = set(range(1, n + 1)) - rem
	k = len(ind)
	l = len(ind & dif)
	res = 0
	for i in range(l + 1):
		tmp = fct[k - i] * nCk(l, i) % mod
		if i & 1:
			res -= tmp
		else:
			res += tmp
	print(res % mod)
main()