inf = open('binary.in', 'r')
ouf = open('binary.out', 'w')

n = int(inf.readline())
z = list(map(int, inf.readline().split()))

a = [set() for i in range(n)]

bad = not(z[0] == 0 or z[0] == -1)
for i in range(1, n):
	if z[i] != -1:
		if i + z[i] > n:
			bad = True
			break
		for j in range(z[i]):
			a[j].add((i + j, 0))
		if i + z[i] < n:
			a[z[i]].add((i + z[i], 1))

parity = [0] * n
vis = [False] * n

def dfs(x, p):
	global vis
	global parity
	global bad
	vis[x] = True
	parity[x] = p
	for y, d in a[x]:
		if not vis[y]:
			dfs(y, (p + d) % 2)
		if parity[y] != (p + d) % 2:
			bad = True

cnt = 0
for i in range(n):
	if not vis[i]:
		dfs(i, 0)
		cnt += 1


if bad:
	ans = 0
else:
	ans = (2 ** cnt) % (10 ** 9 + 7)

print(ans, file=ouf)
