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())
  count = 0
  LastA = 0
  FirstB = 0
  LA = 0
  for i in range(0, N):
      f = input()
      count = count + f.count("AB")
      if f[0] == "B" and f[-1] == "A":
          LA = LA + 1
      elif f[0] == "B":
          FirstB = FirstB + 1
      elif f[-1] == "A":
          LastA = LastA + 1
  count = count + LA
  if LastA == 0 and FirstB == 0:
      count = count - 1
  elif FirstB >= LastA:
      count = count + LastA
  else:
      count = count + FirstB
  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"}]