#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define MAXN 505
ll dp[MAXN][MAXN];
const ll MOD = 1e9+7;
bool bio[MAXN][MAXN];
int niz[MAXN];
int n;

ll sracunaj(int l,int r)
{
    if(l>r)swap(l,r);
    if(bio[l][r])return dp[l][r];
    if(abs(r-l+1)%4!=0){bio[l][r]=1;dp[l][r]=0;return dp[l][r];}
    bio[l][r]=1;
    for(int a = l; a <= r; a++)
    {
        if(a>n)a-=n;
        for(int b = a; b <= r; b++)
        {
            if(b>n)b-=n;
            if(a==b)continue;
            for(int c = b; c <= r; c++)
            {
                if(c==a||c==b)continue;
                if(c>n)c-=n;
                for(int d = c; d <= r; d++)
                {
                    if(d==a||d==b||d==c)continue;
                    if(d>n)d-=n;
                    if(niz[a]+niz[b]+niz[c]+niz[d]==1 || niz[a]+niz[b]+niz[c]+niz[d]==3)
                    {
                        ll p1,p2,p3,p4,p5;
                        //ll p1 = sracunaj(i,a-1);
                        //ll p2 = sracunaj(a+1,b-1);
                        //ll p3 = sracunaj(b+1,c-1);
                        //ll p4 = sracunaj(c+1,d-1);
                        //ll p5 = sracunaj(d+1,j);
                        if(l==a)p1=1;
                        else p1=sracunaj(l,a-1);
                        if(a+1==b)p2=1;
                        else p2=sracunaj(a+1,b-1);
                        if(b+1==c)p3=1;
                        else p3=sracunaj(b+1,c-1);
                        if(c+1==d)p4=1;
                        else p4=sracunaj(c+1,d-1);
                        if(d==r)p5=1;
                        else p5=sracunaj(d+1,r);
                        dp[l][r]+=( ((p1*p2%MOD)*(p3*p4%MOD)%MOD)*p5%MOD);
                        dp[l][r]%=MOD;
                    }
                }
            }
        }
    }
}

int Zvezda(int N,int* A)
{
    for(int i = 1; i <= N; i++)niz[i]=A[i];
    return (int)(sracunaj(1,N)+2*MOD)%MOD;
}