Problem p03488 (python)

Fixed submission:
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
y=abs(y)
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0
v=sum(x1)
w=sum(y1)
v-=x1[0]
x-=x1[0]
x1.pop(0)
x=abs(x)
if v<x or w<y:
    print('No')
    exit()

dpx=[[0 for i in range(v+1)] for j in range(len(x1)+1)]
dpx[0][-1]=1

for i in range(len(x1)):
    for j in range(v+1):
        if dpx[i][j]==1:
            if j-2*x1[i]>=0:
                dpx[i+1][j-2*x1[i]]=1
            dpx[i+1][j]=1

if len(y1)==0:
    y1.append(0)
dpy=[[0 for i in range(w+1)] for j in range(len(y1)+1)]
dpy[0][-1]=1

for i in range(len(y1)):
    for j in range(w+1):
        if dpy[i][j]==1:
            if j-2*y1[i]>=0:
                dpy[i+1][j-2*y1[i]]=1
            dpy[i+1][j]=1

if dpy[-1][y]==1 and dpx[-1][x]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
s = list(input())
x, y = map(int, input().split())
y = abs(y)
s.append('T')
x1 = []
y1 = []

count = 0
u = 0
for i in range(len(s)):
    if s[i] == 'F':
        count += 1
    else:
        if u % 2 == 0:
            x1.append(count)
            u += 1
            count = 0
        else:
            y1.append(count)
            u += 1
            count = 0

v = sum(x1)
w = sum(y1)
if v < x or w < y:
    print('No')
    exit()

dpx = [[0 for i in range(v + 1)] for j in range(len(x1) + 1)]
dpx[0][-1] = 1
x -= x1[0]
x1[0] = 0
v -= x1[0]
x = abs(x)

for i in range(len(x1)):
    for j in range(v + 1):
        if dpx[i][j] == 1:
            if j - 2 * x1[i] >= 0:
                dpx[i + 1][j - 2 * x1[i]] = 1
            dpx[i + 1][j] = 1

if len(y1) == 0:
    y1.append(0)
dpy = [[0 for i in range(w + 1)] for j in range(len(y1) + 1)]
dpy[0][-1] = 1

for i in range(len(y1)):
    for j in range(w + 1):
        if dpy[i][j] == 1:
            if j - 2 * y1[i] >= 0:
                dpy[i + 1][j - 2 * y1[i]] = 1
            dpy[i + 1][j] = 1

if dpy[-1][y] == 1 and dpx[-1][x] == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
    import sys
    input = sys.stdin.readline
    s = list(input())
    x, y = map(int, input().split())
    y = abs(y)
    s.append('T')
    x1 = []
    y1 = []

    count = 0
    u = 0
    for i in range(len(s)):
        if s[i] == 'F':
            count += 1
        else:
            if u % 2 == 0:
                x1.append(count)
                u += 1
                count = 0
            else:
                y1.append(count)
                u += 1
                count = 0

    v = sum(x1)
    w = sum(y1)
    if v < x or w < y:
        print('No')
        exit()

    dpx = [[0 for i in range(v + 1)] for j in range(len(x1) + 1)]
    dpx[0][-1] = 1
    x -= x1[0]
    x1[0] = 0
    v-=x1[0]
    x=abs(x)

    for i in range(len(x1)):
        for j in range(v + 1):
            if dpx[i][j] == 1:
                if j - 2 * x1[i] >= 0:
                    dpx[i + 1][j - 2 * x1[i]] = 1
                dpx[i + 1][j] = 1

    if len(y1) == 0:
        y1.append(0)
    dpy = [[0 for i in range(w + 1)] for j in range(len(y1) + 1)]
    dpy[0][-1] = 1

    for i in range(len(y1)):
        for j in range(w + 1):
            if dpy[i][j] == 1:
                if j - 2 * y1[i] >= 0:
                    dpy[i + 1][j - 2 * y1[i]] = 1
                dpy[i + 1][j] = 1

    if dpy[-1][y] == 1 and dpx[-1][x] == 1:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
x=abs(x)
y=abs(y)
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0

v=sum(x1)
w=sum(y1)

dpx=[[0 for i in range(v+1)] for j in range(len(x1)+1)]

dpx[0][-1]=1

for i in range(len(x1)):
    for j in range(v+1):
        if dpx[i][j]==1:
            if j-2*x1[i]>=0:
                dpx[i+1][j-2*x1[i]]=1
            dpx[i+1][j]=1

if len(y1)==0:
    y1.append(0)

dpy=[[0 for i in range(w+1)] for j in range(len(y1)+1)]
dpy[0][-1]=1

for i in range(len(y1)):
    for j in range(w+1):
        if dpy[i][j]==1:
            if j-2*y1[i]>=0:
                dpy[i+1][j-2*y1[i]]=1
            dpy[i+1][j]=1



if dpy[len(y1)][y]==1 and dpx[len(x1)][x]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]]
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]]
        else:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j - x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]]
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]]
        else:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]

if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]>=-sum(x1)-1 and j+x1[i]<sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j-x1[i]] 
        elif j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]] 
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]]






dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]>=-sum(y1)-1 and j+y1[i]<sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]] 
        elif j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]] 
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]]




if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]>=-sum(x1)-1 and j+x1[i]<sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j-x1[i]] or dpx[i][j]
        elif j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]] or dpx[i][j]
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]] or dpx[i][j]
        else:
            dpx[i + 1][j] = dpx[i][j]





dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]>=-sum(y1)-1 and j+y1[i]<sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]] or dpy[i][j]
        elif j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]] or dpy[i][j]
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j]
        else:
            dpy[i + 1][j] =  dpy[i][j]




if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]>=-sum(x1)-1 and j+x1[i]<sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j-x1[i]] or dpx[i][j]
        elif j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]] or dpx[i][j]
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]] or dpx[i][j]
        else:
            dpx[i + 1][j] = dpx[i][j]





dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]>=-sum(y1)-1 and j+y1[i]<sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]] or dpy[i][j]
        elif j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]] or dpy[i][j]
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j]
        else:
            dpy[i + 1][j] =  dpy[i][j]




if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        dpx[i + 1][j] = dpx[i][j - x1[i]] or dpx[i][j+x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]


if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0

if (len(x1)<=1 and x1[0]!=x) or (len(y1)==0 and y1[0]!=y):
    print('No')
    exit()

if (len(x1)==1 and x1[0]==x) and (len(y1)==0 and y1[0]==y):
    print('Yes')
    exit()



dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)>=2:
    dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        dpx[i + 1][j] = dpx[i][j - x1[i]] or dpx[i][j+x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]

dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]


if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0

if (len(x1)<=1 and x1[0]!=x) or (len(y1)==0 and y1[0]!=y):
    print('No')
    exit()

dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)>=2:
    dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        dpx[i + 1][j] = dpx[i][j - x1[i]] or dpx[i][j+x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]

dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]


if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')