output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      R G B N
attempt: n = int(input())
  s = [input() for i in range(n)]
  
  ans = 0
  A = 0
  B = 0
  BA = 0
  for i in s:
      ans += i.count("AB")
      if i[0:1] != "B" and i[-1:] == "A":
          A += 1
      elif i[0:1] == "B" and i[-1:] != "A":
          B += 1
      elif i[0:1] == "B" and i[-1:] == "A":
          BA += 1
  
  # print(ans)
  # print(A,B,BA)
  
  while 1:
      if BA == 0 or A == B:
          break
      if A >= B:
          B += 1
      else:
          A += 1
      BA -= 1
  # print(A,B,BA)
  if A == 0 and B == 0:
      BA -= 1
  print(ans + min(A, B) + BA)
  
problem_description: Statement
  
  Snuke has come to a store that sells boxes containing balls. The store sells
  the following three kinds of boxes:
  
    * Red boxes, each containing R red balls
    * Green boxes, each containing G green balls
    * Blue boxes, each containing B blue balls
  
  Snuke wants to get a total of exactly N balls by buying r red boxes, g green
  boxes and b blue boxes. How many triples of non-negative integers (r,g,b)
  achieve this?
samples: [{"input": "1 2 3 4", "output": "4\n    \n\nFour triples achieve the objective, as follows:\n\n  * (4,0,0)\n  * (2,1,0)\n  * (1,0,1)\n  * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]