#include #include using namespace atcoder; #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using mint = modint1000000007; int f(int a, int b, int c) { return (a and b and c) or (!b and !c) ? 0 : 1; } int main() { int n; cin >> n; vector e(n); rep(i, n) cin >> e[i]; mint ans; rep(s, 4) { vector dp(4); dp[s] = 1; rep(i, n) { vector old(4); dp.swap(old); rep(t, 4) { int a = t/2, b = t%2; rep(c, 2) { if (f(a, b, c) == e[i]) { dp[b*2+c] += old[t]; } } } } ans += dp[s]; } cout << ans.val() << '\n'; return 0; }