N=int(input()) A=[0]*N for i in range(N): A[i]=int(input()) ans = 0 mod =1000000007 for i in range(2): for j in range(2): dp=[0]*4 dp[i*2+j]=1 for k in range(1,N-1): ndp=[0]*4 if A[k]==0: ndp[3]+=dp[3] ndp[0]+=dp[0] ndp[0]+=dp[2] else : ndp[1]+=dp[0] ndp[2]+=dp[1] ndp[3]+=dp[1] ndp[1]+=dp[2] ndp[2]+=dp[3] for l in range(4): ndp[l]%=mod dp[l]=ndp[l] for k in range(4): p=1 if i==0 and j==0: p=0 if k%2==1 and i==1 and j==1: p=0 q=1 if k%2==0 and i==0: q=0 if k//2==1 and k%2==1 and i==1: q=0 if A[0]==p and A[N-1]==q: ans += dp[k] print(ans%mod)