N = int(input()) e = [] for i in range(N): e.append(int(input())) dp = [[[0] * 4 for _ in range(N)] for _ in range(4)] for i in range(4): dp[i][1][i] = 1 S = [[0, 4, 7], [1, 2, 3, 5, 6]] mod = 10 ** 9 + 7 for a in range(4): for n in range(2, N): for x in range(4): for i in range(2): now = x * 2 + i if now not in S[e[n - 1]]: continue nx = now % 4 dp[a][n][nx] += dp[a][n-1][x] dp[a][n][nx] %= mod ans = 0 for a in range(4): for b in range(4): nx = b % 2 * 4 + a if nx not in S[e[0]]: continue nx = b * 2 + a // 2 if nx not in S[e[-1]]: continue ans += dp[a][-1][b] ans %= mod print(ans)