#include using namespace std; #define rep(i,n) for(long long i = 0; i < (long long)(n); i++) using ll = long long; using vll = vector; #define mo (ll)(1e9+7) ll n; vll b; ll baa[2][2][2] = { {{0,-1},{0,1}}, {{1,3},{1,0}}, }; // i(2<=i= 0) return dp[i][p][pp]; if (i == n-1) { ll dis; dis = baa[b[i-1]][pp][p]; if (dis != 3 && dis != c) return dp[i][p][pp] = 0; dis = baa[b[i]][p][c]; if (dis != 3 && dis != a0) return dp[i][p][pp] = 0; return dp[i][p][pp] = 1; } else { ll state = baa[b[i-1]][pp][p]; ll ret = 0; if (state == 0 || state == 3) (ret += dfs(i+1, 0, p, a0, c)) %= mo; if (state == 1 || state == 3) (ret += dfs(i+1, 1, p, a0, c)) %= mo; return (dp[i][p][pp] = ret) %= mo; } } int main(void) { cin >> n; assert(4<=n&&n<=2000); b.resize(n); rep(i, n) cin >> b[i]; rep(i, n) assert(b[i] == 0 || b[i] == 1); ll ret = 0; vll rule = {0,1,1,1,0,1,1,0}; rep(maski, 8) if (b[0] == rule[maski]) { bitset<3> mask(maski); rep(i, 2020) rep(j, 2) rep(h, 2) dp[i][j][h] = -1; (ret += dfs(2, mask[0], mask[1], mask[1], mask[2])); } cout << ret % mo << endl; return 0; }