import sys sys.setrecursionlimit(10 ** 6) def II(): return int(sys.stdin.readline()) def main(): md = 10 ** 9 + 7 n = II() ee = [II() for _ in range(n)] ans = 0 for sj in range(2): for sk in range(2): dp = [[[0] * 2 for _ in range(2)] for _ in range(n + 1)] dp[0][sj][sk] = 1 for i, e in enumerate(ee): for j in range(2): for k in range(2): pre = dp[i][j][k] % md if pre == 0: continue if (j, k, e) == (0, 1, 0): continue if (j, k, e) == (0, 1, 1): dp[i + 1][k][0] += pre dp[i + 1][k][1] += pre elif k == e: dp[i + 1][k][0] += pre else: dp[i + 1][k][1] += pre ans += dp[n][sj][sk] print(ans % md) main()