output_description: Print the minimum number of elements that needs to be removed so that a will
  be a good sequence.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      a_1 a_2 ... a_N
attempt: import sys
  from collections import defaultdict, Counter
  from itertools import product, groupby, count, permutations, combinations
  from math import pi, sqrt, ceil, floor
  from collections import deque
  from bisect import bisect, bisect_left, bisect_right
  from string import ascii_lowercase
  from functools import lru_cache, reduce
  from operator import xor
  from heapq import heappush, heappop
  
  INF = float("inf")
  sys.setrecursionlimit(10**7)
  
  # 4近傍（右, 下, 左, 上）
  dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]
  
  
  def inside(y: int, x: int, H: int, W: int) -> bool:
      return 0 <= y < H and 0 <= x < W
  
  
  def ceil(a, b):
      return (a + b - 1) // b
  
  
  YES = "Yes"
  NO = "No"
  
  
  def check(x, nums):
      x = abs(x)
      dp = [False] * (x + 1)
      dp[0] = True
      for y in nums:
          tmp = [False] * (x + 1)
          for i in range(len(dp)):
              if i + y < len(tmp):
                  tmp[i + y] |= dp[i]
              if i - y >= 0:
                  tmp[i - y] |= dp[i]
          dp = tmp
      return dp[x]
  
  
  def solve(s, x, y):
      type_num = [(k, len(list(g))) for k, g in groupby(s)]
      if s[0] == "F":
          x -= type_num[0][1]
          type_num.pop(0)
  
      h, v = [], []
      now = 0
      for t, n in type_num:
          if t == "F":
              if now == 0:
                  h.append(n)
              else:
                  v.append(n)
          else:
              if n % 2 != 0:
                  now = (now + 1) % 2
      return YES if check(x, h) and check(y, v) else NO
  
  
  def main():
      s = input()
      x, y = map(int, input().split())
  
      print(solve(s, x, y))
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  You are given a sequence of positive integers of length N, a = (a_1, a_2, ...,
  a_N). Your objective is to remove some of the elements in a so that a will be
  a **good sequence**.
  
  Here, an sequence b is a **good sequence** when the following condition holds
  true:
  
    * For each element x in b, the value x occurs exactly x times in b.
  
  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are
  good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
  
  Find the minimum number of elements that needs to be removed so that a will be
  a good sequence.
samples: [{"input": "4\n    3 3 3 3", "output": "1\n    \n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good\nsequence.\n\n* * *"}, {"input": "5\n    2 4 1 4 2", "output": "2\n    \n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good\nsequence.\n\n* * *"}, {"input": "6\n    1 2 2 3 3 3", "output": "0\n    \n\n* * *"}, {"input": "1\n    1000000000", "output": "1\n    \n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\n* * *"}, {"input": "8\n    2 7 1 8 2 8 1 8", "output": "5"}]