#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
vector<int> niz;
const int M=500;
int dp[M][M][14];
const int mod=1e9+7;
int add(int a,int b)
{
    a+=b;
    if(a>=mod)
        a-=mod;
    return a;
}
int mul(int a,int b){
    return (ll)a*b%mod;
}
int calc(int l,int r,int s)
{
    if(l>r){
        if(s==0||s==7||s==13)
            return 1;
        return 0;
    }
    if(dp[l][r][s]!=-1)
        return dp[l][r][s];
    dp[l][r][s]=0;
    for(int i=l;i<=r;i+=4)
    {
        if(niz[i]==0)
        {
            if(s==0||s==1||s==2||s==4||s==5||s==6||s==8||s==12)
                dp[l][r][s]=add(dp[l][r][s],mul(calc(l,i-1,0),calc(i+1,r,s+1)));
        }
        else
        {
            if(s==0||s==1||s==2||s==3||s==4||s==5||s==8||s==9)
                dp[l][r][s]=add(dp[l][r][s],mul(calc(l,i-1,0),calc(i+1,r,s+4)));
        }
    }
    return dp[l][r][s];
}
int Zvezda(int n, int* a) {
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
        niz.pb(a[i]);
    return calc(0,n-1,0);
}