output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: N = int(input())
  counter = 0
  end_a = 0
  start_b = 0
  start_b_end_a = 0
  for n in range(N):
      s = input()
      for i in range(len(s) - 1):
          if s[i : i + 2] == "AB":
              counter += 1
      if s[-1] == "A":
          end_a += 1
      if s[0] == "B":
          start_b += 1
      if s[-1] == "A" and s[0] == "B":
          start_b_end_a += 1
  if N == start_b_end_a:
      print(counter + min([end_a, start_b]) - 1)
  else:
      print(counter + min([end_a, start_b]))
  
problem_description: Statement
  
  Snuke received a positive integer N from Takahashi. A positive integer m is
  called a _favorite number_ when the following condition is satisfied:
  
    * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
  
  Find all favorite numbers and print the sum of those.
samples: [{"input": "8", "output": "10\n    \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n    \n\nWatch out for overflow."}]