import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } long MOD = 1_000_000_000 + 7; int[] e; int n; void run() { Scanner sc = new Scanner(System.in); n = sc.nextInt(); e = new int[n]; for (int i = 0; i < e.length; ++i) e[i] = sc.nextInt(); long ans = 0; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { ans = (ans + calc(i, j)) % MOD; } } System.out.println(ans); } long calc(int v1, int v2) { long[][][] dp = new long[2][2][2]; dp[0][v1][v2] = 1; for (int i = 1; i < n - 1; ++i) { for (int tmp = 0; tmp < 2; ++tmp) for (int tmp2 = 0; tmp2 < 2; ++tmp2) dp[i % 2][tmp][tmp2] = 0; for (int u = 0; u <= 1; ++u) { for (int v = 0; v <= 1; ++v) { for (int w = 0; w <= 1; ++w) { if (f(u, v, w) == e[i]) { dp[i % 2][v][w] = (dp[i % 2][v][w] + dp[(i % 2) ^ 1][u][v]) % MOD; } } } } } long ret = 0; for (int i = 0; i <= 1; ++i) { for (int j = 0; j <= 1; ++j) { if (f(i, j, v1) == e[n - 1] && f(j, v1, v2) == e[0]) { ret = (ret + dp[(n % 2)][i][j]) % MOD; } } } return ret; } int f(int a, int b, int c) { int[] ret = new int[] { 0, 1, 1, 1, 0, 1, 1, 0 }; return ret[a << 2 | b << 1 | c]; } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }