Chef is a big fan of soccer! He loves soccer so much that he even invented soccer for dogs! Here are the rules of soccer for dogs:
- N$N$ dogs (numbered 1$1$ through N$N$) stand in a line in such a way that for each valid i$i$, dogs i$i$ and i+1$i + 1$ are adjacent.
- Each dog has a skill level, which is either 1$1$ or 2$2$.
- At the beginning of the game, Chef passes a ball to dog 1$1$ (dog 1$1$ receives the ball).
- For each valid i$i$, if dog i$i$ has skill level s$s$, this dog can pass the ball to any dog with number j$j$ such that 1≤|i−j|≤s$1 \le |i-j| \le s$.
- Each dog (including dog 1$1$) may receive the ball at most once.
- Whenever a dog receives the ball, it must either pass it to another dog or finish the game by scoring a goal.
While the dogs were playing, Chef also created a game for developers. He defined the result of a game of soccer for dogs as the sequence of dogs which received the ball in the order in which they received it. The last dog in the sequence is the dog that decided to score a goal; if a dog never received the ball, it does not appear in the sequence. In the game for developers, you should find the number of possible results of soccer for dogs.
Find this number of possible results modulo 109+7$10^9 + 7$. Two results of soccer for dogs (sequences of dogs' numbers) are considered different if these sequences have different lengths or if there is a valid index i$i$ such that the i$i$-th dog in one sequence is different from the i$i$-th dog in the other sequence.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains a single integer N$N$.
- The second line contains N$N$ space-separated integers A1,A2,…,AN$A_1, A_2, \ldots, A_N$ denoting the skill levels of the dogs.

-----Output-----
For each test case, print a single line containing one integer - the number of different results of soccer for dogs, modulo 109+7$10^9 + 7$.

-----Constraints-----
- 1≤T≤10$1 \le T \le 10$
- 1≤N≤105$1 \le N \le 10^5$
- 1≤Ai≤2$1 \le A_i \le 2$ for each valid i$i$

-----Subtasks-----
Subtask #1 (10 points): N≤10$N \le 10$
Subtask #2 (30 points): N≤103$N \le 10^3$
Subtask #3 (60 points): original constraints

-----Example Input-----
3
4
1 1 1 1
3
2 2 2
4
1 2 1 1

-----Example Output-----
4
5
6

-----Explanation-----
Example case 1: The following results are possible: 1$1$, [1,2]$[1, 2]$, [1,2,3]$[1, 2, 3]$, [1,2,3,4]$[1, 2, 3, 4]$.
Example case 2: The following results are possible: [1]$[1]$, [1,2]$[1, 2]$, [1,2,3]$[1, 2, 3]$, [1,3,2]$[1, 3, 2]$, [1,3]$[1, 3]$.

Starter code:

Solutions:
for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*num
	dp[0]=1
	ans=1
	j=0
	for i in range(1,num):
		j=i+1
		count=1
		dp[i]=dp[i-1]%1000000007
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]%1000000007
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]
		ans+=dp[i]%1000000007
		if arr[i-1]==2 and i<num-1:
			if i>=j or j==0:
				j=i+1
			while j<num and arr[j]==2:
			   	j+=1
			count=j-i
			while j<len(arr) and arr[j]==2:
				j+=1
				count+=1
			if j==num:
				ans+=dp[i-1]*(count-1)%1000000007
			elif count%2!=0:
				if j<num-1 and arr[j+1]==2:
					ans+=dp[i-1]*(count+1)%1000000007
				else:
					ans+=dp[i-1]*(count)%1000000007
			elif count%2==0:
				ans+=dp[i-1]*(count-1)%1000000007
	print(ans%1000000007)




for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*num
	dpr=[0]*num
	dpt=[0]*num
	dp[0]=1
	dpr[0]=0
	ans=1
	j=0
	for i in range(1,num):
		dp[i]=dp[i-1]%1000000007
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]%1000000007
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]%1000000007
		if arr[i-1]==2 and i<num-1:
			if i>=j or j==0:
				j=i+1 
				while j<num and arr[j]==2:
					j+=1
			count=j-i
			if j==num:
				dpr[i]=dp[i-1]*(count-1)%1000000007
			elif count%2!=0:
				if j<num-1 and arr[j+1]==2:
					dpr[i]=dp[i-1]*(count+1)%1000000007
				else:
					dpr[i]=dp[i-1]*(count)%1000000007
			elif count%2==0:
				dpr[i]=dp[i-1]*(count-1)%1000000007
		ans+=(dpr[i]+dp[i])%1000000007
	print(ans%1000000007)




			

for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*num
	dp[0]=1
	ans=1
	j=0
	for i in range(1,num):
		j=i+1
		count=1
		dp[i]=dp[i-1]
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]
		ans+=dp[i]%1000000007
		if arr[i-1]==2 and i<num-1:
			if i>=j or j==0:
				j=i+1
			while j<num and arr[j]==2:
			   	j+=1
			count=j-i
			while j<len(arr) and arr[j]==2:
				j+=1
				count+=1
			if j==num:
				ans+=dp[i-1]*(count-1)%1000000007
			elif count%2!=0:
				if j<num-1 and arr[j+1]==2:
					ans+=dp[i-1]*(count+1)%1000000007
				else:
					ans+=dp[i-1]*(count)%1000000007
			elif count%2==0:
				ans+=dp[i-1]*(count-1)%1000000007
	print(ans%1000000007)




for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*num
	dp[0]=1
	ans=1
	for i in range(1,num):
		j=i+1
		count=1
		dp[i]=dp[i-1]
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]
		ans+=dp[i]%1000000007
		if arr[i-1]==2 and i<num-1:
			while j<len(arr) and arr[j]==2:
				j+=1
				count+=1
			if j==num:
				ans+=dp[i-1]*(count-1)%1000000007
			elif count%2!=0:
				if j<num-1 and arr[j+1]==2:
					ans+=dp[i-1]*(count+1)%1000000007
				else:
					ans+=dp[i-1]*(count)%1000000007
			elif count%2==0:
				ans+=dp[i-1]*(count-1)%1000000007
	print(ans%1000000007)




			

for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*num
	dp[0]=1
	ans=1
	for i in range(1,num):
		j=i+1
		count=1
		dp[i]=dp[i-1]
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]
		ans+=dp[i]%1000000007
		if arr[i-1]==2 and i<num-1:
			while j<len(arr) and arr[j]==2:
				j+=1
				count+=1
			if j==num:
				ans+=dp[i-1]*(count-1)%1000000007
			elif count%2!=0:
				if j<num-1 and arr[j+1]==2:
					ans+=dp[i-1]*(count+1)%1000000007
				else:
					ans+=dp[i-1]*(count)%1000000007
			elif count%2==0:
				ans+=dp[i-1]*(count-1)%1000000007
	print(ans)




			

for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*num
	dp[0]=1
	ans=1
	for i in range(1,num):
		j=i+1
		count=1
		dp[i]=dp[i-1]
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]
		ans+=dp[i]%1000000007
		if arr[i-1]==2 and i<num-1:
			while j<len(arr) and arr[j]==2:
				j+=1
				count+=1
			if j==num:
				ans+=dp[i-1]*(count-1)%1000000007
			elif count%2!=0:
				if j<num-1 and arr[j+1]==2:
					ans+=dp[i-1]*(count+1)%1000000007
				else:
					ans+=dp[i-1]*(count)%1000000007
			elif count%2==0:
				ans+=dp[i-1]*(count-1)%1000000007
	print(ans%1000000007)




			

for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*num
	dp[0]=1
	ans=1
	for i in range(1,num):
		j=i+1
		count=1
		dp[i]=dp[i-1]
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]
		ans+=dp[i]
		if arr[i-1]==2 and i<num-1:
			while j<len(arr) and arr[j]==2:
				j+=1
				count+=1
			if j==num:
				ans+=dp[i-1]*(count-1)
			elif count%2!=0:
				if j<num-1 and arr[j+1]==2:
					ans+=dp[i-1]*(count+1)
				else:
					ans+=dp[i-1]*(count)
			elif count%2==0:
				ans+=dp[i-1]*(count-1)
	print(ans)




			

for _ in range(int(input())):
	num=int(input())
	arr=list(map(int,input().split()))
	dp=[0]*len(arr)
	dpr=[0]*len(arr)
	dpt=[0]*len(arr)
	dp[0]=1
	dpr[0]=0
	ans=1
	for i in range(1,len(arr)):
		j=i+1
		count=1
		dp[i]=dp[i-1]
		if i-2>=0 and arr[i-2]==2:
			dp[i]+=dp[i-2]
			if i-3>=0 and arr[i-3]==2:
				dp[i]+=dp[i-3]
		ans+=dp[i]
		if arr[i-1]==2 and i<len(arr)-1:
			while j<len(arr) and arr[j]==2:
				j+=1
				count+=1
			if j==len(arr):
				ans+=dp[i-1]*(count-1)
			elif count%2!=0:
				if j<len(arr)-1 and arr[j+1]==2:
					ans+=dp[i-1]*(count+1)
				else:
					ans+=dp[i-1]*(count)
			elif count%2==0:
				ans+=dp[i-1]*(count-1)
	print(ans)




			

try:
	for _ in range(int(input())):
		num=int(input())
		arr=list(map(int,input().split()))
		dp=[0]*num
		dpr=[0]*num
		dpt=[0]*num
		dp[0]=1
		dpr[0]=0
		ans=1
		for i in range(1,num):
			j=i+1
			count=1
			dp[i]=dp[i-1]
			if i-2>=0 and arr[i-2]==2:
				dp[i]+=dp[i-2]
				if i-3>=0 and arr[i-3]==2:
					dp[i]+=dp[i-3]
			if arr[i-1]==2 and i<num-1:
				while j<num and arr[j]==2:
					j+=1
					count+=1
				if j==num:
					dpr[i]=dp[i-1]*(count-1)
				elif count%2!=0:
					if j<num-1 and arr[j+1]==2:
						dpr[i]=dp[i-1]*(count+1)
					else:
						dpr[i]=dp[i-1]*(count)
				elif count%2==0:
					dpr[i]=dp[i-1]*(count-1)
			ans+=dpr[i]+dp[i]
		print(ans)
except:
	pass



			

# cook your dish here
import sys
sys.setrecursionlimit(10**8)
try:
    for _ in range(int(input())):
        class mat(object):
            limit=[]
            arr=[]
            num=0
            ans=0
        def passes(n,m):
            if m>mat.num:
                return
            mat.ans+=1
            mat.limit.append(m)
            for i in range(1,mat.arr[m]+1):
                if m-i>0 and n<mat.num-1 and not(m-i in mat.limit) :
                    passes(n+1,m-i)
                if m+i<mat.num  and n<mat.num-1 and not(m+i in mat.limit):
                    passes(n+1,m+i)
            mat.limit.pop()
        mat.num=int(input())
        mat.arr=[]*mat.num
        mat.arr=list(map(int,input().split()))
        passes(0,0)
        print(mat.ans)
        
except:
    pass

# cook your dish here
try:
    for _ in range(int(input())):
        class mat(object):
            game=[]
            limit=[]
            arr=[]
            num=0
            ans=0
        def passes(n,m):
            if m>mat.num:
                return
            mat.ans+=1
            mat.limit.append(m)
            for i in range(1,mat.arr[m]+1):
                if m-i>0 and n<mat.num-1 and not(m-i in mat.limit) :
                    passes(n+1,m-i)
                if m+i<mat.num  and n<mat.num-1 and not(m+i in mat.limit):
                    passes(n+1,m+i)
            mat.limit.pop()
        mat.num=int(input())
        mat.arr=[]*mat.num
        mat.arr=list(map(int,input().split()))
        passes(0,0)
        print(mat.ans)
        
except:
    pass

# cook your dish here
try:
    for _ in range(int(input())):
        class mat(object):
        	game=[]
        	limit=[]
        def see(key):
        	for i in range(len(mat.limit)-1,-1,-1):
        		if mat.limit[i]==key:
        			return False
        	return True
        def passes(n,m,arr):
        	if m>len(arr) or n>len(arr):
        		return
        	mat.game[n][m]+=1
        	mat.limit.append(m)
        	for i in range(1,arr[m]+1):
        		if m-i>0 and n<len(arr)-1 and not(m-i in mat.limit) :
        			passes(n+1,m-i,arr)
        		if m+i<len(arr)  and n<len(arr)-1 and not(m+i in mat.limit):
        			passes(n+1,m+i,arr)
        	mat.limit.pop()
        n=int(input())
        arr=list(map(int,input().split()))
        mat.game=[[0]*(len(arr)) for _ in range(len(arr))]
        passes(0,0,arr)
        ans=0
        for i in mat.game:
        	ans+=sum(i)
        print(ans)
        
except:
    pass

for _ in range(int(input())):
    n=int(input())
    p=[int(o) for o in input().split()]
    s=[0]*n
    pr=[0]*n
    s[n-1]=1
    pr[n-1]=0
    if n-2>=0:
        s[n-2]=2
        pr[n-2]=1
    if n-3>=0:
        s[n-3]=3
        pr[n-3]=1
        if p[n-3]==2:
            s[n-3]+=2
            pr[n-3]+=1
    i=n-4
    while i>=0:
        s[i]=1
        s[i]+=s[i+1]
        pr[i]=1
        if p[i]==2:
            s[i]+=s[i+2]
            s[i]+=1
            pr[i]+=1
            if p[i+3]==2:
                s[i]+=pr[i+2]
                pr[i]+=pr[i+2]
            if p[i+1]==2:
                s[i]+=s[i+3]
        s[i]=s[i]%1000000007
        pr[i]=pr[i]%1000000007
        i-=1
    print(s[0])

import math;
from math import log2,sqrt;
import sys;
sys.setrecursionlimit(pow(10,6))
import collections
from collections import defaultdict
from statistics import median
inf = float("inf")
mod=pow(10,9)+7
def give(l,n,index,visited):
    if index<0 or index>=n:
        return 0;
    if visited[index]==1:
        return 0;
    visited[index]=1;
    theta=1
    # print("index is",index)
    for i in graph[index]:
        theta+=give(l,n,i,visited.copy())

    return theta;

for i in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    visited=defaultdict(int)
    graph=defaultdict(set)
    for i in range(len(l)):
        if l[i]==1:
            graph[i].add(i-1)
            graph[i].add(i+1)
        else:
            graph[i].add(i-2)
            graph[i].add(i-1)
            graph[i].add(i+1)
            graph[i].add(i+2)
    theta=give(l,n,0,visited.copy())

    print(theta)





# cook your dish here
# cook your dish here
def array1(size):
    return [0 for _ in range(size)]


def array2(rows, cols):
    return [[0 for _ in range(cols)] for _ in range(rows)]


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    no_of_twos = array1(n + 1)
    for i in range(n - 1, -1, -1):
        if a[i] == 1:
            no_of_twos[i] = 0
        else:
            no_of_twos[i] += 1
            no_of_twos[i] += no_of_twos[i + 1]
    dp = array1(n + 1)
    dp[0] = 1
    ans = 1
    for i in range(1, n):
        if i - 1 >= 0:
            dp[i] += dp[i - 1]
        if i - 2 >= 0 and a[i - 2] == 2:
            dp[i] += dp[i - 2]
        if i - 3 >= 0 and a[i - 3] == 2 and a[i - 2] == 2:
            dp[i] += dp[i - 3]
        dp[i] = dp[i] % 1000000007
        ans += dp[i]
        x = no_of_twos[i + 1]
        if i + 1 < n and a[i - 1] == 2:
            ans += (x * dp[i - 1])
            if x % 2 == 0:
                if i + x + 1 < n:
                    ans += dp[i - 1]
                if i + x + 2 < n and a[i + x + 2] == 2:
                    ans += dp[i - 1]
        ans = ans % 1000000007
    print(ans % 1000000007)


# cook your dish here
def array1(size):
    return [0 for _ in range(size)]


def array2(rows, cols):
    return [[0 for _ in range(cols)] for _ in range(rows)]


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    no_of_twos = array1(n + 1)
    for i in range(n - 1, -1, -1):
        if a[i] == 1:
            no_of_twos[i] = 0
        else:
            no_of_twos[i] += 1
            no_of_twos[i] += no_of_twos[i + 1]
    dp = array1(n + 1)
    dp[0] = 1
    ans = 1
    for i in range(1, n):
        if i - 1 >= 0:
            dp[i] += dp[i - 1]
        if i - 2 >= 0 and a[i - 2] == 2:
            dp[i] += dp[i - 2]
        if i - 3 >= 0 and a[i - 3] == 2 and a[i - 2] == 2:
            dp[i] += dp[i - 3]
        dp[i] = dp[i] % 1000000007
        ans += dp[i]
        x = no_of_twos[i + 1]
        if i + 1 < n and a[i - 1] == 2:
            ans += (x * dp[i - 1])
            if x % 2 == 0:
                if i + x + 1 < n:
                    ans += dp[i - 1]
                if i + x + 2 < n and a[i + x + 2] == 2:
                    ans += dp[i - 1]
        ans = ans % 1000000007
    print(ans % 1000000007)


def array1(size):
    return [0 for _ in range(size)]


def array2(rows, cols):
    return [[0 for _ in range(cols)] for _ in range(rows)]


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    no_of_twos = array1(n + 1)
    for i in range(n - 1, -1, -1):
        if a[i] == 1:
            no_of_twos[i] = 0
        else:
            no_of_twos[i] += 1
            no_of_twos[i] += no_of_twos[i + 1]
    dp = array1(n + 1)
    dp[0] = 1
    ans = 1
    for i in range(1, n):
        if i - 1 >= 0:
            dp[i] += dp[i - 1]
        if i - 2 >= 0 and a[i - 2] == 2:
            dp[i] += dp[i - 2]
        if i - 3 >= 0 and a[i - 3] == 2 and a[i - 2] == 2:
            dp[i] += dp[i - 3]
        dp[i] = dp[i] % 1000000007
        ans += dp[i]
        x = no_of_twos[i + 1]
        if i + 1 < n and a[i - 1] == 2:
            ans += (x * dp[i - 1])
            if x % 2 == 0:
                if i + x + 1 < n:
                    ans += dp[i - 1]
                if i + x + 2 < n and a[i + x + 2] == 2:
                    ans += dp[i - 1]
        ans = ans % 1000000007
    print(ans % 1000000007)


for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    dp=[0]*(n+3)
    dp[0]=1
    for i in range(1,n):
        dp[i]=dp[i-1]
        if i-2>=0 and a[i-2]==2:dp[i]+=dp[i-2]
        if i-3>=0 and a[i-3]==2 and a[i-2]==2:dp[i]+=dp[i-3]
    dpr=[0]*(n+3)
    i1=[0]*n
    i2=-1
    for i in range(n-1,-1,-1):
        i1[i]=i2
        if a[i]==1:i2=i
    for i in range(1,n-1):
        if a[i-1]==1:continue
        if i1[i]==-1:
            i2=n-i-1
            if i2%2:z=2*(i2//2)+1
            else:z=i2
        else:
            i2=i1[i]-i-1
            if not i2%2:
                z=i2+1
                if i1[i]+1 <n and a[i1[i]+1]==2:z+=1
            else:z=2*(i2//2)+1
        dpr[i]=z*dp[i-1]
    c=0
    for i in range(n):c+=dp[i]+dpr[i]
    x=7+pow(10,9)
    print(c%x)

# cook your dish here
def f(x,ud,li):
    if not ud:return 1
    m=1
    if x+1 in ud:
        ud1=ud[:]
        ud.remove(x+1)
        m+=f(x+1,ud,li)
        ud=ud1[:]
    if x-1 in ud:
        ud1=ud[:]
        ud.remove(x-1)
        m+=f(x-1,ud,li)
        ud=ud1[:]
    if li[x]==2:
        if x+2 in ud:
            ud1=ud[:]
            ud.remove(x+2)
            m+=f(x+2,ud,li)
            ud=ud1[:]
        if x-2 in ud:
            ud1=ud[:]
            ud.remove(x-2)
            m+=f(x-2,ud,li)
            ud=ud1[:]
    return m
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    ud=[]
    for i in range(1,n):ud.append(i)
    c=f(0,ud,a)
    x=7+pow(10,9)
    print(c%x)

for _ in range(int(input())):
    n=int(input())
    p=[int(o) for o in input().split()]
    s=[0]*n
    pr=[0]*n
    s[n-1]=1
    pr[n-1]=0
    if n-2>=0:
        s[n-2]=2
        pr[n-2]=1
    if n-3>=0:
        s[n-3]=3
        pr[n-3]=1
        if p[n-3]==2:
            s[n-3]+=2
            pr[n-3]+=1
    i=n-4
    while i>=0:
        s[i]=1
        s[i]+=s[i+1]
        pr[i]=1
        if p[i]==2:
            s[i]+=s[i+2]
            s[i]+=1
            pr[i]+=1
            if p[i+3]==2:
                s[i]+=pr[i+2]
                pr[i]+=pr[i+2]
            if p[i+1]==2:
                s[i]+=s[i+3]
        s[i]=s[i]%1000000007
        pr[i]=pr[i]%1000000007
        i-=1
    print(s[0])

for _ in range(int(input())):
    n=int(input())
    p=[int(o) for o in input().split()]
    s=[0]*n
    pr=[0]*n
    s[n-1]=1
    pr[n-1]=0
    if n-2>=0:
        s[n-2]=2
        pr[n-2]=1
    if n-3>=0:
        s[n-3]=3
        pr[n-3]=1
        if p[n-3]==2:
            s[n-3]+=2
            pr[n-3]+=1
    i=n-4
    while i>=0:
        s[i]=1
        s[i]+=s[i+1]
        pr[i]=1
        if p[i]==2:
            s[i]+=s[i+2]
            s[i]+=1
            pr[i]+=1
            if p[i+3]==2:
                s[i]+=pr[i+2]
                pr[i]+=pr[i+2]
            if p[i+1]==2:
                s[i]+=s[i+3]
        s[i]=s[i]%1000000007
        pr[i]=pr[i]%1000000007
        i-=1
    print(s[0])

for _ in range(int(input())):
    n=int(input())
    p=[int(o) for o in input().split()]
    s=[0]*n
    pr=[0]*n
    s[n-1]=1
    pr[n-1]=0
    if n-2>=0:
        s[n-2]=2
        pr[n-2]=1
    if n-3>=0:
        s[n-3]=3
        pr[n-3]=1
        if p[n-3]==2:
            s[n-3]+=2
            pr[n-3]+=1
    i=n-4
    while i>=0:
        s[i]=1
        s[i]+=s[i+1]
        pr[i]=1
        if p[i]==2:
            s[i]+=s[i+2]
            s[i]+=1
            pr[i]+=1
            if p[i+3]==2:
                s[i]+=pr[i+2]
                pr[i]+=pr[i+2]
            if p[i+1]==2:
                s[i]+=s[i+3]
        s[i]=s[i]%1000000007
        pr[i]=pr[i]%1000000007
        i-=1
    print(s[0])