Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    l = input()
    li = [int(l[i]) for i in range(len(l))]
    dprint(li)

    # 制約1 a+b は L 以下
    # 制約2 a と b で同じけたは 00 01 10 のいずれか

    mx = 10**9 + 7
    def next_digit_pat(subli, flag):
        ans = -1
        if len(subli) == 1:
            if subli[0] == 1:
                ans = 3
            else:
                if flag:
                    ans = 1
                else:
                    ans = 3
        else:
            if subli[0] == 1:
                ans = 1 * next_digit_pat(subli[1:], False) + 2 * next_digit_pat(subli[1:], True)
            else:
                ans = next_digit_pat(subli[1:], True)

        #dprint(subli, flag, ans)

        return ans % mx
    print(next_digit_pat(li, True))

solve()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    l = input().rstrip('\n')
    n = len(l)
    # 制約1 a+b は L 以下
    # 制約2 a と b で同じけたは 00 01 10 のいずれか

    mx = 10**9 + 7
    same = 1 # iまでの a+b が l と等しい（a+b <= L となるかは次の桁で気をつける必要あり）
    diff = 0 # iまでの a+b が l と異なっている（すでに a+b <= L が確定）

    for i in range(n):
        if l[i] == "1":
            same_tmp = same * 2
            diff_tmp = same * 1 + diff * 3
        else:
            same_tmp = same * 1
            # diff_tmp = same * 2 + diff * 3 ×sameで次の桁が0の場合、次の桁を1にはできない
            diff_tmp = diff * 3
        same = same_tmp % mx
        diff = diff_tmp % mx

        dprint(i, l[i], same, diff)

    print((same + diff) % mx)

solve()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    l = input()
    li = [int(l[i]) for i in range(len(l))]
    dprint(li)

    # 制約1 a+b は L 以下
    # 制約2 a と b で同じけたは 00 01 10 のいずれか

    mx = 10**9 + 7
    def next_digit_pat(subli, flag):
        ans = -1
        if len(subli) == 1:
            if subli[0] == 1:
                ans = 3
            else:
                if flag:
                    ans = 1
                else:
                    ans = 3
        else:
            if subli[0] == 1:
                ans = 1 * next_digit_pat(subli[1:], False) + 2 * next_digit_pat(subli[1:], True)
            else:
                ans = next_digit_pat(subli[1:], True)

        #dprint(subli, flag, ans)

        return ans
    print(next_digit_pat(li, True) % mx)

solve()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    l = input().rstrip('\n')
    n = len(l)
    # 制約1 a+b は L 以下
    # 制約2 a と b で同じけたは 00 01 10 のいずれか

    mx = 10**9 + 7
    same = 1 # iまでの a+b が l と等しい（a+b <= L となるかは次の桁で気をつける必要あり）
    diff = 0 # iまでの a+b が l と異なっている（すでに a+b <= L が確定）

    for i in range(n):
        if l[i] == "1":
            same_tmp = same * 2
            diff_tmp = same * 1 + diff * 3
        else:
            same_tmp = same * 1
            # diff_tmp = same * 2 + diff * 3 ×sameで次の桁が0の場合、次の桁を1にはできない
            diff_tmp = diff * 3
        same = same_tmp % mx
        diff = diff_tmp % mx

        dprint(i, l[i], same, diff)

    print((same + diff) % mx)

solve()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    l = input()
    li = [int(l[i]) for i in range(len(l))]
    dprint(li)

    # 制約1 a+b は L 以下
    # 制約2 a と b で同じけたは 00 01 10 のいずれか

    mx = 10**9 + 7
    def next_digit_pat(subli, flag):
        ans = -1
        if len(subli) == 1:
            if subli[0] == 1:
                ans = 3
            else:
                if flag:
                    ans = 1
                else:
                    ans = 3
        else:
            if subli[0] == 1:
                ans = 1 * next_digit_pat(subli[1:], False) + 2 * next_digit_pat(subli[1:], True)
            else:
                ans = next_digit_pat(subli[1:], True)

        #dprint(subli, flag, ans)

        return ans
    print(next_digit_pat(li, True) % mx)

solve()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    l = input().rstrip('\n')
    n = len(l)
    # 制約1 a+b は L 以下
    # 制約2 a と b で同じけたは 00 01 10 のいずれか

    mx = 10**9 + 7
    same = 1 # iまでの a+b が l と等しい（a+b <= L となるかは次の桁で気をつける必要あり）
    diff = 0 # iまでの a+b が l と異なっている（すでに a+b <= L が確定）

    for i in range(n):
        if l[i] == "1":
            same_tmp = same * 2
            diff_tmp = same * 1 + diff * 3
        else:
            same_tmp = same * 1
            # diff_tmp = same * 2 + diff * 3 ×sameで次の桁が0の場合、次の桁を1にはできない
            diff_tmp = diff * 3
        same = same_tmp % mx
        diff = diff_tmp % mx

        dprint(i, l[i], same, diff)

    print((same + diff) % mx)

solve()