peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]

EDGE = [[] for _ in range(N+1)]

for a,b in AB:
  EDGE[a].append(b)
  EDGE[b].append(a)
  
def dfs(p,u,d):
  if u == N:
    return True
  
  if d == 0:
    return False
  
  ans = False
  
  for v in EDGE[u]:
    if v == u:
      continue
      
    ans |= dfs(u,v,d-1)
  
  return ans

ans = dfs(-1,1,2)

s = 'POSSIBLE' if ans else 'IMPOSSIBLE'

print(s)
# Judge status: Wrong Answer
a,b=map(str, input().split())
c=a+b
d=int(c)
for i in range(1,317):
  if d==i**2:
    print('Yes')
  else:
    print('No')
# Judge status: Accepted
from collections import Counter
N = int(input())
A = [int(i) for i in input().split(" ")]
count = Counter(A)
S = sum(A)
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split(" "))
    n = count[B]
    count[B] -= n
    count[C] += n
    S = S - B*n + C*n
    print(S)
# Judge status: Accepted
#import numpy as np
N = int(input())
#x1,y1,x2,y2= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
S= str(input())
x=0
max=0
for i in S:
    if i == 'I':
        x+=1
        if x>=max:
            max=x
    elif i== 'D':
        x-=1

print(max)
# Judge status: Accepted
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect
from decimal import Decimal


a,b=map(str,input().split())
b=Decimal(b)
a=int(a)
p=list(str(a*b))
ans=''
for i in p:
    if i=='.':
        break
    ans+=i
print(ans)
# Judge status: Accepted
[H, N] = [int(x) for x in input().split()]
A = list(map(int, input().split()))
count = 0
for x in A:
    count += x
print("Yes" if count >= H else "No")
# Judge status: Accepted
sx,sy,tx,ty=map(int,input().split())

ans='U'*(ty-sy)+'R'*(tx-sx)+'D'*(ty-sy)+'L'*(tx-sx)
ans+='L'+'U'*(ty-sy+1)+'R'*(tx-sx+1)+'D'
ans+='R'+'D'*(ty-sy+1)+'L'*(tx-sx+1)+'U'

print(ans)
# Judge status: Accepted
N, Y = map(int, input().split())

man = -1
gosen = -1
sen = -1

for i in range(N+1):
  for j in range(N+1):
    k = N-i-j
    if Y == i*10000+j*5000+k*1000 and k >= 0:
      print(i, j, k)
      exit()
      
print(-1, -1, -1)
# Judge status: Accepted
import bisect
N=int(input())
A=list(map(int,input().split(' ')))
A_sort = sorted([A[i]-i for i in range(N)])
ans = 0
for n,i in enumerate(A):
    ans += bisect.bisect_right(A_sort,-(n+i))-bisect.bisect_left(A_sort,-(n+i))
print(ans)
# Judge status: Wrong Answer
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())
    
    if (b+c)*k>10**18 or (a+c)*k > 10**18:
        print("Unfair")
    elif a == b == c:
        print(0)
    elif k % 2==0:
        print(-1*((b+c)-(a+c)))
    else:
        print((b+c)-(a+c))
    

if __name__=="__main__":
    main()
# Judge status: Accepted
n,k=list(map(int,input().split()))
h=list(map(int,input().split()))

l=sorted(h,reverse=True)

ans=0
for i in range(k,n):
  ans=ans+l[i]
print(ans)
# Judge status: Wrong Answer
w, a, b = map(int, input().split())
print(max(0, (b - a) - w))
# Judge status: Accepted
N, M=map(int, input().split())
info=[]
for _ in range(N):
  a, b=map(int, input().split())
  info.append([a,b])

info.sort(key=lambda x:x[0])
ans=0
for a, b in info:
  if M>=b:
    ans+=a*b
    M-=b
  elif M<b and M>0:
    ans+=a*M
    break
  else:
    break
print(ans)
# Judge status: Accepted
import fractions
a,b=map(int,input().split())
gcd=fractions.gcd(a,b)
print((a//gcd)*b)
# Judge status: Wrong Answer
N,M=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(M)]
zero=["0"]*N
for i in range(M):
  order=li[i][0]-1
  if zero[order]=="0" or zero[order]==li[i][1]:
    zero[order]=li[i][1]
  else:
    print(-1)
    exit()
a=[str(s) for s in zero]
a2="".join(a)
a3=int(a2)
a4=str(a3)
if len(a2)!=len(a4):
  print(-1)
  exit()
print(a2)
# Judge status: Accepted
def main():
    N = int(input())
    W = [int(x) for x in input().split()]
    w = sum(W)
    mini = w
    for i in range(N):
        a = sum(W[i+1:])
        b = w - a
        k = abs(a - b)
        if mini > k:
            mini = k
    print(mini)


if __name__ == "__main__":
    main()
# Judge status: Accepted
A, B = list(map(int, input().split()))

total = max(
    A + A - 1,
    B + B - 1,
    A + B,
)

print(total)
# Judge status: Wrong Answer
import sys

def main(args):
    h, n = map(int,input().split())
    
    magic = [0]*n
    for i in range(n):
        dam, mp = map(int,input().split())
        magic[i] = (dam, mp)
    
    damage = [float('inf')]*(2*10**4)
    damage[0] = 0
    for i in range(2*h):
        for m in magic:
            dam, mp = m
            damage[i] = min(damage[i-dam]+mp, damage[i])
    
    print(min(damage[h:]))

if __name__ == '__main__':
    main(sys.argv[1:])
# Judge status: Accepted
n=int(input())
for i in range(9):
    a,b=divmod(n,9-i)
    if a<=9 and b==0:
        print("Yes")
        break
else:
    print("No")
# Judge status: Accepted
from math import*

A,B,H,M = map(int, input().split())

print((A*A+B*B-2*A*B*cos((M*11/360-H/6)*pi))**.5)
# Judge status: Accepted
s_nums = input()
ans = 0
for nums in s_nums:
    if int(nums) == 1:
        ans += 1
print(ans)
# Judge status: Accepted
A, B, C = map(int, input().split())
print(C - min(A - B, C))
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

cnt = [0] * 1001
res = 0
for v in a:
    if v <= 1000:
        cnt[v] += 1
    else:
        res += 1

for i in range(1, 1001):
    if cnt[i] < i:
        res += cnt[i]
    elif cnt[i] > i:
        res += cnt[i] - i

print(res)
# Judge status: Accepted
s=input()
print("Yes"if s[0]!=s[1] or s[1]!=s[2] else "No")
# Judge status: Accepted
import collections

K = int(input())
Q = collections.deque([i for i in range(1, 10)])
for _ in range(K):
  x = Q.popleft()
  r = x%10
  if r != 0: Q.append(x*10 + r - 1)
  Q.append(x*10 + r)
  if r != 9: Q.append(x*10 + r + 1)
print(x)
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n):
    if p[i] == i + 1:
        if i != n - 1:
            p[i], p[i + 1] = p[i + 1], p[i]
            ans += 1
        else:
            p[i], p[i - 1] = p[i - 1], p[i]
            ans += 1

print(ans)
# Judge status: Wrong Answer
#ABC 132 B
n = int(input())
p= [int(j) for j in input().split()]
ans =0
for i in range(0,n-3+1):
    if p[i:i+3][1] ==sorted(p[i:i+3])[1]:
        ans+=1
        print(p[i:i+3])
print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))

Alice=0
Bob=0
a.sort()
#print(a)
h=len(a)
for i in range(h):
    if len(a)>0:
        Alice+=a[-1]
        del a[-1]
        h-=1
    if len(a)>0:
        Bob+=a[-1]
        del a[-1]
        h-=1
print(Alice-Bob)
# Judge status: Accepted
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    X = int(input())

    result = (X // 11) * 2
    X %= 11

    if X == 0:
        print(result)
    elif X <= 6:
        print(result + 1)
    else:
        print(result + 2)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
N = int(input())
S = str(input())

if ')' in S:
  for i in range(N):
    if S[N-1-i] == ')':
      n = N-i
      break
  lc = S[:n].count('(')
  rc = S[:n].count(')')
  if rc > lc:
    S = (rc-lc) * '(' + S

s = S.index('(')
l = 0
r = 0
for i in range(s, len(S)):
  if S[i] == '(':
    l += 1
  else:
    r += 1
if l > r:
  S = S + (l-r) * ')'
  
print(S)
# Judge status: Wrong Answer
s = input()

z_g = 0
z_k = 0
o_g = 0
o_k = 0

for i in range(len(s)-1):
    if i % 2 == 0:
        if s[i] == "0":
            z_g += 1
        else:
            o_g += 1
    else:
        if s[i] == "0":
            z_k += 1
        else:
            o_k += 1

if (z_g + o_k) > (z_k + o_g):
    print(z_k + o_g)
else:
    print(z_g + o_k)
# Judge status: Accepted
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,c = mi()
ans = c - (a-b)
if ans < 0:
    print(0)
else:
    print(ans)
# Judge status: Accepted
K = int(input())
S = input()
if len(S) <= K:
  print(S)
else:
  print(S[:K]+"...");
# Judge status: Wrong Answer
a,b,c,d,e,f = input()
if c == d or e == f:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
x = "T"+input()+"S"
ans = len(x)-2
s = t = 0
for i in x:
    if i=="S":
        ans -= min(s,t)*2
        if t: s = t = 0
        s += 1
    else: t += 1
print(ans)
# Judge status: Accepted
S = input()
li = ["SU","SAT","FRI","THU","WED","TUE","MON","SUN"]
print(li.index(S))
# Judge status: Wrong Answer
k,x =list(map(int, input().split()))
if [k*500>=x] :
 print('yes')
 exit()
else:
 print('no')
# Judge status: Accepted
n,m=map(int,input().split())
p=10**9+7
n,m=min(n,m),max(n,m)
if m-n>=2:
    print(0)
elif m-n==1:
    ans=1
    for i in range(m):
        ans=ans*(i+1)%p
    for i in range(n):
        ans=ans*(i+1)%p
    print(ans%p)
else:
    ans=1
    for i in range(n):
        ans=ans*(i+1)%p
    print(2*ans*ans%p)
# Judge status: Accepted
N, X = map(int, input().split())
L = list(map(int, input().split()))

ans = 1
d = 0
for l in L:
  if d + l <= X:
    d += l
    ans += 1
  else:
    break

print(ans)
# Judge status: Accepted
N=int(input())
P=list(input().split())
Q=list(input().split())

import itertools
arr = list(map(lambda x: ('').join(list(map(str,x))),list(itertools.permutations(range(1,N+1)))))

print(abs(arr.index(('').join(P))-arr.index(('').join(Q))))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

def solve(N, A):
  if not A or A[0] != 1:
    print(-1)
    return

  prev = 1
  rt = 1
  for a in A[1:]:
    if a > prev * 2:
      print(-1)
      return
    rt += (prev * 2 - a) % (prev * 2)
    prev = a

  print(rt)
# Judge status: Wrong Answer
N=int(input())
a=list(map(int,input().split()))
S=sum(a[1:])
SS=a[0]
mi=abs(S-SS)
for i in range(1,N-1):
    if mi>abs((S-a[i])-(SS+a[i])):
        S-=a[i]
        SS+=a[i]
        mi=abs(mi-2*a[i])
print(mi)
# Judge status: Wrong Answer
from fractions import gcd
from functools import reduce
lcm=lambda x,y:x//gcd(x,y)*y
MOD=10**9+7

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

c=sum(pow(a,MOD-2,MOD) for a in A)//MOD
l=reduce(lcm,A)//MOD

print(c*l//MOD)
# Judge status: Accepted
N = int(input())
while True:
    if len(set(str(N))) == 1:
        break
    N += 1

print(N)
# Judge status: Accepted
from collections import defaultdict

N = int(input())
if not N == 1:
    counter = defaultdict(lambda: 0)
    for e in list(map(int, input().split())):
        counter[e] += 1
    answer = 0
    for i in counter:
        ball_count = counter[i]
        if i > ball_count:
            answer += ball_count
        elif i < ball_count:
            answer += ball_count - i
    print(answer)
else:
    if not 1 == int(input()):
        print(1)
    else:
        print(0)
# Judge status: Accepted
s = input()[::-1]
t = input()[::-1]
x = ""
for i in range(0,len(s)-len(t)+1):
    if x == "": x = s[i:i+len(t)]
    else:x = x[1:] + s[i+len(t)-1]
    flag = True
    for j in range(len(t)):
        if x[j] == "?" or x[j] == t[j]: continue
        else: flag = False
    if flag:
        s = (s[:i] + t + s[i+len(t):])[::-1]
        print(s.replace("?", "a"))
        exit()
print("UNRESTORABLE")
# Judge status: Accepted
# 2020/08/10
# AtCoder Beginner Contest 086 - B

# Input
a, b = input().split()
ab = int(a + b)

# Calc
if ab ** (1/2) - int(ab ** (1/2)) == 0:
    ans = 'Yes'
else:
    ans = 'No'

# Output
print(ans)
# Judge status: Accepted
S = input()
T = input()
print(sum(s != t for s, t in zip(S, T)))
# Judge status: Accepted
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    money = 1000
    for i in range(1, N):
        if A[i-1] < A[i]:
            v = money//A[i-1]  # 株数
            money -= v*A[i-1]
            money += v*A[i]
    print(money)


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math


def main():
    a, b, x = [int(x) for x in input().split()]
    area = x / a
    if area < a*b/2:
        theta = math.pi/2 - math.atan(2*area/b/b)
    else:
        theta = math.atan((2*b-2*area/a)/a)
    theta_deg = math.degrees(theta)
    print(theta_deg)


if __name__ == "__main__":
    main()
# Judge status: Accepted
A = list(map(int, input().split()))
if A.count(5) == 2 and A.count(7) == 1:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
n=int(input())
if n<=999:
  print("ABD")
else:
  print("ABD")
# Judge status: Wrong Answer
n= int(input())
a = list(map(int,input().split()))
o = {}
for i in a:
    if not i in o:
        o[i] = 0
a = []
for i in o:
    a.append(i)
money = 1000
buy = 0
have = 0
for i in a:
    if i == max(a):
        money += have * i
        break
    if have == 0:
        have = money // i
        money -= i*have
        buy = i
    elif buy < i:
        money += i*have
        have = 0
print(money)
# Judge status: Accepted
N,P=map(int,input().split())
A=list(map(int,input().split()))
x,y=1,0
for a in A:
    if a%2:
        x,y=x+y,x+y
    else:
        x,y=x*2,y*2
print(y if P else x)
# Judge status: Accepted
from collections import deque
n = int(input())
a = list(map(int, input().split()))
odd = deque([])
even = deque([])
even2 = deque([])
for i in a:
    if i % 4 == 0:
        even2.append(i)
    elif i % 2 == 0:
        even.append(i)
    else:
        odd.append(i)
if len(odd)-1 <= len(even2) and len(even) == 0:
    print("Yes")
elif len(odd) <= len(even2):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, m = map(int, input().split())
h_lis = list(map(int, input().split()))
ab_lis = [list(map(int, input().split())) for _ in range(m)]
ans=[True]*n

for ab_li in ab_lis:
    #print(ab_li)
    if h_lis[ab_li[0]-1] > h_lis[ab_li[1]-1]:
        ans[ab_li[1]-1] = False
    elif h_lis[ab_li[0]-1] < h_lis[ab_li[1]-1]:
        ans[ab_li[0]-1] = False
    else:
        ans[ab_li[0]-1], ans[ab_li[1]-1] = False, False
#print(ans)
print(sum(ans))
# Judge status: Accepted
def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      cd.append(i)
      if i != n//i:
        cd.append(n//i)
    i += 1
  return cd
 
N, M = map(int, input().split())
cd = divisor(M)
cd.sort(reverse=True)
for d in cd:
  if M//d>=N:
    print(d)
    break
# Judge status: Accepted
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

b1 = [i[0] for i in c.items() if i[1] >= 4]
b2 = [i[0] for i in c.items() if i[1] >= 2]
b = b1 + b2 + [0,0]

b.sort()
print(b[-1]*b[-2])
# Judge status: Accepted
S = input()
N = len(S)

a = (N-1)//2

def isKaibun(S):
    N = len(S)
    flag = 0
    for i in range((N//2)+1):
        if S[i] != S[N-1-i]:
            flag =1
    if flag == 1:
        return False
    else:
         return True

if isKaibun(S[0:a]) == True:
    if isKaibun(S[-1:-a-1:-1]) == True:
        if isKaibun(S) == True:
            print("Yes")
            exit()
print("No")
# Judge status: Accepted
x, y, z = map(str, input().split())
print('A'+y[0]+'C')
# Judge status: Accepted
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for i in range(A+1):
    for j in range(B+1):
        res = X - 500*i - 100*j
        if res%50 == 0 and res//50 <= C and res >= 0:
            ans += 1
            
print(ans)
# Judge status: Accepted
N = int(input())
v = list(map(int,input().split()))

v.sort()
t = (v[0] + v[1])/2
for i in range(2,N):
    t = (t + v[i])/2
print(t)
# Judge status: Accepted
n = int(input())
if n%10==0:
  print(10)
else:
  ans = [char for char in str(n)]
  for i in range(0, len(ans)): 
    ans[i] = int(ans[i]) 
  print(sum(ans))
# Judge status: Accepted
n,m=map(int,input().split())
if m<2*n:
    print(m//2)
else:
    print(n+(m-2*n)//4)
# Judge status: Accepted
R,G,B=map(str,input().split())
ans="NO"
num=int(R+G+B)
if num%4==0:
    ans="YES"
print(ans)
# Judge status: Accepted
S = input()
if S[2] == S[3] and S[4] == S [5]:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
a, b, c, k = map(int, input().split())
d = k - a - b

if k < a:
	print(k)

elif a <= k <= a + b:
	print(a)

elif a + b < k <= a + b + c:
	print(a - d)
# Judge status: Accepted
N,K=map(int,input().split())
sum=0
#N面サイコロ、得点K
#K-1以下の得点ならコインを振り続ける
for i in range(1,N+1):
  target=i
  count=0
  while(target<K):
    target*=2
    count+=1
  sum+=(1/N)*(0.5**count)
print(sum)
# Judge status: Wrong Answer
import sys
a, b, c = map(int, input().split())
if a == c or b == c or a+b == c:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
A = input()
B = input()
 
if (A in B) and (len(B)-len(A)==1) and (1<=len(A)<=10) and (A.islower()) and (B.islower()):
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N = int(input())
A = list(input())

res = N
num = [0] * (N+1)
for i in range(0, N):
    num[i + 1] = num[i]
    if A[i] == 'W':
        num[i + 1] += 1
for i in range(1, N + 1):
    res = min(res, num[i] + (N - i) - (num[N] - num[i]))

print(res)
# Judge status: Wrong Answer
N,X,T=map(int,input().split())
print((N//X+1)*T)
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))
money = 1000
stack = 0

for i in range(n-1):
    if A[i] < A[i+1]:
        stack = int(money/A[i])
        money = stack*A[i+1] - stack*A[i] + money

print(money)
# Judge status: Accepted
H = int(input())
W = int(input())
N = int(input())

p = -1
if H > W:
    p = H
else:
    p = W

count = 1
result = 1
while True:
    result = count * p
    if result >= N:
        print(count)
        break
    else:
        count += 1
# Judge status: Wrong Answer
n, x, t = input().split()
n = int(n)
x = int(x)
t = int(t)

if n % x == 0:
  print((n//x)*t)
else:
  print(int((n//x)*t))
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
L = [0]
R = [0]
import fractions
def GCD(a,b):
    if a*b != 0:
        return fractions.gcd(a,b)
    else:
        return max(a,b)
for i in range(N-1):
    x = A[i]
    y = A[-i-1]
    L.append(GCD(L[i],x))
    R.append(GCD(R[i],y))
ans = 0
for i in range(N):
    x = L[i]
    y = R[-i-1]
    ans = max(GCD(x,y),ans)
print(ans)
# Judge status: Accepted
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return int(j * (j-1) / 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))
# Judge status: Wrong Answer
import heapq
n,k = map(int,input().split())
a = list(map(int,input().split()))
r = [0 for _ in range(max(a)+1)]
if len(set(a)) <= 2:
    print(0)
    exit()
for i in range(n):
    r[a[i]] += 1
t = []
for i in range(len(r)):
    if r[i]:
        t.append(r[i])
t = list(map(lambda x:-x,t))
heapq.heapify(t)
print(n+sum(t[:k]))
# Judge status: Wrong Answer
n,a,b=map(int,input().split())
x=0
if a>b:
  x=0
elif n==1 and a==b:
  x=1
else:
  x=(b-a)*(n-2)+1
print(x)
# Judge status: Wrong Answer
n=int(input())
l=[int(n) for n in input().split()]
sum=0
oc=1
for i in l:
    if i%2!=0:
        oc=0
    sum+=i
if(oc==0):
    print(0)
else:
    c=0
    while(sum%2==0 and sum>=2):
        c+=1
        sum=sum//2
    print(c)
# Judge status: Accepted
N, K = map(int, input().split())
S = list((num+1)/2 for num in map(int, input().split()))
temp = 0
ans = 0
for i in range(K):
    temp += S[i]
ans = temp
for i in range(K, N):
    temp = temp + S[i] - S[i-K]
    ans = max(ans, temp)
print(ans)
# Judge status: Wrong Answer
x = int(input())
t = int(x ** 0.5)
min_d = t * 0.5 * (t + 1)
if min_d == x:
  print(t)
elif (min_d + 2) <= x:
  print(t + 2)
else:
  print(t + 1)
# Judge status: Accepted
N=int(input())
S=input()
if S=='#'*N or S=='.'*N:
  print(0)
  exit()
rightB=0
for i in S:
  if i=='#':
    rightB+=1
rightW=N-rightB
leftB=0
leftW=0
ans=min(rightB,rightW)
for i in range(N):
  if S[i]=='.':
    leftW+=1
    rightW-=1
    d=rightW+leftB
    ans=min(ans,d)
  else:
    leftB+=1
    rightB-=1
    d=rightW+leftB
    ans=min(ans,d)
print(ans)
# Judge status: Accepted
X = input()
N = len(X)

right = 1
cnt = 0

for left in range(N - 1):
    if X[left] == 'S':
        right = max(right, left + 1)
        while right < N and X[right] != 'T':
            right += 1
        if right >= N:
            break
        if X[right] == 'T':
            # print(left, right)
            right += 1
            cnt += 1
print(N - cnt * 2)
# Judge status: Accepted
import math

n, m = map(int, input().split())
n_f = math.factorial(n)
m_f = math.factorial(m)
mod = 1000000007

if abs(n-m) > 1:
    print(0)
    exit()
if n == m:
    print((n_f * m_f * 2) % mod)
else:
    print((n_f * m_f) % mod)
# Judge status: Accepted
def main():
    # これはなに？笑
    N = int(input())
    ans = 0

    for i in range(1, N+1):
        for j in range(i, N+1, i):
            ans += j
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
M,N = list(map(int,input().split()))
s = list(map(int,input().split()))
count = 0
kiroku = 0

t = [0 for i in range(M+1)]
for i in range(M):
    t[i+1] = t[i] + (1+s[i])/2

for i in range(N,M-N+1):
    if t[i] -t[i-N] > count:
        count = t[i] -t[i-N]

print(count)
# Judge status: Accepted
N=int(input())
li=[input() for i in range(N)]

a=li.count("AC")
b=li.count("WA")
c=li.count("TLE")
d=li.count("RE")

print("AC x "+str(a))
print("WA x "+str(b))
print("TLE x "+str(c))
print("RE x "+str(d))
# Judge status: Accepted
#!/usr/bin/env python3
def main():
    from bisect import bisect, bisect_left

    N = int(input())
    A = sorted([int(x) for x in input().split()])
    B = [int(x) for x in input().split()]
    C = sorted([int(x) for x in input().split()])

    print(sum([bisect_left(A, b) * (N - bisect(C, b)) for b in B]))


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math
import itertools

K = int(input())
a = list(range(1, K + 1))
it = itertools.product(a, repeat=2)

c = 0
for i, j in it:
    g = math.gcd(i, j)
    for j in a:
        c += math.gcd(g, j)

print(c)
# Judge status: Accepted
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()

x.sort()

d = [x[i+1] - x[i] for i in range(m-1)]

d.sort()

print(sum(d[:m-n]))
# Judge status: Accepted
N,M = map(int,input().split())
ls1 = []
ls2 = []
for i in range(N):
  ls1.append(list(map(int,input().split())))
for i in range(M):
  ls2.append(list(map(int,input().split())))
for i in range(N):
  minimum = 10**18
  check = 0
  for j in range(M):
    K = abs(ls1[i][0]-ls2[j][0])+abs(ls1[i][1]-ls2[j][1])
    if K < minimum:
      minimum = K
      check = j
  print(check+1)
# Judge status: Accepted
n = int(input())
s = input()
sh = s[0:n//2]
if s == sh + sh:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
from bisect import bisect_right

N = int(input())
A = [int(input()) for _ in range(N)]

t = [-A[0]]
for a in A[1:]:
    if a <= -t[-1]:
        t.append(-a)
    else:
        t[bisect_right(t, -a)] = -a
print(len(t))
# Judge status: Accepted
import bisect
N = int(input())
A= list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
  a = bisect.bisect_left(A,b)
  c = bisect.bisect_right(C,b)
  ans += a * (len(C)-c)
print(ans)
# Judge status: Accepted
N=int(input());
a=1;
while(2*a<=N):
  a*=2
print(a)
# Judge status: Wrong Answer
N, W = map(int, input().split())
dp_pv = [0]*(W+1)

for i in range(N):
    w, v = map(int, input().split())
    #print(w,v)
    dp = [0]+[dp_pv[j+1] if w > j else max(dp_pv[j+1], dp_pv[j+2-w]+v) for j in range(W)]
    dp_pv = dp
    #print(dp)
    
print(dp[-1])
# Judge status: Accepted
n,k = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))

a = sorted(a, key = lambda x:x[0])

x = 0
for i in a:
	x += i[1]
	if x >= k:
		break
print(i[0])