Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = _s()
ans = 3**(len(L) - 1) % MOD

sumL = L.count('1')
ans = (ans + 2**(sumL) % MOD) % MOD
count = 0
for i, j in enumerate(L[::-1][:-1]):
    if j == '1':
        count += 1
        ans = (ans + 2 * (2**(sumL-count-1)) % MOD * (3**i) % MOD) % MOD

print(int(ans))


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = _s()

ans = 3**(len(L) - 1) % MOD
# for i in range(1, len(L)):
#     ans = (ans + 2**(2*i-1)) % MOD

sumL = L.count('1')
ans = (ans + 2**(sumL) % MOD) % MOD

count = 0
for i in range(len(L)-1):
    if L[-1-i] == '1':
        count += 1
        ans = (ans + 2 * pow(2, sumL-count-1, MOD) * pow(3, i, MOD)) % MOD

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = _s()
ans = 3**(len(L) - 1)
# for i in range(1, len(L)):
#     ans = (ans + 2**(2*i-1)) % MOD

sumL = L.count('1')
ans = (ans + 2**(sumL)) % MOD
count = 0
for i, j in enumerate(L[::-1][:-1]):
    if j == '1':
        count += 1
        ans = (ans + 2 * (2**(sumL-count-1)) % MOD * (3**i) % MOD) % MOD

print(int(ans))


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = _s()

ans = 3**(len(L) - 1) % MOD
# for i in range(1, len(L)):
#     ans = (ans + 2**(2*i-1)) % MOD

sumL = L.count('1')
ans = (ans + 2**(sumL) % MOD) % MOD

count = 0
for i in range(len(L)-1):
    if L[-1-i] == '1':
        count += 1
        ans = (ans + 2 * pow(2, sumL-count-1, MOD) * pow(3, i, MOD)) % MOD

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = list(map(int, list(_s())))
ans = 3**(len(L) - 1)
# for i in range(1, len(L)):
#     ans = (ans + 2**(2*i-1)) % MOD

sumL = sum(L)
ans = (ans + 2**(sumL)) % MOD
count = 0
for i, j in enumerate(L[::-1][:-1]):
    if j == 1:
        count += 1
        ans = (ans + 2 * (2**(sumL-count-1)) % MOD * (3**i) % MOD) % MOD

print(int(ans))


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = _s()

ans = 3**(len(L) - 1) % MOD
# for i in range(1, len(L)):
#     ans = (ans + 2**(2*i-1)) % MOD

sumL = L.count('1')
ans = (ans + 2**(sumL) % MOD) % MOD

count = 0
for i in range(len(L)-1):
    if L[-1-i] == '1':
        count += 1
        ans = (ans + 2 * pow(2, sumL-count-1, MOD) * pow(3, i, MOD)) % MOD

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = list(map(int, list(_s())))
ans = 3**(len(L) - 1)
# for i in range(1, len(L)):
#     ans = (ans + 2**(2*i-1)) % MOD

sumL = sum(L)
ans = (ans + 2**(sumL)) % MOD
count = 0
for i, j in enumerate(L[::-1][:-1]):
    if j == 1:
        count += 1
        ans = (ans + 2 * 2**(sumL-count-1) * 3**i) % MOD

print(int(ans))


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9 + 7
L = _s()

ans = 3**(len(L) - 1) % MOD
# for i in range(1, len(L)):
#     ans = (ans + 2**(2*i-1)) % MOD

sumL = L.count('1')
ans = (ans + 2**(sumL) % MOD) % MOD

count = 0
for i in range(len(L)-1):
    if L[-1-i] == '1':
        count += 1
        ans = (ans + 2 * pow(2, sumL-count-1, MOD) * pow(3, i, MOD)) % MOD

print(int(ans))