Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

L = str(input())
L_list = [0 for i in range(len(L))]
for i in range(len(L)):
    L_list[i] = int(L[i])
n = len(L)
num = 0
L_list.reverse()
for i in range(n):
    num += L_list[i]*2**i


def count2digit(num):
    cnt = 0
    while num > 0:
        if num % 2 == 1:
            cnt +=1
        num //= 2
    return cnt


ans = 3**(n-1) % mod
for i in range(2**(n-1),num+1):
    ans += 2**count2digit(i) % mod
    ans = ans % mod

print(ans)


Fixed submission:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

L = str(input())
n = len(L)
dp = [[0,0] for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if L[i] == "0": #a+b = 0
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
    else:
        dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod

    if L[i] == "0":
        dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod
    else:
        dp[i+1][0] = (dp[i+1][0] + dp[i][0]*2) % mod
        dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod


print(sum(dp[n]) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

L = str(input())
L_list = [0 for i in range(len(L))]
for i in range(len(L)):
    L_list[i] = int(L[i])
n = len(L)
num = 0
L_list.reverse()
for i in range(n):
    num += L_list[i]*2**i


def count2digit(num):
    cnt = 0
    while num > 0:
        if num % 2 == 1:
            cnt +=1
        num //= 2
    return cnt


ans = 3**(n-1) % mod
for i in range(2**(n-1),num+1):
    ans += 2**count2digit(i) % mod
    ans = ans % mod

print(ans)


Fixed submission:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

L = str(input())
n = len(L)
dp = [[0,0] for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if L[i] == "0": #a+b = 0
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
    else:
        dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod

    if L[i] == "0":
        dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod
    else:
        dp[i+1][0] = (dp[i+1][0] + dp[i][0]*2) % mod
        dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod


print(sum(dp[n]) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

L = str(input())
L_list = [0 for i in range(len(L))]
for i in range(len(L)):
    L_list[i] = int(L[i])
n = len(L)
num = 0
L_list.reverse()
for i in range(n):
    num += L_list[i]*2**i


def count2digit(num):
    cnt = 0
    while num > 0:
        if num % 2 == 1:
            cnt +=1
        num //= 2
    return cnt

ans = 1 # (0,0)
for i in range(1,num+1):
    ans += 2**count2digit(i) % mod
    ans = ans % mod

print(ans)


Fixed submission:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

L = str(input())
n = len(L)
dp = [[0,0] for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if L[i] == "0": #a+b = 0
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
    else:
        dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod

    if L[i] == "0":
        dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod
    else:
        dp[i+1][0] = (dp[i+1][0] + dp[i][0]*2) % mod
        dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod


print(sum(dp[n]) % mod)