/*
#include <iostream>

using namespace std;
*/

typedef long long ll;

int n;
int *a;
int b[501];
ll mod = 1e9+7;

int abs(int x)
{
    return (x < 0) ? -x : x;
}

int pov(int x)
{
    return (x+3)%n + 1;
}

int dist(int a, int b)
{
    if(a > b) return n - (a - b - 1) - 2;
    return (b - a -1);
}

bool uIntervalu(int i, int l, int d)
{
    if(l < d) return l <= i && i <= d;
    else return !uIntervalu(i, (l == 1) ? n : l-1, d%n+1);
}

ll mem[501][501];

ll brNacina(int l, int d)
{
    if(d - l + 1 == 4) return (a[l] + a[l+1] + a[l+2] + a[l+3])%2 == 1;
    if(mem[l][d] != -1) return mem[l][d];
    int brZ = (d - l + 1)/4;
    if((b[d] - b[l-1])%2 != brZ%2) return 0;

    //for(int i = 0; i < dub; i++) cout << "\t";
    //cout << "Pozvan za " << l << " " << d << " " << endl;
    ll rez = 0;

    for(int i = l + 1; l <= i && i <= d; i += 4)
    {
        for(int j = i + 1; l <= j && j <= d; j += 4)
        {
            for(int k = j + 1; l <= k && k <= d; k += 4)
            {
                if((a[i] + a[j] + a[k] + a[l]) % 2 == 1)
                {
                    //cout << "Validna trojka " << root << " " << i << " " << j << " " << k << endl;
                    ll a1 = 1, a2 = 1, a3 = 1, a4 = 1;
                    if(i-l != 1) a1 = brNacina(l + 1, i-1);
                    if(j-i != 1) a2 = brNacina(i + 1, j-1);
                    if(k-j != 1) a3 = brNacina(j + 1, k-1);
                    if(k != d) a4 = brNacina(k + 1,  d);
                    rez += (((((a1*a2)%mod)*a3)%mod)*a4)%mod;
                    if(rez > mod) rez -= mod;
                }
                //else cout << "Nije validna " << root << " " << i << " " << j << " " << k << endl;
            }
        }
    }
    //while(dub--) cout << "\t";
    //cout << "Ovako moze " << rez << endl;
    mem[l][d] = rez%mod;
    return rez%mod;
}

int Zvezda(int nn, int *aa)
{
    n = nn, a = aa;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            mem[i][j] = -1;
    if(n == 4) return (a[1] + a[2] + a[3] + a[4])%2 == 1;
    b[1] = a[1];
    for(int i = 2; i <= n; i++)
        b[i] = b[i-1] + a[i];
    ll rez = 0;

    for(int i = 2; true; i = pov(i))
    {
        for(int j = i%n + 1; true; j = pov(j))
        {
            int zbir = a[1] + a[i] + a[j], potrebna = 0;
            if(zbir == 0 || zbir == 2) potrebna = 1;
            for(int k = j%n + 1; true; k = pov(k))
            {
                if(a[k] == potrebna)
                {
                    //cout << "\tValidna trojka " << root << " " << i << " " << j << " " << k << endl;
                    ll a1 = 1, a2 = 1, a3 = 1, a4 = 1;
                    if(abs(1 - i) != 1) a1 = brNacina(2, i-1);
                    if(abs(i - j) != 1) a2 = brNacina(i%n + 1, j-1);
                    if(abs(j - k) != 1) a3 = brNacina( j%n + 1, k-1);
                    if(k != n) a4 = brNacina(k%n + 1, n);

                    rez += (((((a1*a2)%mod)*a3)%mod)*a4)%mod;
                    if(rez > mod) rez -= mod;
                }
                //else cout << "\tNije validna " << root << " " << i << " " << j << " " << k << endl;
                if(pov(k) < k) break;
            }
            if(pov(j) < j) break;
        }
        if(pov(i) < i) break;
    }
    return rez%mod;
}

/*
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 1; i <= n; i++) cin >> a[i];
    cout << Zvezda(n, a);
    return 0;
}
*/