Problem p03488 (python)

Fixed submission:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
XY=[set([0]), set([0])]
    
for bit in range(2):
    for i in range(len(F[bit])):
        temp=set([])
        a=F[bit][i]
        b=-a
        if bit==0 and i==0 and s[0]=="F":
            b=a
        for j in range(len(XY[bit])):
            aaa=XY[bit].pop()
            temp.add(aaa+a)
            temp.add(aaa+b)
        XY[bit]=temp
        
if (x in XY[0] ) and (y in XY[1] ):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def main():
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))

    s=input()+"T"

    N=len(s)
    x,y=MI()

    F=[[],[]]

    temp=0
    bit=0
    for i in range(N):
        if s[i]=="F":
            temp+=1
        else:
            if temp!=0:
                F[bit].append(temp)
            bit=(bit+1)%2
            temp=0

    Nx=len(F[0])
    Ny=len(F[1])


    #i番目の文字で，位置x [-N~N]につけるかどうか
    dpx=[[False]*(2*N+3) for _ in range(2)]
    dpy=[[False]*(2*N+3) for _ in range(2)]

    dpx[0][N]=True
    if Nx>=1:
        dpx[0][N]=False
        dpx[0][N+F[0][0]]=True
        if s[0]=="T":
            dpx[1][N-F[0][0]]=True
    dpy[0][N]=True

    MA=F[0][0]+1

    for i in range(1,Nx):
        MA+=F[0][i]
        for j in range(N-MA,N+MA):
            if dpx[(i+1)%2][j]:
                dpx[i%2][j+F[0][i]]=True
                dpx[i%2][j-F[0][i]]=True


    MA=0
    for i in range(Ny):
        MA+=F[0][i]
        for j in range(N-MA,N+MA):
            if dpy[i%2][j]:
                dpy[(i+1)%2][j+F[1][i]]=True
                dpy[(i+1)%2][j-F[1][i]]=True

    if dpx[(Nx+1)%2][N+x] and dpy[Ny%2][N+y]:
        print("Yes")
    else:
        print("No")

main()

Buggy submission (verdict: Runtime Error):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            dpx[i+1][jj]=True
            dpx[i+1][jjj]=True
                
if Ny>=1:   
    MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            dpy[i+1][jj]=True
            dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            dpx[i+1][jj]=True
            idpx[i+1][jjj]=True
                
if Ny>=1:   
    MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            dpy[i+1][jj]=True
            dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    for j in range(N-MA,N+MA+1):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            if jj<=(2*N):
                dpx[i+1][jj]=True
            if jjj>=0:
                dpx[i+1][jjj]=True
                
if Ny>=1:   
    MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    for j in range(N-MA,N+MA+1):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            if jj<=(2*N):
                dpy[i+1][jj]=True
            if jjj>=0:
                dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    for j in range(N-MA,N+MA+1):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            if jj<=(2*N):
                dpx[i+1][jj]=True
            if jjj>=0:
                dpx[i+1][jjj]=True
                
                
MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    for j in range(N-MA,N+MA+1):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            if jj<=(2*N):
                dpy[i+1][jj]=True
            if jjj>=0:
                dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")