output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      s_1
      \vdots
      s_N
attempt: # C問題
  N = int(input())
  B = 0
  A = 0
  BA = 0
  count = 0
  for i in range(N):
      s = str(input())
      slist = list(s)
      slen = len(slist)
      flag = 0
      abflag = 0
      j = 0
      for j in range(slen):
          if j == 0:
              if slist[0] == "B":
                  flag = 1
              elif slist[0] == "A":
                  abflag = 1
              else:
                  pass
          elif j == slen - 1:
              if slist[-1] == "A":
                  if flag == 1:
                      flag = 3
                  else:
                      flag = 2
              elif slist[-1] == "B":
                  if abflag == 1:
                      count += 1
              else:
                  pass
          else:
              if slist[j] == "A":
                  abflag = 1
              elif slist[j] == "B":
                  if abflag == 1:
                      count += 1
                      abflag = 0
                  else:
                      abflag = 0
              else:
                  abflag = 0
  
      if flag == 1:
          B += 1
      elif flag == 2:
          A += 1
      elif flag == 3:
          BA += 1
  
  if BA >= 1:
      count += BA - 1
  
  if B >= 1 and BA >= 1:
      count += 1
      if A >= 1:
          count += 1
          count += min((A - 1), (B - 1))
  elif A >= 1 and BA >= 1:
      count += 1
  elif A >= 1 and B >= 1:
      count += min(A, B)
  print(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"}]