{$APPTYPE CONSOLE}

uses Math, SysUtils;

const
	MAXN = 1001;
	MAXE = 4 * MAXN * MAXN;
	MODULO = 1000000007;
var
	n, answer, cc, i, j: longint;
	z: array[0..MAXN] of longint;
	first: array[0..MAXN] of longint;
	next: array[0..MAXE] of longint;
	eend: array[0..MAXE] of longint;
	cost: array[0..MAXE] of longint;
	color: array[0..MAXN] of longint;
	edges: longint;

procedure addEdge(u, v, c: longint);
begin
	next[edges] := first[u];
	eend[edges] := v;
	cost[edges] := c;
	first[u] := edges;
	inc(edges);
end;
	
function dfs(u, c: longint): boolean;
var
	i: longint;
begin
	if color[u] <> -1 then begin
		dfs := color[u] = c;
		exit;
	end;
	color[u] := c;
	i := first[u];
	while i <> -1 do begin
		if not dfs(eend[i], (c + cost[i]) mod 2) then begin
			dfs := false;
 			exit;
		end;
		i := next[i];
	end;
	dfs := true;
end;

begin
	assign(input, 'binary.in');
	assign(output, 'binary.out');
	reset(input);
	rewrite(output);
	readln(n);
	answer := 1;
	for i := 0 to n - 1 do begin
		read(z[i]);
		if i + z[i] > n then begin
			answer := 0;
		end;
	end;
	if z[0] = -1 then begin
		z[0] := 0;
	end;
	if z[0] <> 0 then begin
		answer := 0;
	end;
	edges := 0;
	for i := 0 to n - 1 do begin
		first[i] := -1;
		color[i] := -1;
	end;
	for i := 1 to n - 1 do begin
		if z[i] = -1 then begin
			continue;
		end;
		for j := 0 to z[i] - 1 do begin
			addEdge(j, i + j, 0);
			addEdge(i + j, j, 0);
		end;
		if i + z[i] < n then begin
			addEdge(z[i], i + z[i], 1);
			addEdge(i + z[i], z[i], 1);
		end;
	end;
	cc := 0;
	for i := 0 to n - 1 do begin
		if color[i] = -1 then begin
			if not dfs(i, 0) then begin
				answer := 0;
			end;
			inc(cc);
		end;
	end;
	for i := 1 to cc do begin
		answer := (answer * 2) mod MODULO;
	end;
	writeln(answer);
	close(input);
	close(output);
end.