#include <cstdio>
#include <cstdlib>
#define gr 512
#define ll long long
#define mdl 1000000007ll
using namespace std;

int n;
int a[gr];
ll r[gr][gr];
ll rb[gr][gr];
ll rc[gr][gr];
void postavirove()
{
    for(int i=1;i<=n;++i)
    {
        r[i][i]=0;
        rc[i][i]=a[i];
        rb[i][i]=1-a[i];
    }
    for(int i=1;i<=n+1;++i)
        r[i][i-1]=1;
}
void resi(int p,int k)
{
    //printf("resi %d %d\n",p,k);
    ll tr,trb,trc;
    tr=trb=trc=0;
    for(int i=p;i<=k;++i)
    {
        if (a[i]) trc=(trc+r[p][i-1]*r[i+1][k])%mdl;
        else      trb=(trb+r[p][i-1]*r[i+1][k])%mdl;
    }
    for(int i=p+1;i<k;++i)
    {
        if (a[i]!=a[p])  tr=(tr+rb[p+1][i-1]*rb[i+1][k]+rc[p+1][i-1]*rc[i+1][k])%mdl;
        else             tr=(tr+rb[p+1][i-1]*rc[i+1][k]+rc[p+1][i-1]*rb[i+1][k])%mdl;
    }
    r[p][k]=tr;
    rb[p][k]=trb;
    rc[p][k]=trc;
}
void resisve()
{
    postavirove();
    for(int d=1;d<n;++d)
        for(int i=1;i+d<=n;++i)
            resi(i,i+d);
}
int Zvezda(int N, int *A)
{
    n=N;
    for(int i=1;i<=n;++i)a[i]=A[i];
    resisve();
    return (int)(r[1][n]);
}

int glup[gr];
int mainn()
{
    int nn;
    scanf("%d",&nn);
    for(int i=1;i<=nn;++i)scanf("%d",glup+i);
    int res=Zvezda(nn,glup);

    printf("\n");
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=n;++j)
            printf("%d ",rb[i][j]); printf("\n"); }
    printf("\n");
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=n;++j)
            printf("%d ",rc[i][j]); printf("\n"); }
    printf("\n");
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=n;++j)
            printf("%d ",r[i][j]); printf("\n"); }
    printf("\n");

    printf("%d\n",res);
    system("PAUSE");
    return 0;
}