output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      s_1
      \vdots
      s_N
attempt: N = int(input())
  word = []
  num = []
  a = []
  count = 0
  type_A = 0
  type_B = 0
  type_C = 0
  for i in range(N):
      word.append(input())
  for i in range(len(word)):
      text = word[i]
      AB = word[i].count("AB")
      count += AB
      if text[0] == "B" and text[-1] == "A":
          type_C += 1
      elif text[-1] == "A":
          type_A += 1
      elif text[0] == "B":
          type_B += 1
  num.append(type_A)
  num.append(type_B)
  num.append(type_C)
  a = sorted(num)
  if a[0] == type_C:
      print(a[0] * 2 + a[1] - a[0] + count)
  else:
      k = type_C - a[0]
      m = max(type_A - a[0], type_B - a[0])
      if k > m and m != 0:
          print(a[0] * 2 + k + count)
      elif k > m and m == 0:
          print(a[0] * 2 + k - 1 + count)
      elif k < m or k == m:
          print(a[0] * 2 + k + count)
  
problem_description: Statement
  
  Snuke has N strings. The i-th string is s_i.
  
  Let us concatenate these strings into one string after arranging them in some
  order. Find the maximum possible number of occurrences of `AB` in the
  resulting string.
samples: [{"input": "3\n    ABCA\n    XBAZ\n    BAD", "output": "2\n    \n\nFor example, if we concatenate `ABCA`, `BAD` and `XBAZ` in this order, the\nresulting string `ABCABADXBAZ` has two occurrences of `AB`.\n\n* * *"}, {"input": "9\n    BEWPVCRWH\n    ZZNQYIJX\n    BAVREA\n    PA\n    HJMYITEOX\n    BCJHMRMNK\n    BP\n    QVFABZ\n    PRGKSPUNA", "output": "4\n    \n\n* * *"}, {"input": "7\n    RABYBBE\n    JOZ\n    BMHQUVA\n    BPA\n    ISU\n    MCMABAOBHZ\n    SZMEHMA", "output": "4"}]