#include <bits/stdc++.h>
using namespace std;
typedef long long ll;    
const int NMAX=507; 
const int MOD=1e9+7;     

int a[NMAX]; 
ll dp[NMAX][NMAX];    

ll radi(int i, int j)
{
    if(dp[i][j]) return dp[i][j];     
    if(j-i<3) return 0; 
    if(j-i==3)  
    {
        int br0=0;
        int br1=0; 
        for(int t=i;t<=j;t++) 
        {
            if(a[i]==0) br0++; 
            else br1++; 
        } 
        if(br0==1 || br1==1) return 1;
        return 0; 
    } 
    for(int t1=i;t1<=j;t1++) 
    {
        for(int t2=t1+1;t2<=j;t2++) 
        {
            for(int t3=t2+1;t3<=j;t3++) 
            {
                for(int t4=t3+1;t4<=j;t4++) 
                {
                    int br0=0; 
                    int br1=0;  
                    if(a[t1]==0) br0++;
                    else br1++; 
                    if(a[t2]==0) br0++;
                    else br1++; 
                    if(a[t3]==0) br0++;
                    else br1++; 
                    if(a[t4]==0) br0++;
                    else br1++;  
                    if(br0!=1 && br1!=1) continue; 
                    dp[i][j]=(dp[i][j]+(((radi(i,t1-1)%MOD)*(radi(t1+1,t2-1)%MOD)%MOD)*((radi(t2+1,t3-1)%MOD)*(radi(t3+1,t4-1)%MOD)%MOD)%MOD)*(radi(t4+1,j)%MOD))%MOD;    
                }
            }
        }
    }
    return dp[i][j]%MOD;   
}

ll Zvezda(int N, int A[]) 
{
    for(int i=1;i<=N;i++) a[i]=A[i];   
    return radi(1,N);    
}