open Printf open Scanf
open Array

let print_list f ls = List.iter (fun v -> printf "%s " @@ f v) ls; print_newline ()

(* rosetta code *)
let count_substring str sub =
  let sub_len = String.length sub in
  let len_diff = (String.length str) - sub_len
  and reg = Str.regexp_string sub in
  let rec aux i n =
    if i > len_diff then n else
      try
        let pos = Str.search_forward reg str i in
        aux (pos + sub_len) (succ n)
      with Not_found -> n
  in
  aux 0 0

let () = scanf " %d" @@ fun n ->
  let arr = init n (fun _ -> scanf " %s" @@ fun s -> s)
  in
  let kba,kbx,kxa,krest = fold_left (fun (kba,kbx,kxa,krest) s ->
    let bx = s.[0] = 'B' in
    let xa = s.[String.length s-1] = 'A' in
    let ab = bx && xa in
    let kba = if ab then kba + 1 else kba in
    let kbx = if not ab then (
      if bx then kbx+1 else kbx
    ) else kbx in
    let kxa = if not ab then (
      if xa then kxa+1 else kxa
    ) else kxa in
    let krest = krest + count_substring s "AB"
    in
    (kba,kbx,kxa,krest)
  ) (0,0,0,0) arr in
  let hoge =
    if kba >= 1 then (
      let pair_ba = kba - 1 in
      let res = 0 in
      let res,kbx =
        if kbx > 0 then res+1,kbx-1 else res,kbx in
      let res,kxa =
        if kxa > 0 then res+1,kxa-1 else res,kxa in
      pair_ba + res + min kbx kxa
    ) else (
      min kbx kxa
    ) in
  print_int @@ krest + hoge


