Harryxun/stf_run huggingface dataset:
class UnionFindTree():
    def __init__(self, N):
        self.parent = [-1]*(N+1)
        self.size = [1]*(N+1)
        self.hubensa = N*(N-1)//2
  
    def find(self, i):
        if self.parent[i] == -1:
            group = i
        else:
            group = self.find(self.parent[i]) 
            self.parent[i] = group
        return group
      
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] == self.rank[py]: # rank is same
                self.rank[px] += 1
            elif self.rank[px] < self.rank[py]:
                px, py = py, px
                
            self.parent[py] = px
            self.hubensa -= self.size[px] * self.size[py]
            self.size[px] += self.size[py]

N, M = list(map(int, input().split()))
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))

ans = []
UFT = UnionFindTree(N)

# 後ろから処理
for i in range(M-1, -1, -1):
    ans.append(UFT.hubensa)
    UFT.unite(A[i], B[i])

print(*ans[::-1], sep="\n")


### FIXED CODE ###

class UnionFindTree():
    def __init__(self, N):
        self.parent = [-1]*(N+1)
        self.rank = [1]*(N+1)
        self.size = [1]*(N+1)
        self.hubensa = N*(N-1)//2

    def find(self, i):
        if self.parent[i] == -1:
            group = i
        else:
            group = self.find(self.parent[i]) 
            self.parent[i] = group
        return group
      
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] == self.rank[py]: # rank is same
                self.rank[px] += 1
            elif self.rank[px] < self.rank[py]:
                px, py = py, px
                
            self.parent[py] = px
            self.hubensa -= self.size[px] * self.size[py]
            self.size[px] += self.size[py]

N, M = list(map(int, input().split()))
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))

ans = []
UFT = UnionFindTree(N)

# 後ろから処理
for i in range(M-1, -1, -1):
    ans.append(UFT.hubensa)
    UFT.unite(A[i], B[i])

print(*ans[::-1], sep="\n")
wake_up_hour= int(input("Enter WakeUp Hour: "))
wake_up_minute=int(input("Enter WakeUp Minute: "))
sleep_hour=int(input("Enter Sleep Hour: "))
sleep_minute= int(input("Enter Sleep Minute:" ))
study_time=int(input("Study time :"))

#print(wake_up_hour, wake_up_minute, sleep_hour, sleep_minute, study_time)
Total_Minutes = (sleep_hour) *60 + (sleep_minute) - ((wake_up_hour) * 60 + (wake_up_minute))
if Total_Minutes > study_time:
    print("You can finish the study")
    start_before_minute= ((sleep_hour*60 +  sleep_minute) - study_time) % 60
    start_before_hour= ((sleep_hour*60 +  sleep_minute) - study_time) // 60 
    print("Start before: ", start_before_hour, start_before_minute, )
else:
    print("You are lazy!!!. wake up early")

### FIXED CODE ###

import math
import re
import copy

h1,m1,h2,m2,k = map(int,input().split())
w1 = h1*60 + m1
w2 = h2 * 60 + m2
w3 = (w2-w1+24*60)%(24*60)
w3 = w3 - k
print(w3)
K = int(input())
a,b = map(int,input().split())
for i in range(a,b+1):
  if i%K == 0:
  print('OK')
  else:
  print('No')

### FIXED CODE ###

K = int(input())
a,b = map(int,input().split())
c = 'NG'
for i in range(a,b+1):
  if i % K == 0:
    c = 'OK'
    break
print(c)
s = int(input())
l = s / 100
r = s % 100

if(1 <= l && <= 12):
    if(1 <= r && r <= 12):
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if(1 <= r && r <= 12):
        print('YYMM')
    else:
      print('NA')

### FIXED CODE ###

s = int(input())
l = s / 100
r = s % 100

if(1 <= l and l <= 12):
    if(1 <= r and r <= 12):
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if(1 <= r and r <= 12):
        print('YYMM')
    else:
        print('NA')
X=[int(input()) for i in range(5)]

ans=0
W=[]

for i in range(len(X)):
    if X[i]%10 == 0:
        ans+=X[i]
    else:
        ans+=(X[i]//10)*10+10
        W.append(X[i]%10)

ans +=-10+min(W)
print(ans)

### FIXED CODE ###

A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())

X=[A,B,C,D,E]
ans=0

Y=10

for i in range(len(X)):
    if X[i]%10 == 0:
        ans+=X[i]
    else:
        Y=min(Y,X[i]%10)
        ans+=(X[i]//10)*10+10

ans +=-10+Y
print(ans)
l,n=map(int,input().split())

s=[]
for i in range(n):
    s.append(input())

order=sorted(s)
ans=''.join(order)

print(ans)

### FIXED CODE ###

n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")
N,L = map(int,input().split())
S = sorted(list(input() for i in range(N)))
print(*s,sep="")

### FIXED CODE ###

N,L = map(int,input().split())
S = sorted(list(input() for i in range(N)))
print(*S,sep="")
import math
N = int(input())
M = []
sqr_N = math.floor(math.sqrt(N))
    
for i in range(sqr_N):
    if i == 0:
        continue
    elif N % i == 0:
        M.append(i)
        
        
ANS = (max(M) - 1) + ((N / max(M)) - 1)

print(int(ANS))

### FIXED CODE ###

import math
N = int(input())
M = []
sqr_N = math.floor(math.sqrt(N))
a = 0
    
for i in range(1, (sqr_N + 1)):
    if N % i == 0:
        a = i

a_pair = N // a
print(a + a_pair - 2)
n, m = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()], reverse=True)
i = 0
j = 1
l = len(a)
for _ in range(m):
    if n == 1:
        a[0] //=2
    else:
        if a[0] >= a[i] and a[0] >= a[j]:
            a[0] //= 2
        elif a[i] >= a[j]:
            a[i] //= 2
        else:
            a[j] //= 2
        if a[j] < a[j+1]:
            i = j
            j = j+1
print(sum(a))

### FIXED CODE ###

# ABC141-D
import heapq
n, m = [int(x) for x in input().split()]
h = [-int(x) for x in input().split()]
heapq.heapify(h)
for i in range(m):
    x = heapq.heappop(h)
    heapq.heappush(h, -(-x//2))
z = 0
print(-sum(h))
if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = map(int, input().split(' '))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            for i in range(0, 100):
                if (X-i) not in P:
                    print(X-i)
                    break

                elif (X+i) not in P:
                    print(X+i)
                    break
        elif X not in P:
            print(X)
    else:
        print(X)

### FIXED CODE ###

if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            for i in range(100):
                if (X-i) not in P:
                    print(X-i)
                    break

                elif (X+i) not in P:
                    print(X+i)
                    break
        elif X not in P:
            print(X)
    else:
        print(X)
a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a'))


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))

### FIXED CODE ###

a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a')+1)


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))
A, B, C = int(input())
if A==B:
	print(C)
elif B==C:
	print(A)
elif C==A:
	print(B)

### FIXED CODE ###

A, B, C = list(map(int, input().split()))
if A==B:
	print(C)
elif B==C:
	print(A)
elif C==A:
	print(B)
H, W = map(int, input().split())

li = []
for i in range(H+2):
    li.append(["."]*(W+2))

for h in range(H):
    for w in range(W):
        li[h+1][w+1] = input()

S = [i[1:-1] for i in li][1:-1]

import numpy as np
ans = np.zeros([H+2, W+2], dtype=int)

for h in range(1, H):
    for w in range(1, W):
        if li[h][w]=="#":
            ans[h-1:h+2, w-1:w+2] += 1      

ans = ans.astype("str")
ans = ans[1:-1, 1:-1]

for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            ans[h, w] = "#"

for i in ans:
    print("".join(i))

### FIXED CODE ###

import numpy as np

# 読み込み
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(map(str, input().rstrip())))

# 外枠を「.」で囲う準備
li = []
for i in range(H+2):
    li.append(["."]*(W+2))

# 外枠付きSの生成
for i in range(1, H+1):
    li[i][1:-1] = S[i-1]

# カウント用配列の準備
ans = []
for i in range(H+2):
    ans.append([0]*(W+2))
ans = np.array(ans)

# カウント処理
for h in range(1, H+1):
    for w in range(1, W+1):
        if li[h][w]=="#":
            ans[h-1:h+2, w-1:w+2] += 1

# カウント結果から必要な場所だけ切り出す
ans = ans.astype("str")
ans = ans[1:-1, 1:-1]

# 「#」で上書きしながら出力
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            ans[h, w] = "#"
    print("".join(ans[h]))
n = input()
a = map(int, raw_input().split())
b = [0 for _ in range(n)]
used = []

for i in xrange(n, 0, -1):
  sum = 0
  for j in xrange(2 * i, n + 1, i):
    sum += b[j]
  if sum % 2 != a[i]:
    used.append(i)
    b[i] = 1
print len(used)
for x in used: print x,
print

### FIXED CODE ###

n = input()
a = [0] + map(int, raw_input().split())
b = [0 for _ in range(n + 1)]
used = []

for i in xrange(n, 0, -1):
  sum = 0
  for j in xrange(2 * i, n + 1, i):
    sum += b[j]
  if sum % 2 != a[i]:
    used.append(i)
    b[i] = 1
print len(used)
for x in used: print x,
print
x, y = map(int, input(). split())
  if x < y:
    print('x < y')
  elif x == y:
      print('x == y')
  else:
    pass


### FIXED CODE ###

a, b = map(int,input().split())
 
if a < b :
  print('a < b')
elif a > b:
    print('a > b')
else :
    print('a == b')
import sys
input_lines=sys.stdin.readlines()
for line in input_lines:
 x=[int(i) for i in line]
 print(len(str(x[0]+x[1])))

### FIXED CODE ###

while True:
 try:
  x,y=[int(i) for i in input().split()]
  print(len(str(x+y)))
 except EOFError:
  break
from operator import mul
from functools import reduce

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
#def ConN(i):
    #n_num = int(i*(i-1)/2)
    #return n_num

def cmb(n):
    over = reduce(mul, range(n, n - 2, -1))
    under = reduce(mul, range(1,2 + 1))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*2019
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
    
#print(mod)
x += ConZ(mod[0])
del mod[0]

for j in range(len(mod)):
    x+=cmb(mod[j])
print(x)


### FIXED CODE ###

S,W = map(int,input().split())
if W>=S:
    print('unsafe')
else:
    print('safe')
INF = 1000000000

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]

maxA = max(AB[:][0])

dp = [INF for i in range(h+maxA)]
dp[0] = 0

for i in range(1, h+maxA):
    dp[i] = min(dp[i-a] + b for a, b in AB)

print(min(dp[h:]))


### FIXED CODE ###

INF = 1000000000

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]

maxA = max(AB, key=lambda x: x[0])[0]

dp = [INF for i in range(h+maxA)]
dp[0] = 0

for i in range(1, h+maxA):
    dp[i] = min(dp[i-a] + b for a, b in AB)

print(min(dp[h:]))
s,t = input()
if t[:-1]==s:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

s= input()
t = input()
if t[:-1]==s:
  print("Yes")
else:
  print("No")
n = int(input())
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n):
    if dp[i] == float("Inf"):
        pass
    else:
        for j in range(1,n//6):
            if i + 6**j > n:
                break
            dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)
        for j in range(1,n//9):
            if i + 9**j > n:
                break
            dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)
ans = float("Inf")
for i in range(n-5, n+1):
    ans = min(ans, dp[i]+n-i)
print(ans)

### FIXED CODE ###

from collections import deque
n = int(input())
q = deque([])
now = 0
reach = [0]*100001
lis = []
for i in range(6):
    lis.append(6**(i+1))
for i in range(5):
    lis.append(9**(i+1))
lis.append(1)
lis = sorted(lis)
q.append(0)
ans = 0
while q:
    if ans == 1:
        break
    x = q.popleft()
    
    for y in lis:
        if x + y < n:
            if  reach[x+y] == 0:
                q.append(x+y)
                reach[x+y] = reach[x]+1
            
        elif x + y == n:
            reach[x+y] = reach[x]+1
            ans = 1
            break
print(max(reach))
S = raw_input()
mat = []
lis = list(S)
for i in lis:
	if i in S
		print "no"
		break
	mat.add(i)
else:
	print "yes"

### FIXED CODE ###

S = raw_input()
lis = list(S)
mat = []
for i in lis:
	if i in mat:
		print "no"
		break
	mat.append(i)
else:
	print "yes"
n = int(input())
a, b = map(int,input().split())
listP=list(map(int,input().split()))
num0 = sum(listP<=a)
num1 = sum(listP<=b) - num0
num2 = sum(listP>b)
print(min([num0,num1,num2]))

### FIXED CODE ###

n = int(input())
listAB = list(map(int,input().split()))
listP=list(map(int,input().split()))

a = listAB[0]
b = listAB[1]

num0 = sum([1 for p in listP if p <=a])
num2 = sum([1 for p in listP if p > b])
num1 = n - num0 -num2
print(min([num0,num1,num2]))
n=int(input())
a=list(map(int,input().split()))
a1=0
a2=0
a3=0
for i in a:
  if a%4==0:
    a1+=1
  elif a%4==2:
    a2+=1
  else:
    a3+=1
    
if a3==0:
  print("Yes")
else:
  if a2==0:
    if a1>=a3-1:
      print("Yes")
    else:
      print("No")
  else:
    if a1>=a3:
      print("Yes")
    else:
      print("No")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a1=0
a2=0
a3=0
for i in a:
  if i%4==0:
    a1+=1
  elif i%4==2:
    a2+=1
  else:
    a3+=1
    
if a3==0:
  print("Yes")
else:
  if a2==0:
    if a1>=a3-1:
      print("Yes")
    else:
      print("No")
  else:
    if a1>=a3:
      print("Yes")
    else:
      print("No")
while True:
    a = [int(i) for i in input().split(" ")]
    num1 = a[0]
    num2 = a[1]
    if num1 == 0 and num2 == 0:
    elif num1 <= num2:
        print(num1,num2)
    elif num1 > num2:
        print(num2,num1) 
    

### FIXED CODE ###

while True:
    a = [int(i) for i in input().split(" ")]
    num1 = a[0]
    num2 = a[1]
    if num1 == 0 and num2 == 0:
        break
    elif num1 <= num2:
        print(num1,num2)
    elif num1 > num2:
        print(num2,num1)
I,*U=N,*D=9**9,
P,*L='x+y,',
M,*R='x-y,',
for t in[*open(n:=0)][1:]:*z,u=t.split();exec(u+'+=[*map(int,z)],')
for*A,S in(L,R,'y,x,'),(U,R,P+M),(D,U,'x,y,'),(L,D,P+M),(L,U,M+P),(D,R,M+P):
 for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in P)'%S):
  if r:n,p=x,y
  elif x==n:N=min(N,y-p)
print(N%I*5or'SAFE')

### FIXED CODE ###

d=[[],[],[],[]]
for t in[*open(0)][1:]:*z,u=t.split();d[ord(u)%5]+=[*map(int,z)],
I=N=9**9
P,M='x+y,','x-y,'
for*A,S in(3,0,'x,y,'),(1,2,'y,x,'),(0,2,P+M),(1,3,P+M),(1,0,M+P),(3,2,M+P):
 n=p=-I
 for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in d[P])'%S):
  if r:n,p=x,y
  elif x==n:N=min(N,y-p)
print(N%I*5or'SAFE')
n = int(input())
a = list(map(int, input().split()))

count_list = {}
s = 0
for i in range(n):
  s += a[i]
  count_list[s] = count_list.get(s, 0) += 1

count = 0
# count += count_list.get(0, 0) * (count_list.get(0, 0)+1) // 2
for i in count_list.keys():
  count+= count_list[i] * count_list.get(-i, 0)
print((count + count_list.get(0, 0))//2)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

count_list = {}
s = 0
for i in range(n):
  s += a[i]
  count_list[s] = count_list.get(s, 0) + 1

count = 0
count += count_list.get(0, 0) * (count_list.get(0, 0)+1)
for i in count_list.keys():
  if i!=0:
    #count+= count_list[i] * count_list.get(-i, 0)
    count += count_list[i] * (count_list[i]-1)
print(count//2)
strstart = input()
wzc = 0
wzf = 0
for i in strstart:
    i2 += 1
    if i == 'C':
        wzc = i2
    if i == 'F':
        wzf = i2
if wzc < wzf:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

s = input()
if s.count('C') == 0 or s.count('F') == 0:
    print('No')
else:
    s = s[s.find('C'):]
    if s.count('F') == 0:
        print('No')
    else:
        print('Yes')
import numpy as np
    n = int(input())
    h = list(map(int, input().split()))
    ans = [np.inf for i in range(n)]
    ans[0] = 0
    def dp(ans, h, k):
        if n == k + 1:
            return
        if n != k + 2:
            ans[k + 2] = min(ans[k + 2], ans[k] + abs(h[k + 2] - h[k]))
        ans[k + 1] = min(ans[k + 1], ans[k] + abs(h[k + 1] - h[k]))
        dp(ans, h , k + 1)
    dp(ans, h, 0)
    print(ans[-1])

### FIXED CODE ###

n = int(input())
hl = list(map(int,input().split()))

dp = [float("inf") for i in range(n)]

dp[0] = 0
for idx, h in enumerate(hl):
    if idx + 2 < n:
        dp[idx+2] = min(dp[idx] + abs(hl[idx] - hl[idx+2]), dp[idx+2])
    if idx+1 < n:
        dp[idx+1] = min(dp[idx] + abs(hl[idx] - hl[idx+1]), dp[idx+1])

print(dp[n-1])
if S =< W :
  print('unsafe')
 
else:
  print('safe')


### FIXED CODE ###

S, W = map(int, input().split())
if S <= W:
  print('unsafe')
  
else:
  print('safe')
a = int(input())
b = int(input())

print (max(a+b, a-b, a*b))


### FIXED CODE ###

a, b = map(int,input().split())

print (max([a+b, a-b, a*b]))
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = a * b
if c % 2 == 0:
  print(Even)
else:
  print(Odd)
  

### FIXED CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = a * b
if c % 2 == 0:
  print("Even")
else:
  print("Odd")
a = int("".join(input().split("/"))))
if a <= 20190430:
  print("Heisei")
else:
  print("TBD")

### FIXED CODE ###

a = int("".join(input().split("/")))
if a <= 20190430:
  print("Heisei")
else:
  print("TBD")
N, M = map(int, input().split())
d = dict([list(map(int, input().split())) for i in range(N)])
d = sorted(d.items())

c = p = i = 0

while c < M:
    if c + d[i][1] <= M:
        c += d[i][1]
        p += d[i][0] * d[i][1]
        i += 1
    else:
        p += d[i][0] * (M - c)
        break

print(p)


### FIXED CODE ###

N, M = map(int, input().split())
d = [list(map(int, input().split())) for i in range(N)]
d.sort(key=lambda x:(x[0],x[1]))

c = p = i = 0

while c < M:
    if c + d[i][1] <= M:
        c += d[i][1]
        p += d[i][0] * d[i][1]
        i += 1
    else:
        p += d[i][0] * (M - c)
        break

print(p)
a,b,k = map(int,input().split())
 
for a,b in range(k):
	if a >=  1:
            a -= 1
  
	elif a < 1 and b >= 1:
            b -= 1
	else:
            break
        
print (a,b,end=" ")

### FIXED CODE ###

s = input().split()
print(s[1] + s[0])
S, T = input()
print(T + S)

### FIXED CODE ###

S, T = input().split()
print(T + S)
s=str(input())
flag=0
for i in range(len(s)):
  s=s[:len(s)-2*i]
  for j in range(len(s)//2):
    if s[j]!=s[len(s)-j]:
      flag=1
      break
  if flag==0:
    print(len(s))
    exit()
  else:
    flag=0
    continue

### FIXED CODE ###

s=str(input())
flag=0
for i in range(1,len(s)):
  s=s[:len(s)-2]
  for j in range(len(s)//2):
    if s[j]!=s[len(s)//2+j]:
      flag=1
      break
  if flag==0:
    print(len(s))
    exit()
  else:
    flag=0
    continue
x >= 0
x <= 9
a >= 0
a <= 9

if x < a 
  print(0)
else
  print(10)

### FIXED CODE ###

i = list(map(int, input().split()))
if i[0] < i[1]:
  print("0")
else:
  print("10")
h,w=map(int,input().split())
if k>=2 and s>=2:
	k=h//2
	s=h%2
	print(k*w+s*((w+1)//2))
else:
	print("1")

### FIXED CODE ###

h,w=map(int,input().split())
if h>=2 and w>=2:
	k=h//2
	s=h%2
	print(k*w+s*((w+1)//2))
else:
	print("1")
s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
AX = []
AY = []
for a in C:
    if a>0 and a%2==0 and C[a]>0:
        AX.append(C[a])
    elif a%2==1 and C[a]>0:
        AY.append(C[a])
cntx = sum(AX)
dpx = [[0 for _ in range(2*cntx+1)] for _ in range(len(AX)+1)]
dpx[0][cntx] = 1
if cntx>0:
    dpx[1][cntx-AX[0]] = 1
    dpx[1][cntx+AX[0]] = 1
    for i in range(2,len(AX)+1):
        for j in range(2*cntx+1):
            if j-AX[i-1]>=0:
                dpx[i][j] = dpx[i-1][j-AX[i-1]+cntx]
                if j+AX[i-1]<=cntx:
                    dpx[i][j] = max(dpx[i][j],dpx[i-1][j+AX[i-1]+cntx])
            elif j+AX[i-1]<=cntx:
                dpx[i][j] = dpx[i-1][j+AX[i-1]+cntx]
cnty = sum(AY)
dpy = [[0 for _ in range(2*cnty+1)] for _ in range(len(AY)+1)]
dpy[0][cnty] = 1
if cnty>0:
    dpy[1][cnty-AY[0]] = 1
    dpy[1][cnty+AY[0]] = 1
    for i in range(2,len(AY)+1):
        for j in range(2*cnty+1):
            if j-AY[i-1]>=0:
                dpy[i][j] = dpy[i-1][j-AY[i-1]+cnty]
                if j+AY[i-1]<=cnty:
                    dpy[i][j] = max(dpy[i][j],dpy[i-1][j+AY[i-1]+cnty])
            elif j+AY[i-1]<=cnty:
                dpy[i][j] = dpy[i-1][j+AY[i-1]+cnty]
if C[0]-cntx<=x<=C[0]+cntx and dpx[len(AX)][x-C[0]+cntx]==1 and -cnty<=y<=cnty and dpy[len(AY)][y+cnty]==1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
AX = []
AY = []
for a in C:
    if a>0 and a%2==0 and C[a]>0:
        AX.append(C[a])
    elif a%2==1 and C[a]>0:
        AY.append(C[a])
cntx = sum(AX)
dpx = [[0 for _ in range(2*cntx+1)] for _ in range(len(AX)+1)]
dpx[0][cntx] = 1
if cntx>0:
    dpx[1][cntx-AX[0]] = 1
    dpx[1][cntx+AX[0]] = 1
    for i in range(2,len(AX)+1):
        for j in range(-cntx,cntx+1):
            if -cntx<=j-AX[i-1]:
                dpx[i][j+cntx] = dpx[i-1][j-AX[i-1]+cntx]
                if j+AX[i-1]<=cntx:
                    dpx[i][j+cntx] = max(dpx[i][j+cntx],dpx[i-1][j+AX[i-1]+cntx])
            elif j+AX[i-1]<=cntx:
                dpx[i][j+cntx] = dpx[i-1][j+AX[i-1]+cntx]
cnty = sum(AY)
dpy = [[0 for _ in range(2*cnty+1)] for _ in range(len(AY)+1)]
dpy[0][cnty] = 1
if cnty>0:
    dpy[1][cnty-AY[0]] = 1
    dpy[1][cnty+AY[0]] = 1
    for i in range(2,len(AY)+1):
        for j in range(-cnty,cnty+1):
            if -cnty<=j-AY[i-1]:
                dpy[i][j+cnty] = dpy[i-1][j-AY[i-1]+cnty]
                if j+AY[i-1]<=cnty:
                    dpy[i][j+cnty] = max(dpy[i][j+cnty],dpy[i-1][j+AY[i-1]+cnty])
            elif j+AY[i-1]<=cnty:
                dpy[i][j+cnty] = dpy[i-1][j+AY[i-1]+cnty]
if C[0]-cntx<=x<=C[0]+cntx and dpx[len(AX)][x-C[0]+cntx]==1 and -cnty<=y<=cnty and dpy[len(AY)][y+cnty]==1:
    print("Yes")
else:
    print("No")