Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
from functools import lru_cache
L = int(input(),2)
MOD = 10**9+7
@lru_cache(None)
def f(n):
  if n==1:
    return 3
  elif n==0:
    return 1
  a = n>>1
  if n%2==1:
    return (f(a)*3)%MOD
  return (f(a)+f(a-1)*2)%MOD
print(f(L))

Fixed submission:
L = input()
MOD = 10**9+7

pow_3=[1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)
  
pow_2=[1]
for _ in range(2*10**5):
  pow_2.append((pow_2[-1]*2)%MOD)
  
count = L.count('1')
ans = pow_2[count]

for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_3[len(L)-i-1]*pow_2[count]
    ans += m
    ans %= MOD
print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
L = int(input(),2)
MOD = 10**9+7
@lru_cache(None)
def f(n):
  if n==1:
    return 3
  elif n==0:
    return 1
  a = n>>1
  if n%2==1:
    return (f(a)*3)%MOD
  return (f(a)+f(a-1)*2)%MOD

print(f(L))

Fixed submission:
L = input()
MOD = 10**9+7

pow_3=[1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)
  
pow_2=[1]
for _ in range(2*10**5):
  pow_2.append((pow_2[-1]*2)%MOD)
  
count = L.count('1')
ans = pow_2[count]

for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_3[len(L)-i-1]*pow_2[count]
    ans += m
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L = input()
INF = 10**9+7
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
count = L.count('1')
ans = pow_k(2,count)
for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_k(3,len(L)-i-1)*pow_k(2,count)
    ans += m
    ans %= INF
print(ans)

Fixed submission:
L = input()
MOD = 10**9+7

pow_3=[1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)
  
pow_2=[1]
for _ in range(2*10**5):
  pow_2.append((pow_2[-1]*2)%MOD)
  
count = L.count('1')
ans = pow_2[count]

for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_3[len(L)-i-1]*pow_2[count]
    ans += m
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L = input()
INF = 10**9+7

count = L.count('1')
ans = 2**count
for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = 3**(len(L)-i-1)*(2**count)
    ans += m
    ans %= INF
print(ans)

Fixed submission:
L = input()
MOD = 10**9+7

pow_3=[1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)
  
pow_2=[1]
for _ in range(2*10**5):
  pow_2.append((pow_2[-1]*2)%MOD)
  
count = L.count('1')
ans = pow_2[count]

for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_3[len(L)-i-1]*pow_2[count]
    ans += m
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L = input()
INF = 10**9+7

count = L.count('1')
ans = 2**count
for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = 3**(len(L)-i-1)*(2**count)
    ans += m
    ans %= INF
print(ans)


Fixed submission:
L = input()
MOD = 10**9+7

pow_3=[1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)
  
pow_2=[1]
for _ in range(2*10**5):
  pow_2.append((pow_2[-1]*2)%MOD)
  
count = L.count('1')
ans = pow_2[count]

for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_3[len(L)-i-1]*pow_2[count]
    ans += m
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L = input()
INF = 10**9+7

count = L.count('1')
ans = 2**count
for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = 3**(len(L)-i-1)*(2**count)
    ans += m
    ans %= INF
print(ans)

Fixed submission:
L = input()
MOD = 10**9+7

pow_3=[1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)
  
pow_2=[1]
for _ in range(2*10**5):
  pow_2.append((pow_2[-1]*2)%MOD)
  
count = L.count('1')
ans = pow_2[count]

for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_3[len(L)-i-1]*pow_2[count]
    ans += m
    ans %= MOD
print(ans)