import java.io.*; import java.util.*; public class Main_yukicoder663 { private static Scanner sc; private static Printer pr; private static void solve() { final int MOD = 1_000_000_007; int n = sc.nextInt(); int[] e = new int[n]; for (int i = 0; i < n; i++) { e[i] = sc.nextInt(); } int[] mm = {0, 1, 1, 1, 0, 1, 1, 0}; long ans = 0; for (int s = 0; s < 8; s++) { long[][] dp = new long[4][n]; if (mm[s] != e[0]) { continue; } dp[s & 0x3][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < 8; j++) { if (mm[j] != e[i]) { continue; } dp[j & 0x3][i] += dp[j >> 1][i - 1]; dp[j & 0x3][i] %= MOD; } } for (int i = 0; i < 4; i++) { if (i == s >> 1) { ans += dp[i][n - 1]; ans %= MOD; } } } pr.println(ans); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }