from functools import lru_cache

MOD = 10 ** 9 + 7

s = input()
s = s[::-1]
dp0 = [0] * len(s)
dp1 = [0] * len(s)  # smaller
if s[0] == "0":
    dp1[0] = 1
else:
    dp1[0] = 3
dp0[0] = 3

for i in range(1, len(s)):
    if s[i] == "1":
        dp1[i] = dp0[i-1] + dp1[i-1] * 2
    else:
        dp1[i] = dp1[i-1]
    dp0[i] = dp0[i-1] * 3

    dp0[i] %= MOD
    dp1[i] %= MOD

print(dp1[-1]) from functools import lru_cache MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 s = input() s input() input s = s[::-1] s s[::-1] s ::-1 -1 dp0 = [0] * len(s) dp0 [0] * len(s) [0] 0 len(s) len s dp1 = [0] * len(s) dp1 [0] * len(s) [0] 0 len(s) len s if s[0] == "0":
    dp1[0] = 1
else:
    dp1[0] = 3 s[0] == "0" s[0] s 0 "0" dp1[0] = 1 dp1[0] dp1 0 1 dp1[0] = 3 dp1[0] dp1 0 3 dp0[0] = 3 dp0[0] dp0 0 3 for i in range(1, len(s)):
    if s[i] == "1":
        dp1[i] = dp0[i-1] + dp1[i-1] * 2
    else:
        dp1[i] = dp1[i-1]
    dp0[i] = dp0[i-1] * 3

    dp0[i] %= MOD
    dp1[i] %= MOD i range(1, len(s)) range 1 len(s) len s if s[i] == "1":
        dp1[i] = dp0[i-1] + dp1[i-1] * 2
    else:
        dp1[i] = dp1[i-1]
     s[i] == "1" s[i] s i "1" dp1[i] = dp0[i-1] + dp1[i-1] * 2 dp1[i] dp1 i dp0[i-1] + dp1[i-1] * 2 dp0[i-1] dp0 i-1 i 1 dp1[i-1] * 2 dp1[i-1] dp1 i-1 i 1 2 dp1[i] = dp1[i-1] dp1[i] dp1 i dp1[i-1] dp1 i-1 i 1 dp0[i] = dp0[i-1] * 3 dp0[i] dp0 i dp0[i-1] * 3 dp0[i-1] dp0 i-1 i 1 3 dp0[i] %= MOD dp0[i] dp0 i MOD dp1[i] %= MOD dp1[i] dp1 i MOD print(dp1[-1]) print dp1[-1] dp1 -1 s = s[::-1] s[::-1] s dp0 = [0] * len(s) [0] * len(s) dp0 s = input() input() s dp1 = [0] * len(s) [0] * len(s) dp1 MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD
from functools import lru_cache

MOD = 10 ** 9 + 7

s = input()
s = s[::-1]
dp0 = [0] * len(s)
dp1 = [0] * len(s)  # smaller
if s[0] == "0":
    dp1[0] = 1
else:
    dp1[0] = 3
dp0[0] = 3

for i in range(1, len(s)):
    if s[i] == "1":
        dp1[i] = dp0[i-1] + dp1[i-1] * 2
    else:
        dp1[i] = dp1[i-1]
    dp0[i] = dp0[i-1] * 3

    dp0[i] %= MOD
    dp1[i] %= MOD

print(dp1[-1])
