Problem p03488 (python)

Fixed submission:
#!/usr/bin/env python3


def reachable(start, target, lst):

    current = set()
    current.add(start)

    for moves in lst:
        candidates = set()
        for x in current:
            candidates.add(x + moves)
            candidates.add(x - moves)
        current = candidates

    return target in current


def main():
    s = input()
    sa = input().split(' ')
    x = int(sa[0])
    y = int(sa[1])

    x_list = []
    y_list = []
    moves = 0
    move_x = True
    lst = x_list
    for cmd in s:
        if cmd == 'F':
            moves += 1
        else:
            # cmd == 'T'
            if moves != 0:
                lst.append(moves)
            moves = 0
            move_x = not move_x
            lst = x_list if move_x else y_list
    if moves != 0:
        lst.append(moves)

    if s[0] == 'F':
        x -= x_list[0]
        x_list = x_list[1:]

    if reachable(0, x, x_list) and reachable(0, y, y_list):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

dp0 = [False for i in range(16000)]
dp1 = [False for i in range(16000)]


def reachable(start, target, lst, S):

    global dp0, dp1

    for i in range(S):
        dp1[i] = False
    dp1[target] = True

    for moves in lst[::-1]:
        for i in range(S):
            dp0[i] = False
        for i in range(S):
            if dp1[i]:
                dp0[i + moves] = True
                dp0[i - moves] = True
        dp0, dp1 = dp1, dp0

    return dp1[start]

def main():
    s = input()
    sa = input().split(' ')
    x = int(sa[0])
    y = int(sa[1])

    x_list = []
    y_list = []
    moves = 0
    move_x = True
    lst = x_list
    for cmd in s:
        if cmd == 'F':
            moves += 1
        else:
            if moves != 0:
                lst.append(moves)
            moves = 0
            move_x = not move_x
            lst = x_list if move_x else y_list
    if moves != 0:
        lst.append(moves)

    if 0 < len(x_list):
        x -= x_list[0]
        x_list = x_list[1:]

    len_s = len(s)
    if reachable(len_s, len_s + x, x_list, len_s * 2) and reachable(len_s, len_s + y, y_list, len_s * 2):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def reachable(start, target, lst, S):

    dp0 = [False for i in range(S)]
    dp1 = [False for i in range(S)]

    dp1[target] = True

    for moves in lst[::-1]:
        for i in range(S):
            dp0[i] = False
        for i in range(S):
            if dp1[i]:
                dp0[i + moves] = True
                dp0[i - moves] = True
        dp0, dp1 = dp1, dp0

    return dp1[start]

def main():
    s = input()
    sa = input().split(' ')
    x = int(sa[0])
    y = int(sa[1])

    x_list = []
    y_list = []
    moves = 0
    move_x = True
    lst = x_list
    for cmd in s:
        if cmd == 'F':
            moves += 1
        else:
            if moves != 0:
                lst.append(moves)
            moves = 0
            move_x = not move_x
            lst = x_list if move_x else y_list
    if moves != 0:
        lst.append(moves)

    if 0 < len(x_list):
        x -= x_list[0]
        x_list = x_list[1:]

    len_s = len(s)
    if reachable(len_s, len_s + x, x_list, len_s * 2) and reachable(len_s, len_s + y, y_list, len_s * 2):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()