mod = 10**9+7
L = input()
l = len(L)
DP = [[0,0] for _ in range(l)] #上から決めていく、0は一致、1は小さいことが確定
DP[0][0] = 2
DP[0][1] = 1
for i in range(1,l):
    if L[i] == '0':
        DP[i][0] = DP[i-1][0]
        DP[i][1] = DP[i-1][1]*3 % mod
    else:
        DP[i][0] = DP[i-1][0]*2 % mod
        DP[i][1] = (DP[i-1][0]+DP[i-1][1]*3) % mod
print((DP[l-1][0]+DP[l-1][1]) % mod) mod = 10**9+7 mod 10**9+7 10**9 10 9 7 L = input() L input() input l = len(L) l len(L) len L [0,0] for _ in range(l) for _ in range(l) _ range(l) range l for _ in range(l) [0,0] 0 0 DP = [[0,0] for _ in range(l)] DP [[0,0] for _ in range(l)] DP[0][0] = 2 DP[0][0] [0] DP 0 0 2 DP[0][1] = 1 DP[0][1] [0] DP 0 1 1 for i in range(1,l):
    if L[i] == '0':
        DP[i][0] = DP[i-1][0]
        DP[i][1] = DP[i-1][1]*3 % mod
    else:
        DP[i][0] = DP[i-1][0]*2 % mod
        DP[i][1] = (DP[i-1][0]+DP[i-1][1]*3) % mod i range(1,l) range 1 l if L[i] == '0':
        DP[i][0] = DP[i-1][0]
        DP[i][1] = DP[i-1][1]*3 % mod
    else:
        DP[i][0] = DP[i-1][0]*2 % mod
        DP[i][1] = (DP[i-1][0]+DP[i-1][1]*3) % mod L[i] == '0' L[i] L i '0' DP[i][0] = DP[i-1][0] DP[i][0] [i] DP i 0 DP[i-1][0] [i-1] DP i-1 i 1 0 DP[i][1] = DP[i-1][1]*3 % mod DP[i][1] [i] DP i 1 DP[i-1][1]*3 % mod DP[i-1][1]*3 DP[i-1][1] [i-1] DP i-1 i 1 1 3 mod DP[i][0] = DP[i-1][0]*2 % mod DP[i][0] [i] DP i 0 DP[i-1][0]*2 % mod DP[i-1][0]*2 DP[i-1][0] [i-1] DP i-1 i 1 0 2 mod DP[i][1] = (DP[i-1][0]+DP[i-1][1]*3) % mod DP[i][1] [i] DP i 1 (DP[i-1][0]+DP[i-1][1]*3) % mod DP[i-1][0]+DP[i-1][1]*3 DP[i-1][0] [i-1] DP i-1 i 1 0 DP[i-1][1]*3 DP[i-1][1] [i-1] DP i-1 i 1 1 3 mod print((DP[l-1][0]+DP[l-1][1]) % mod) print (DP[l-1][0]+DP[l-1][1]) % mod DP[l-1][0]+DP[l-1][1] DP[l-1][0] [l-1] DP l-1 l 1 0 DP[l-1][1] [l-1] DP l-1 l 1 1 mod DP = [[0,0] for _ in range(l)] [[0,0] for _ in range(l)] DP mod = 10**9+7 10**9+7 mod L = input() input() L l = len(L) len(L) l
mod = 10**9+7
L = input()
l = len(L)
DP = [[0,0] for _ in range(l)] #上から決めていく、0は一致、1は小さいことが確定
DP[0][0] = 2
DP[0][1] = 1
for i in range(1,l):
    if L[i] == '0':
        DP[i][0] = DP[i-1][0]
        DP[i][1] = DP[i-1][1]*3 % mod
    else:
        DP[i][0] = DP[i-1][0]*2 % mod
        DP[i][1] = (DP[i-1][0]+DP[i-1][1]*3) % mod
print((DP[l-1][0]+DP[l-1][1]) % mod)