Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import deque

N = int(input())
color = [0]*(N+1)
q = deque()

u, v, w = map(int, input().split())
finded = set([u, v])
color[v] = (color[u] + (w % 2)) % 2

for _ in range(N-2):
    u, v, w = map(int, input().split())
    if u in finded:
        finded.add(v)
        color[v] = (color[u] + (w % 2)) % 2
    elif v in finded:
        finded.add(u)
        color[u] = (color[v] + (w % 2)) % 2
    else:
        q.append([u, v, w])

while len(q) != 0:
    u, v, w = q.popleft()
    if u in finded:
        finded.add(v)
        color[v] = (color[u] + (w % 2)) % 2
    elif v in finded:
        finded.add(u)
        color[u] = (color[v] + (w % 2)) % 2
    else:
        q.append([u, v, w])

for i in range(1, N+1):
    print(color[i])

### FIXED CODE ###

from collections import deque

N = int(input())
tree = [dict() for _ in range(N+1)]
color = [0]*(N+1)
parent = [0]*(N+1)
for _ in range(N-1):
    u, v, w = map(int, input().split())
    w %= 2
    tree[u][v] = w
    tree[v][u] = w

que = deque([1])
while len(que) != 0:
    u = que.pop()
    Rel, c, p = tree[u], color[u], parent[u]
    for v in Rel.keys():
        if v == p:
            continue
        elif Rel[v] == 0:
            color[v] = c
        else:
            color[v] = c^1
        parent[v] = u
        que.append(v)

for c in color[1:]:
    print(c)
### BUGGY CODE ###

#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())
N,M,P=map(int,input().split())
ABC=[list(map(int,input().split())) for i in range(M)]
for i in range(M):
    ABC[i][2]=-1*(ABC[i][2]-P)

idle_max=10**9
data=[idle_max for i in range(N+1)]
data[1]=0

for i in range(N-1):
    for a,b,c in ABC:
        if data[a] != idle_max:
            data[b]=min(data[b],data[a]+c)
value=data[N]
for i in range(N):
    for a,b,c in ABC:
        if data[a] != idle_max:
            data[b]=min(data[b],data[a]+c)
if data[N]!=value:
    print(-1)
else:
    print(max(-value,0))


### FIXED CODE ###

#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())
N,M,P=map(int,input().split())
ABC=[list(map(int,input().split())) for i in range(M)]
for i in range(M):
    ABC[i][2]=-1*(ABC[i][2]-P)
data=[[] for i in range(N+1)]
for a,b,c in ABC:
    data[b].append(a)

idle_max=10**9




visited=set()
stack=[N]
while stack:
    a=stack.pop()
    for p in data[a]:
        if not p in visited:
            visited.add(p)
            stack.append(p)




data=[idle_max for i in range(N+1)]
data[1]=0
for i in range(N-1):
    for a,b,c in ABC:
        if data[a] != idle_max:
            data[b]=min(data[b],data[a]+c)
predata=copy.copy(data)
value=data[N]
for i in range(N):
    for a,b,c in ABC:
        if data[a] != idle_max:
            data[b]=min(data[b],data[a]+c)

for i in visited:
    if predata[i]>data[i]:
        break
else:
    print(max(-value,0))
    exit()
print(-1)
### BUGGY CODE ###

def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

    for i in range(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n+1):
        j = 0
        for j in range(0, m+1):
            if A[i] + B[j] > k:
                j -= 1
                break
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()

### FIXED CODE ###

def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

    for i in range(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n + 1):
        j = max(ans - i, 0)
        if j > m or A[i] + B[j] > k: continue
        while j <= m:
            if A[i] + B[j] > k:
                j -= 1
                break
            j += 1
        j = min(m,j)
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
h = [int(x) for x in input().split()]
init = 10**9
dp = [init] * N
dp[0] = 0

for i in range(1, N):
    if i - K < 0:
        dp[i] = min(dpk + abs(h[i]-hk) for dpk, hk in zip(dp[:i], h[:i]))
    else:
        dp[i] = min(dpk + abs(h[i]-hk) for dpk, hk in zip(dp[i-K:i], h[i-K:i]))

print(dp[-1])


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
h = [int(x) for x in input().split()]
dp = [0] * N

for i, hi in enumerate(h):
    if i == 0:
        continue
    if i - K < 0:
        dp[i] = min(dpk + abs(hi-hk) for dpk, hk in zip(dp[:i], h[:i]))
    else:
        dp[i] = min(dpk + abs(hi-hk) for dpk, hk in zip(dp[i-K:i], h[i-K:i]))

print(dp[-1])
### BUGGY CODE ###

x=int(input());r=range(-99,x);[i**5-x-j**5or exit(print(i,j))for i in r for j in r]

### FIXED CODE ###

x,r=int(input()),range(-99,120);[i**5-x-j**5or exit(print(i,j))for i in r for j in r]
### BUGGY CODE ###

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


def trial_division(n):
    factor = []
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    if not factor:
        return [n]
    else:
        factor.append(n)
        return factor


count = 0
for i in a:
    temp = trial_division(i)
    count += temp.count(2)

print(count)

### FIXED CODE ###

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


def trial_division(n):
    factor = []
    tmp = int(math.sqrt(n)) + 1
    for _ in range(2,tmp):
        while n % 2 == 0:
            n //= 2
            factor.append(2)
    if not factor:
        return [n]
    else:
        factor.append(n)
        return factor


count = 0
for i in a:
    temp = trial_division(i)
    count += temp.count(2)

print(count)
### BUGGY CODE ###

def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if l[i] + l[j] > l[k]:
                        cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


### FIXED CODE ###

def slove():
    import sys
    import collections
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(n-2):
        for j in range(i+1, n-1):
            ma = l[i] + l[j]
            p = bisect.bisect_left(l, ma)
            if j < p:
                cnt += p - j - 1
    print(cnt)


if __name__ == '__main__':
    slove()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
    r,c,k = map(int,input().split())
    lst = [[0]*c for _ in range(r)]
    for i in range(k):
        a,b,v = map(int,input().split())
        lst[a-1][b-1] = v
    dp = [[[0]*4 for i in range(c)] for j in range(r)]
    dp[0][0][1] = lst[0][0]
    for i in range(r):
        for j in range(c):
            x,y = i+1,j
            s = max(dp[i][j])
            if x < r:
                dp[x][y][0] = s
                if dp[x][y][1] < lst[x][y]+s:
                    dp[x][y][1] = lst[x][y]+s
            x,y = i,j+1
            if y < c:
                if dp[i][j][2] != 0:
                    if dp[x][y][3] < dp[i][j][3]:
                        dp[x][y][3] = dp[i][j][3]
                    if dp[x][y][3] < dp[i][j][2]+lst[x][y] and lst[x][y] != 0:
                        dp[x][y][3] = dp[i][j][2]+lst[x][y]
            
                if dp[i][j][1] != 0:
                    if dp[x][y][2] < dp[i][j][2]:
                        dp[x][y][2] = dp[i][j][2]
                    if dp[x][y][2] < dp[i][j][1]+lst[x][y] and lst[x][y] != 0:
                        dp[x][y][2] = dp[i][j][1]+lst[x][y]
            
                if dp[x][y][1] < dp[i][j][1]:
                    dp[x][y][1] = dp[i][j][1]
                if dp[x][y][1] < dp[i][j][0]+lst[x][y] and lst[x][y] != 0:
                    dp[x][y][1] = dp[i][j][0]+lst[x][y]

                if dp[x][y][0] < dp[i][j][0]:
                    dp[x][y][0] = dp[i][j][0]
    print(max(dp[-1][-1]))

if __name__ == '__main__':
    main()

### FIXED CODE ###

r,c,k = map(int,input().split())
lst = [[0]*c for _ in range(r)]
for i in range(k):
    a,b,v = map(int,input().split())
    lst[a-1][b-1] = v
dp0 = [[0]*c for _ in range(r)]
dp1 = [[0]*c for _ in range(r)]
dp2 = [[0]*c for _ in range(r)]
dp3 = [[0]*c for _ in range(r)]
dp1[0][0] = lst[0][0]

for i in range(r):
    for j in range(c):
        s = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j])
        x,y = i+1,j
        if x < r:
            dp0[x][y] = max(dp0[x][y], s)
            if lst[x][y]:
                dp1[x][y] = max(dp1[x][y], s+lst[x][y])
        x,y = i,j+1
        if y < c:
            dp3[x][y] = max(dp3[i][j], dp3[x][y])
            if lst[x][y]:
                dp3[x][y] = max(dp2[i][j]+lst[x][y], dp3[x][y])
            
            dp2[x][y] = max(dp2[x][y], dp2[i][j])
            if lst[x][y]:
                dp2[x][y] = max(dp2[x][y], dp1[i][j]+lst[x][y])
            
            dp1[x][y] = max(dp1[x][y], dp1[i][j])
            if lst[x][y]:
                dp1[x][y] = max(dp1[x][y], dp0[i][j]+lst[x][y])
            
            dp0[x][y] = max(dp0[x][y], dp0[i][j])
print(max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1]))
### BUGGY CODE ###

from math import floor, ceil
a, b, n = map(int, input().split())
ans = 10 ** 6 * (-1)
x = 1
while x <= n:
    tmp = floor(a * x / b) - a * floor(x / b)
    ans = max(ans, tmp)
    x = ceil((floor(a * x / b) + 1) * b / a)
print(ans)


### FIXED CODE ###

from math import floor
a, b, n = map(int, input().split())
x = min(b - 1, n)
ans = floor(a * x / b) - a * floor(x / b)
print(ans)
### BUGGY CODE ###

def main():
    from collections import Counter
    N, P = (int(i) for i in input().split())
    S = input()

    ans = 0
    if P == 5 or P == 2:
        for i in range(1):
            for j in range(1, N-i+1):
                num = int(S[i:i+j])
                if num % P == 0:
                    ans += len(S[i:i+j])
    else:
        S = S[::-1]
        d = 1
        acc = [0]*(N+1)
        for i, s in enumerate(S):
            s = int(s)
            acc[i+1] = (s * d + acc[i]) % P
            d *= 10
            d %= P
        c = Counter(acc)
        # print(acc, c)
        ans = sum(v*(v-1)//2 for v in c.values())
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from collections import Counter
    N, P = (int(i) for i in input().split())
    S = [int(s) for s in input()]

    ans = 0
    if P == 5 or P == 2:
        for i, s in enumerate(S, start=1):
            # j文字取る
            if s % P == 0:
                ans += i
    else:
        acc = [0]*(N+1)
        d = 1
        for i, s in enumerate(S[::-1], start=1):
            # print(i, s)
            acc[i] = (s * d + acc[i-1]) % P
            d *= 10
            d %= P
        c = Counter(acc)
        # print(acc, c)
        ans = sum(v*(v-1)//2 for v in c.values())
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

while True:
  try:
    s1 = input()
    s2 = input()
    lst = [[1 if s1[i] == s2[j] else 0 for i in range(len(s1))] for j in range(len(s2))]
    ans = 0
    def search(x,y,count):
      while  x < len(s2) and y < len(s1) and lst[x][y]:
        count += 1
        lst[x][y] = 0
        x += 1
        y += 1
      return count
    for i in range(len(s2)):
      for j in range(len(s1)):
        if lst[i][j]:
          ans = max(ans,search(i,j,0))
    print(ans)
  except EOFError:
    break


### FIXED CODE ###

while True:
    try:
        s1 = input()
    except EOFError:
        break
    s2 = input()
    BASE = 27
    MOD = 1000000007


    def rolling_hash(s):
        h_lst = [0]
        for c in s:
            h_lst.append((h_lst[-1] * BASE + ord(c)) % MOD)
        return h_lst


    h_lst1 = rolling_hash(s1)
    h_lst2 = rolling_hash(s2)
    length1 = len(s1)
    length2 = len(s2)

    pow_mem = [pow(BASE, i, MOD) for i in range(min(length1, length2) + 1)]


    def check(center):
        hash_set = {(h_lst1[i + center] - h_lst1[i] * pow_mem[center]) % MOD for i in range(length1 - center + 1)}
        for i in range(length2 - center + 1):
            h2 = (h_lst2[i + center] - h_lst2[i] * pow_mem[center]) % MOD
            if h2 in hash_set:return True
        return False


    left = 0
    right = min(length1, length2)
    while right > left + 1:
        center = (left + right) // 2
        if check(center):
            left = center
        else:
            right = center
    print(right if check(right) else left)
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
result = 0
for i in range(N):
    number = P[i]
    miss = 0
    for j in range(i):
        if P[i]>P[j]:
            miss = 1
            break
    if miss == 0:
        result+=1
print(result)

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
result = 0
nowmin = N
for i in range(N):
    if P[i]>nowmin:
        pass 
    else:
        result += 1
        nowmin = P[i]
print(result)
### BUGGY CODE ###

l = []
n = int(input())
for _ in range (n):
    cmd = input().split(' ')
    if cmd[0]=='insert':
        l.insert(0,int(cmd[1]))
    if cmd[0]=='delete':
        if int(cmd[1]) in l:
            l.remove(int(cmd[1]))
    if cmd[0]=='deleteFirst':
        l.pop(0)
    if cmd[0]=='deleteLast':
        l.pop(len(l)-1)
print(*l)


### FIXED CODE ###

from collections import deque
n = int(input())
l = deque()
for _ in range (n):
    cmd = input().split(' ')
    if cmd[0]=='insert':
        l.appendleft(cmd[1])  
    if cmd[0]=='delete':
        try:l.remove(cmd[1])
        except :pass
    if cmd[0]=='deleteFirst':
        l.popleft()
    if cmd[0]=='deleteLast':
        l.pop()
print(*l)
### BUGGY CODE ###

a=int(input())
tem = 1
if a == 0: #do nothing if 0
    a=1
else:
    b=input().split(" ")
    for i in range(a): #calculate until'a' number only
        tem = tem * int(b[i]) #multiply the list
    if tem> 10**18: #check exceed
        tem = -1
    print(tem)

### FIXED CODE ###

n = int(input())
b = list( map (int , input().split() ) )
b.sort()
ans = 1
for i in range(n):
    ans*=b[i]
    if ans>10**18:
      print(-1)
      exit()

print(ans)
### BUGGY CODE ###

N, K = map(int,input().split())

m = 60
L = pow(2,m)

A = list(map(int,input().split()))
A = [A[i]-1 for i in range(N)]

D = [A]
for i in range(m):
  temp = []
  for j in range(N):
    temp.append(D[i][D[i][j]])
  D.append(temp)

now = 0
for i in range(m):
  if K >> i&1 == 1:
    now = D[i][now]
print(now+1)

### FIXED CODE ###

N , K = map(int,input().split())
 
A = list(map(int,input().split()))
 
reach = [-1 for i in range(N)]
reach[0] = 0 #最初の町は0回でいく
now = 0
#loop = 1
dic ={}
dic[0] = 0
for i in range(N):
  to = A[now]-1
  if reach[to] != -1:
    ini = i+1
    #print(i,to,reach[to])
    loop = i+1 - reach[to]
    break
  if i+1 not in dic:
    dic[i+1] = to
  reach[to] = i+1
  #loop += 1
  now = to
 
 
#print(dic,reach,loop,ini)
if K < ini:
  print(dic[K]+1)
else:
  t = (ini-loop) + (K-ini)%loop
  print(dic[t]+1)
### BUGGY CODE ###

import fractions
from functools import reduce
n=int(input())
numbers=list(map(int,input().split()))
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
l=0
for i in range(n):
    l+=(lcm_list(numbers)//numbers[i])
print(l%(10**9+7))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import fractions
 
mod = 10**9+7
 
n = int(input())
a = list(map(int, input().split()))
 
div = a[0]
for i in a[1:]:
    div = div*i//fractions.gcd(div, i)

ans = 0
for i in a:
    ans += div//i

print(ans%mod)
### BUGGY CODE ###

def mmm(li):
    li[li.index(max(a))]//=2

n,m = map(int,input().split())
a=  list(map(int,input().split()))
[mmm(a) for i in range(m)]
print(sum(a))

### FIXED CODE ###

import heapq
n,m = map(int,input().split())
a=  list(map(int,input().split()))
h = list(map(lambda x:-1*x,a))
heapq.heapify(h)
for i in range(m):
    heapq.heapreplace(h,-(-h[0]//2))
print(-1*sum(h))
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
List = [0 for _ in range(N)]

for k in range(N):
  List[k] = S[:k+1].count("AC")
  
for i in range(Q):
  l , r = map(int, input().split())
  print(List[r-1]-List[l-1])

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
List = [0 for _ in range(N)]
num = 0
for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    num += 1
  List[k] = num
  
for i in range(Q):
  l , r = map(int, input().split())
  print(List[r-1]-List[l-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N = int(input())

power = 1

for x in range(1, N + 1):
    power *= x

mod = 10 ** 9
mod += 7

answer = power % mod
print(answer)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import math

N = int(input())

power = 1

mod = 10 ** 9
mod += 7

power = math.factorial(N)

print(power % mod)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in a:
    ans*=i
if ans>10**18:
    ans=-1
print(ans)

### FIXED CODE ###

n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
for i in a:
    ans*=i
    if ans>10**18:
        ans=-1
        break
    if ans==0:
        break
print(ans)
### BUGGY CODE ###

K = int(input())

list = [1,2,3,4,5,6,7,8,9]
i = 0
while len(list) != 0:
    v = list.pop(0)

    i += 1
    if i == K:
        break

    t = v%10

    if t != 0:
        list.append(10*v + (t-1))

    list.append(10*v + t)

    if t != 9:
        list.append(10*v + (t+1))


print(v)

### FIXED CODE ###

from collections import deque

K = int(input())

list = deque(range(1,10))
i = 0
for i in range(K):
    v = list.popleft()

    t = v%10

    if t != 0:
        list.append(10*v + (t-1))

    list.append(10*v + t)

    if t != 9:
        list.append(10*v + (t+1))


print(v)
### BUGGY CODE ###

n, c = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(n)]
def sumv(s):
    ret = 0
    for _, v in s:
        ret += v
    return ret
# counter clock wize till i
ccw = []
for i in range(n):
    score = sumv(sushi[:i+1]) - sushi[i][0]
    maxscore = score
    for j in range(1, n-i):
        score += sushi[n-j][1]
        maxscore = max(maxscore, score - (c - sushi[n-j][0]) - sushi[i][0])
    ccw.append(maxscore)
# clock wize till i
cw = []
for i in range(n):
    score = sumv(sushi[n-i-1:]) - (c - sushi[n-i-1][0])
    maxscore = score
    for j in range(n-i-1):
        score += sushi[j][1]
        maxscore = max(maxscore, score - sushi[j][0] - (c - sushi[n-i-1][0]))
    cw.append(maxscore)
print(max(max(ccw), max(cw), 0))


### FIXED CODE ###

n, c = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(n)]
sushi = [(0, 0)] + sushi
cclkmax = [0] * (n+1)
cumvalue = 0
for i in range(1, n+1):
    cumvalue += sushi[i][1]
    cclkmax[i] = max(cclkmax[i-1], cumvalue - sushi[i][0])
maxscore = cclkmax[n]
cum = 0
for i in range(n, 0, -1):
    cum += sushi[i][1]
    score = cclkmax[i-1] + cum - 2*(c - sushi[i][0])
    maxscore = max(maxscore, score)
clkmax = [0] * (n+1)
cumvalue = 0
for i in range(n, 0, -1):
    cumvalue += sushi[i][1]
    clkmax[i] = max(clkmax[(i+1)%(n+1)], cumvalue - (c - sushi[i][0]))
maxscore = max(maxscore, clkmax[1])
cum = 0
for i in range(1, n+1):
    cum += sushi[i][1]
    score = clkmax[(i+1)%(n+1)] + cum - 2*sushi[i][0]
    maxscore = max(maxscore, score)
print(maxscore)
### BUGGY CODE ###

from itertools import combinations
def main():
    S = input() + 'T'
    x, y = map(int, input().split())
    #データ加工
    moveX, moveY = [], []
    if S[0] == 'T': moveX.append(0)
    move ={0:moveX, 1:moveY}
    direct = 0
    step = 0
    for s in S:
        if s == 'T':
            if step > 0:
                move[direct].append(step)
                step = 0
            direct ^= 1 
        else:
            step += 1
    #判定
    if possible(x, moveX[1:], moveX[0]) and possible(y, moveY):
        print('Yes')
    else:
        print('No')


def possible(target, move, offset=0):
    Sum = sum(move)
    for k in range(len(move)//2+1):
        for c in combinations(move,k):
            moved = Sum-2*sum(c)
            if moved == abs(target-offset):
                return True
    return False


main()

### FIXED CODE ###

from collections import defaultdict
def main():
    S = input() + 'T'
    x, y = map(int, input().split())
    #データ加工
    moveX, moveY = [], []
    if S[0] == 'T': moveX.append(0)
    move ={0:moveX, 1:moveY}
    direct = 0
    step = 0
    for s in S:
        if s == 'T':
            if step > 0:
                move[direct].append(step)
                step = 0
            direct ^= 1 
        else:
            step += 1
    #判定
    if possible(x, moveX[1:], moveX[0]) and possible(y, moveY):
        print('Yes')
    else:
        print('No')


def possible(target, move, offset=0):
    l = len(move)
    dp = [defaultdict(lambda:False) for _ in range(l+1)]
    #初期化
    dp[0][0] = True
    for i,m in enumerate(move):
        for key in dp[i]:
            dp[i+1][key+m] = True
            dp[i+1][key-m] = True
    return dp[l][target-offset]


main()
### BUGGY CODE ###

def Warshall_Floyd(edges,N):
  """頂点N個のグラフ上の隣接行列edges(空欄はinfとせよ)が与えられたとき, 
  2点間の最短距離距離を隣接行列で返す"""
  for k in range(N):
    for i in range(N):
      for j in range(min(i,200)):
        if edges[i][j]>edges[i][k]+edges[k][j]: return 1
  return 0
 
import sys
from sys import stdin
input = stdin.readline
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
if Warshall_Floyd(A,N):
  print(-1)
  sys.exit()
 
ans=0
for i in range(N):
  for j in range(i):
    need=1
    for k in range(N):
      if k!=i and k!=j and A[i][j]==A[i][k]+A[k][j]:
        need=0
        break
    if need:ans+=A[i][j]
print(ans)

### FIXED CODE ###

def Warshall_Floyd(edges,N):
  """頂点N個のグラフ上の隣接行列edges(空欄はinfとせよ)が与えられたとき, 
  2点間の最短距離距離を隣接行列で返す"""
  for k, i, j in itertools.product(range(N), range(N),range(N)):
    if edges[i][j]>edges[i][k]+edges[k][j]: return 1
  return 0
 
import sys
import itertools
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
if Warshall_Floyd(A,N):
  print(-1)
  sys.exit()
 
ans=0
for i, j in itertools.product(range(N),range(N)):
  need=1
  for k in range(N):
    if k!=i and k!=j and A[i][j]==A[i][k]+A[k][j]:
      need=0
      break
  if need:ans+=A[i][j]
print(ans//2)
### BUGGY CODE ###

n = int(input())
s = input()

l = [30010] * 11
r = [-1] * 11
for i in range(n):
    c = int(s[i])
    r[c] = max(r[c], i)
    l[c] = min(l[c], i)
st = set([])
for i in range(n):
    c = int(s[i])
    for j in range(10):
        for k in range(10):
            if l[j] < i < r[k]:
                number = chr(j) + s[i] + chr(k)
                st.add(number)
print(len(st))

### FIXED CODE ###

n = int(input())
s = input()

l = [30010] * 11
r = [-1] * 11
for i in range(n):
    c = int(s[i])
    r[c] = max(r[c], i)
    l[c] = min(l[c], i)
st = set([])
for i in range(n):
    c = int(s[i])
    for j in range(10):
        for k in range(10):
            if l[j] < i < r[k]:
                number = chr(j) + s[i] + chr(k)
                st.add(number)
print(len(st))