#include using namespace std; using ll = long long; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))< ostream& operator<<(ostream& o, const pair &p){o<<"("< ostream& operator<<(ostream& o, const vector &v){o<<"[";for(T t:v){o<=0) return dp[x][l][m]; ll ret = 0; if(x==n-2){ return (g(l,m,last) == e[x] && g(m,last,first) == e[x+1]); } else{ rep(i,2)if(g(l,m,i) == e[x]) (ret += dfs(x+1,m,i)) %= mod; } return dp[x][l][m] = ret; } int main(){ cin >>n; rep(i,n) cin >>e[i]; ll ans = 0; rep(i,2)rep(j,2){ memset(dp,-1,sizeof(dp)); first = i; last = j; (ans += dfs(0,j,i)) %= mod; } cout << ans << endl; return 0; }