#include "bits/stdc++.h" #define REP(i,n,N) for(ll i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<> typedef long long ll; using namespace std; const ll mod=1e9+7; ll N; ll e[2010]; ll dp[2010][2][2]; ll check(ll a,ll b, ll c){ if(b==0&&c==0) return 0; if(a==1&&b==1&&c==1) return 0; return 1; } int main() { cin >> N; REP(i, 0, N) cin >> e[i]; ll ans=0; REP(w1, 0, 2) { REP(w2, 0, 2) { REP(k,0,N+1) REP(a,0,2) REP(b,0,2) dp[k][a][b]=0; dp[2][w1][w2]=1; REP(l,2,N){ REP(i,0,2){ REP(j,0,2){ REP(k,0,2){ if (check(i, j, k) == e[l-1]) { dp[l+1][j][k] += dp[l][i][j]; dp[l+1][j][k] %= mod; } } } } } REP(i,0,2){ REP(j,0,2){ if(check(i,j,w1)==e[N-1]&&check(j,w1,w2)==e[0]){ ans+=dp[N][i][j]; } } } } } p(ans); return 0; }