Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02988 (python)

Fixed submission:
n = int(input())

X = list(map(int,input().split()))

ans = 0
for i in range(len(X) - 2):
  if (X[i] > X[i+1] > X[i+2]) or (X[i] < X[i+1] < X[i+2]):
  	ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())

X = list(map(int,input().split()))

ans = 0
for i in range(len(X) - 2):
  if (X[i] > X[i+1] > X[i+2]) or (X[i] < X[i+1] < X[i+2])
  	ans += 1

print(ans)
Problem p02995 (python)

Fixed submission:
import fractions
A,B,C,D = map(int,input().split())

lcm = (C*D) // fractions.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(int(Bnondiv-Anondiv))

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())

lcm = (C*D) // math.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(Bnondiv-Anondiv)

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())

lcm = (C*D) // math.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(int(Bnondiv-Anondiv))
Problem p03030 (python)

Fixed submission:
n = int(input())

mylist = []
for i in range(n):
	mylist.append(list(map(str,input().split())))
	mylist[i].append(i+1)

mylist = sorted(mylist,key=lambda mylist:(mylist[0],-int(mylist[1])))
for i in mylist:
	print(i[2])

Buggy submission (verdict: Runtime Error):
N = int(input())

mylist = []
for i in range(n):
	mylist.append(list(map(str,input().split())))
	mylist[i].append(i+1)

mylist = sorted(mylist,key=lambda mylist:(mylist[0],-int(mylist[1])))
for i in mylist:
	print(i[2])
Problem p03032 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N,K = map(int,input().split())
    V = list(map(int,input().split()))
    
    ans = -(10**10)
    for pick in range(min(N+1,K+1)):
        throw = min(pick,K-pick)
        for left in range(pick+1):
            right = pick-left
            p = []
            minus = 0
            for i in range(left):
                if V[i] < 0:
                    minus += 1
                p.append(V[i])
            for i in range(right):
                if V[-i-1] < 0:
                    minus += 1
                p.append(V[-i-1])
            p.sort()
            if minus >= throw:
                rest = p[throw:]
            else:
                rest = p[minus:]
            ans = max(ans,sum(rest))
    
    print(ans)
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N,K = map(int,input().split())
    V = list(map(int,input().split()))
    
    ans = -(10**10)
    for pick in range(K+1):
        throw = min(pick,K-pick)
        for left in range(pick+1):
            right = pick-left
            p = []
            minus = 0
            for i in range(left):
                if V[i] < 0:
                    minus += 1
                p.append(V[i])
            for i in range(right):
                if V[-i-1] < 0:
                    minus += 1
                p.append(V[-i-1])
            p.sort()
            if minus >= throw:
                rest = p[throw:]
            else:
                rest = p[minus:]
            ans = max(ans,sum(rest))
    
    print(ans)
    
if __name__ == "__main__":
    main()
Problem p03037 (python)

Fixed submission:
N,M = map(int,input().split())
X = [list(map(int,input().split())) for i in range(M)]

keymax = 10**6
keymin = 0
for i in range(M):
	if X[i][0] > keymin:
		keymin = X[i][0]
	if X[i][1] < keymax:
		keymax = X[i][1]

if keymax >= keymin:
	print(keymax-keymin+1)
else:
	print("0")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
X = [list(map,int(input().split())) for i in range(M)]

keymax = 10**6
keymin = 0
for i in range(M):
	if X[i][0] > keymin:
		keymin = X[i][0]
	if X[i][1] < keymax:
		keymax = X[i][1]

print(keymax-keymin+1)
Problem p03069 (python)

Fixed submission:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    ans = s.count(".")
    count = ans
    for st in s:
        if st == "#":
            count += 1
        else:
            count -= 1
        ans = min(ans,count)
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    _s = "".join(list(reversed(s)))
    if "#" not in s:
        print(0)
    else:
        sind = s.index("#")
        dind = _s.index(".")
        use = s[sind:(N-dind)]
        print(min(use.count("."),use.count("#")))

if __name__ == "__main__":
    main()
Problem p03106 (python)

Fixed submission:
A,B,K = map(int,input().split())

diflist = []
for i in range(1,min(A,B)+1):
	if (A%i == 0 and B%i == 0):
		diflist.append(i)

print(diflist[-K])

Buggy submission (verdict: Runtime Error):
A,B,K = list(map(int,input().split()))

mylist = []
for i in range(1,max(A,B)):
	if A%i == 0 and B%i == 0:
		mylist.append(i)

print(mylist[K-1])
Problem p03148 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline
import heapq
from collections import defaultdict
from operator import itemgetter

def main():
    N,K = map(int,input().split())
    sushi = []
    for _ in range(N):
        t,d = map(int,input().split())
        sushi.append((-d,t))
    sushi.sort(key=itemgetter(0))
    use,only,unuse = [],[],sushi[K:]
    neta = defaultdict(int)
    x = 0
    for i in range(K):
        d,t = sushi[i]
        if neta[t] == 0:
            only.append((-d,t))
        else:
            use.append((-d,t))
        neta[t] += 1
        x -= d
    
    l = len(neta)
    heapq.heapify(use)
    heapq.heapify(only)
    heapq.heapify(unuse)
    
    ans = x + l**2
    while (len(use) != 0 and len(unuse) != 0 and l < K):
        cd,ct = heapq.heappop(unuse)
        cd *= -1
        if neta[ct] != 0:
            continue
        heapq.heappush(only,(cd,ct))
        rd,rt = heapq.heappop(use)
        x += cd-rd
        l += 1
        neta[ct] += 1
        neta[rt] -= 1
        ans = max(ans,x+l**2)
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
import heapq
from collections import defaultdict
from operator import itemgetter

def main():
    N,K = map(int,input().split())
    sushi = []
    for _ in range(N):
        t,d = map(int,input().split())
        sushi.append((-d,t))
    sushi.sort(key=itemgetter(0))
    use,only,unuse = [],[],sushi[K:]
    neta = defaultdict(int)
    x = 0
    for i in range(K):
        d,t = sushi[i]
        if neta[t] == 0:
            only.append((-d,t))
        else:
            use.append((-d,t))
        neta[t] += 1
        x -= d
    
    l = len(neta)
    heapq.heapify(use)
    heapq.heapify(only)
    heapq.heapify(unuse)
    
    ans = x + l**2
    while (len(use) != 0 or len(unuse) != 0 or l < K):
        cd,ct = heapq.heappop(unuse)
        cd *= -1
        if neta[ct] != 0:
            continue
        heapq.heappush(only,(cd,ct))
        rd,rt = heapq.heappop(use)
        x += cd-rd
        l += 1
        neta[ct] += 1
        neta[rt] -= 1
        ans = max(ans,x+l**2)
        
    print(ans)

if __name__ == "__main__":
    main()
Problem p03160 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    dp = [0 for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    cost = h
    for i in range(1,N-1):
        dp[i+1] = min(dp[i]+abs(cost[i+1]-cost[i]),\
            dp[i-1]+abs(cost[i+1]-cost[i-1]))
    print(dp[-1])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    def fr(i):
        if i == 1:
            return abs(h[1]-h[0])
        elif i == 0:
            return 0
        else:
            return min(fr(i-1)+abs(h[i]-h[i-1]),\
                    fr(i-2)+abs(h[i]-h[i-2]))

    print(fr(N-1))

if __name__ == "__main__":
    main()
Problem p03163 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(N)]
    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
    for i in range(N):
        for w in range(W+1):
            if X[i][0] <= w:
                dp[i+1][w] = max(dp[i][w-X[i][0]]+X[i][1],dp[i+1][w])
            else:
                dp[i+1][w] = dp[i][w]
    dp = np.array(dp)
    print(dp.max())

if __name__ == "__main__":
    main()
Problem p03164 (python)

Fixed submission:
import numpy as np

def main():
	N, W = map(int, input().split())
	dp = np.full(N * 1000 + 1, 10 ** 10, dtype=np.int64)
	dp[0] = 0
	for _ in range(N):
		w, v = map(int, input().split())
		np.minimum(dp[:-v] + w, dp[v:], out=dp[v:])
	print(((dp <= W) * np.arange(N * 1000 + 1)).max())

if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):
import numpy as np

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
table = np.zeros(w+1, dtype=np.int64)

for i in range(n):
    l = table[:-wv[i][0]]
    r = table[wv[i][0]:]
    np.maximum(l + wv[i][1], r, out = r)

print(table[w])
Problem p03166 (python)

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

def main():
    N,M = map(int,input().split())
    
    edge = [[] for _ in range(N)]
    for _ in range(M):
        x,y = map(int,input().split())
        edge[x-1].append(y-1)
        
    dist = [-1 for _ in range(N)]
            
    def dfs(s):
        if dist[s] != -1:
            return dist[s]
        else:
            ret = 0
            for fol in edge[s]:
                ret = max(ret,dfs(fol)+1)
            dist[s] = ret
            return ret

    for i in range(N):
        dfs(i)
        
    print(max(dist))
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    
    edge = [[] for _ in range(N)]
    for _ in range(M):
        x,y = map(int,input().split())
        edge[x-1].append(y-1)
        
    dist = [-1 for _ in range(N)]
            
    def dfs(s):
        if dist[s] != -1:
            return dist[s]
        else:
            ret = 0
            for fol in edge[s]:
                ret = max(ret,dfs(fol)+1)
            dist[s] = ret
            return ret
    
    ans = 0    
    for i in range(N):
        ans = max(ans,dfs(i))
        
    print(ans)
        
if __name__ == "__main__":
    main()
Problem p03213 (python)

Fixed submission:
def main():
    N = int(input())

    if N == 1:
        print(0)
    else:
        def prime_list(n):
            prime = [True for _ in range(n+1)]
            prime[0] = False
            prime[1] = False
            for i in range(2,int(n**0.5)+1):
                if not prime[i]:
                    continue
                for j in range(i*2,n+1,i):
                    prime[j] = False
            return [i for i in range(n+1) if prime[i]]

        prime_list = prime_list(N//2)
        cnt_list = [0 for _ in range(len(prime_list))]
        for i in range(len(prime_list)):
            count = 0
            d = N
            while d >= 1:
                count += d//(prime_list[i])
                d //= prime_list[i]
            cnt_list[i] = count

        def num(X):
            return len(list(filter(lambda x:x>=X-1,cnt_list)))

        print(num(75)+num(15)*(num(5)-1)+num(25)*(num(3)-1)+\
            num(5)*(num(5)-1)*(num(3)-2)//2)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    def prime_list(n):
        prime = [True for _ in range(n+1)]
        prime[0] = False
        prime[1] = False
        for i in range(2,int(n**0.5)+1):
            if not prime[i]:
                continue
            for j in range(i*2,n+1,i):
                prime[j] = False
        return [i for i in range(n+1) if prime[i]]

    prime_list = prime_list(N//2)
    cnt_list = [0 for _ in range(len(prime_list))]
    for i in range(len(prime_list)):
        count = 0
        d = N
        while d >= 1:
            count += d//(prime_list[i])
            d //= prime_list[i]
        cnt_list[i] = count

    def num(X):
        return len(list(filter(lambda x:x>=X-1,cnt_list)))

    print(num(75)+num(15)*(num(5)-1)+num(25)*(num(3)-1)+\
        num(5)*(num(5)-1)*(num(3)-2)//2)

if __name__ == "__main__":
    main()
Problem p03238 (python)

Fixed submission:
N = int(input())
 
if N == 1:
  print("Hello World")
else:
  A = int(input())
  
  B = int(input())
  
  print( A + B )

Buggy submission (verdict: Runtime Error):
N = int(input())

if N = 1:
  print("Hello World")
else:
  A = int(input())
  
  B = int(input())
  
  print( A + B )
Problem p03244 (python)

Fixed submission:
from collections import Counter 
n = int(input())
v = list(map(int,input().split()))
 
odd = []
even = []
for i in range(n//2):
	odd.append(v[2*i+1])
	even.append(v[2*i])

odd = sorted(odd)
even = sorted(even)
ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)
def cnt(X):
	count = 0
	ans = 0
	for i in range(len(X)-1):
		if X[i+1] == X[i]:
			count += 1
			ans = max(ans,count)
		else:
			count = 0
	return ans+1
            
if ac[0][0] != bc[0][0]:
  print(len(v)-cnt(odd)-cnt(even))
elif len(ac) == 1 and len(bc) == 1:
	print(n//2)
else:
	print(n-max(ac[0][1]+bc[1][1],ac[1][1]+bc[0][1]))

Buggy submission (verdict: Runtime Error):
from corections import Counter 
n = int(input())
v = list(map(int,input().split()))
 
odd = []
even = []
for i in range(n//2):
	odd.append(v[2*i+1])
	even.append(v[2*i])
 
odd = sorted(odd)
even = sorted(even)
ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)
def cnt(X):
	count = 0
	ans = 0
	for i in range(len(X)-1):
		if X[i+1] == X[i]:
			count += 1
			ans = max(ans,count)
		else:
			count = 0
	return ans+1
            
if ac[0][0] != bc[0][0]:
  print(len(v)-cnt(odd)-cnt(even))
elif len(ac) == 1 and len(bc) == 1:
	print(n//2)
else:
	print(n-max(ac[0][1]+bc[1][1],ac[1][1]+bc[0][1]))
Problem p03260 (python)

Fixed submission:
a,b = map(int,input().split())
 
if ( a * b ) % 2 == 0:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
a,b = map.(int,input().split())

if ( a * b ) % 2 == 0:
  print("No")
else:
  print("Yes")
Problem p03263 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline

def main():
    H,W = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(H)]
    
    ans = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j]%2 != 0:
                a[i][j+1] += 1
                ans.append((i+1,j+1,i+1,j+2))
                
    for i in range(H-1):
        if a[i][-1]%2 != 0:
            a[i+1][-1] += 1
            ans.append((i+1,W,i+2,W))
            
    print(len(ans))
    for x in ans:
        print(*x)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

def main():
    H,W = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(H)]
    
    ans = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j]%2 != 0:
                a[i][j+1] += 1
                ans.append((i+1,j+1,i+1,j+2))
                
    for i in range(H-1):
        if a[i][-1]%2 != 0:
            a[i+1][-1] += 1
            ans.append((i+1,j+1,i+2,j+1))
            
    print(len(ans))
    for x in ans:
        print(*x)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

def main():
    H,W = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(H)]
    
    ans = []
    for i in range(H):
        for j in range(W-1):
            if i%2 == 0:
                ans.append((i+1,j+1,i+1,j+2))
                last = W
            else:
                ans.append((i+1,W-j,i+1,W-j-1))
                last = 1
        if i != H-1:
            ans.append((i+1,last,i+2,last))
    
    print(len(ans))
    for x in ans:
        print(*x)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(H)]

    ans_list = []
    count = 0
    for i in range(H):
        for j in range(W-1):
            if a[i][j]%2 == 1:
                count += 1
                ans_list.append([i+1,j+1,i+1,j+2])
            a[i][j+1] += a[i][j]

    for i in range(H-1):
        if a[i][-1]%2 == 1:
            count += 1
            ans_list.append([i+1,j+1,i+2,j+1])
        a[i+1][-1] += a[i][-1]

    ans = [" ".join(map(str,i)) for i in ans_list]

    print(count)
    print("\n".join(map(str,ans)))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(H)]

    for i in range(H):
        for j in range(W-1):
            if a[i][j]%2 == 1:
                print(i+1,j+1,i+1,j+2)
            a[i][j+1] += a[i][j]

    for i in range(H-1):
        if a[i][-1]%2 == 1:
            print(i+1,j+1,i+2,j+1)
        a[i+1][-1] += a[i][-1]

if __name__ == "__main__":
    main()
Problem p03436 (python)

Fixed submission:
from collections import Counter
def main():
    H,W = map(int,input().split())
    s = [list(map(str,input())) for _ in range(H)]
    INF = 10**5
    maze_list = [[INF for _ in range(W)] for _ in range(H)]
    maze_list[0][0] = 0
    def item(array):
        return [item for sublist in array for item in sublist]

    counter = list(Counter(item(s)).items())
    num = 0
    for i in range(len(counter)):
        if counter[i][0] == ".":
            num = counter[i][1]
            break

    queue = []
    queue.insert(0,(0,0))
    while len(queue):
        x,y = queue.pop()
        if x == H-1 and y == W-1:
            break
        for i in range(4):
            nx,ny = x + [1,0,-1,0][i],y + [0,1,0,-1][i]
            if (0<=nx and nx<H and 0<=ny and ny<W and \
                s[nx][ny]!="#" and maze_list[nx][ny]==INF):
                queue.insert(0,(nx,ny))
                maze_list[nx][ny] = maze_list[x][y] + 1

    if maze_list[H-1][W-1] == INF:
        print(-1)
    else:
        print(num-maze_list[H-1][W-1]-1)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter
def main():
    H,W = map(int,input().split())
    s = [list(map(str,input())) for _ in range(H)]
    INF = 10**5
    maze_list = [[INF for _ in range(W)] for _ in range(H)]
    maze_list[0][0] = 0
    def item(array):
        return [item for sublist in array for item in sublist]

    counter = sorted(list(Counter(item(s)).items()))

    queue = []
    queue.insert(0,(0,0))
    while len(queue):
        x,y = queue.pop()
        if x == H-1 and y == W-1:
            break
        for i in range(4):
            nx,ny = x + [1,0,-1,0][i],y + [0,1,0,-1][i]
            if (0<=nx and nx<H and 0<=ny and ny<W):
                if (s[nx][ny]!="#" and maze_list[nx][ny]==INF):
                    queue.insert(0,(nx,ny))
                    maze_list[nx][ny] = maze_list[x][y] + 1

    if maze_list[H-1][W-1] == INF:
        print(-1)
    else:
        print(counter[1][1]-maze_list[H-1][W-1]-1)

if __name__ == "__main__":
    main()
Problem p03476 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    M = 100000
    def sieve(n):
        is_prime = [True for _ in range(n+1)]
        is_prime[0] = False

        for i in range(2, n+1):
            if is_prime[i-1]:
                j = 2 * i
                while j <= n:
                    is_prime[j-1] = False
                    j += i
        return is_prime
    prime = sieve(M)
    alike = [0]
    for i in range(1,M+1,2):
        if (prime[i-1] and prime[(i+1)//2-1]):
            alike.append(alike[-1]+1)
        else:
            alike.append(alike[-1])
            
    for i in range(N):
        l,r = map(int,input().split())
        l = (l+1)//2
        r = (r+1)//2
        print(alike[r]-alike[l-1])
    
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
import sympy

def main():
    N = int(input())
    M = 100000
    def sieve(n):
        is_prime = [True for _ in range(n+1)]
        is_prime[0] = False

        for i in range(2, n+1):
            if is_prime[i-1]:
                j = 2 * i
                while j <= n:
                    is_prime[j-1] = False
                    j += i
        return is_prime
    prime = sieve(M)
    alike = [0]
    for i in range(1,M+1,2):
        if (prime[i-1] and prime[(i+1)//2-1]):
            alike.append(alike[-1]+1)
        else:
            alike.append(alike[-1])
            
    for i in range(N):
        l,r = map(int,input().split())
        l = (l+1)//2
        r = (r+1)//2
        print(alike[r]-alike[l-1])
    
    
if __name__ == "__main__":
    main()
Problem p03488 (python)

Fixed submission:
import sys
#input = sys.stdin.buffer.readline

def main():
    s = input().split("T")
    x,y = map(int,input().split())
    l = len(s)
    dx,dy = [len(s[0])],[0]
    nx,ny = [],[]
    for i in range(1,l):
        d = len(s[i])
        if i%2 == 0:
            nx = []
            for num in dx:
                nx.append(num+d)
                nx.append(num-d)
            dx = list(set(nx))
        else:
            ny = []
            for num in dy:
                ny.append(num+d)
                ny.append(num-d)
            dy = list(set(ny))

    if (x in dx and y in dy):
        print("Yes")
    else:
        print("No")
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    s = list(input())
    s.append("T")
    x,y = map(int,input().split())
    x_list = []
    y_list = []
    count = 0
    n = 0
    for i in range(len(s)+1):
        if s[i] == "F":
            count += 1
        else:
            if n == 0:
                x_list.append(count)
                n = 1
            else:
                y_list.append(count)
                n = 0
            count = 0
    x_def = {0}
    for i in x_list:
        x__def = set()
        for j in x_def:
            x__def.add(j+i)
            x__def.add(j-i)
        x_def = x__def
    if x not in x_def:
        print("No")
        exit()

    y_def = {0}
    for i in y_list:
        y__def = set()
        for j in y_def:
            y__def.add(j+i)
            y__def.add(j-i)
        y_def = y__def
    if y not in y_def:
        print("No")
        exit()
    print("Yes")

if __name__ == "__main__":
    main()