import java.io.*;
import java.util.*;

public class binary_av {

	FastScanner in;
	PrintWriter out;
	
	final int mod = (int) (1e9 + 7);

	void solve() {
		int n = in.nextInt();
		int[] z = new int[n];
		for (int i = 0; i < n; i++) {
			z[i] = in.nextInt();
		}

		if (z[0] != -1 && z[0] != 0) {
			out.println(0);
			return;
		}
		
		DSU2Coloring dsu = new DSU2Coloring(n);
		for (int i = 1; i < n; i++) {
			if (z[i] != -1) {
				for (int j = 0; j < z[i]; j++) {
					if (i + j >= n || !dsu.union(j, i + j, 0)) {
						out.println(0);
						return;
					}
				}
				if (i + z[i] < n) {
					if (!dsu.union(z[i], i + z[i], 1)) {
						out.println(0);
						return;
					}
				}
			}
		}
		
		int ans = 1;
		for (int i = 0; i < dsu.comps; i++) {
			ans = (ans * 2) % mod;
		}
		out.println(ans);
	}

	class DSU2Coloring {
		int[] dist, parent, rank;
		int comps;
		
		public DSU2Coloring(int n) {
			dist = new int[n];
			parent = new int[n];
			rank = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
			}
			comps = n;
		}
		
		int get(int v) {
			if (parent[v] == v) {
				return v;
			}
			int root = get(parent[v]);
			dist[v] = dist[v] ^ dist[parent[v]];
			return parent[v] = root;
		}
		
		boolean union(int a, int b, int d) {
			int rootA = get(a), rootB = get(b);
			if (rootA == rootB) {
				if ((dist[a] ^ dist[b]) != d) {
					return false;
				}
				return true;
			}
			
			comps--;
			int rootDist = dist[a] ^ dist[b] ^ d;
			
			if (rank[rootA] == rank[rootB]) {
				rank[rootA]++;
			}
			if (rank[rootA] > rank[rootB]) {
				parent[rootB] = rootA;
				dist[rootB] = rootDist;
			} else {
				parent[rootA] = rootB;
				dist[rootA] = rootDist;
			}
			
			return true;
		}
	}

	void run() {
		try {
			in = new FastScanner("binary.in");
			out = new PrintWriter("binary.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new binary_av().run();
	}
}
