#include<cstdio>
#include<cstdlib>
#include<cstring>
#define N 10010
long long f[N][2][2];
int n,i,j,k,l,a[N];
int main()
{
scanf("%d",&n);
for (i=1;i<=n;i++) scanf("%d",&a[i]);
memset(f,0,sizeof(f));
f[0][0][1]=f[0][0][0]=1;
for (i=1;i<=n;i++)
for (j=0;j<=1;j++)
for (k=0;k<=1;k++)
for (l=0;l<=1;l++)
if (j+k+l==a[i])
{
f[i][j][k]+=f[i-1][l][j];
}
printf("%lld\n",f[n][1][0]+f[n][0][0]);
}