let count_ab l str = 
  let tmp = ref 0 in
  for i = 0 to l - 2 do
    if String.sub str i 2 = "AB" then tmp := !tmp + 1
  done; !tmp

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let ar = Array.make n "" in
  for i = 0 to n - 1 do
    Scanf.scanf "%s\n" (fun s -> ar.(i) <- s)
  done;
  let ar' = Array.make n None in
  for i = 0 to n - 1 do
    let l = String.length ar.(i) in
    let abs = count_ab l ar.(i) in
    let a, b = (String.get ar.(i) (l-1) = 'A'), 
               (String.get ar.(i) 0 = 'B') in
    ar'.(i) <- Some (abs, a, b)
  done;
  let res = ref 0 in
  let tmp = ref 0 in
  for i = 0 to n - 1 do
    begin
      match ar'.(i) with
      | Some (abs, true, true) -> 
         ar'.(i) <- None; res := !res + abs; tmp := !tmp + 1
      | _ -> ()
    end;
    if !tmp >= 2 then res := !res + !tmp - 1;
  done;
  let aflag, bflag = ref true, ref true in
  for i = 0 to n - 1 do
    if !aflag then
      begin
        (match ar'.(i) with
         | Some (abs, true, false) ->
            ar'.(i) <- None; res := !res + abs + 1;
         | _ -> ());
        aflag := false;
      end;
    if !bflag then
      begin
        (match ar'.(i) with
         | Some (abs, false, true) ->
            ar'.(i) <- None; res := !res + abs + 1;
         | _ -> ());
        bflag := false;
      end;
  done;
  let cnta = ref 0 in
  let cntb = ref 0 in
  for i = 0 to n - 1 do
    match ar'.(i) with
    | Some (abs, true, false) ->
       res := !res + abs;
       cnta := !cnta + 1
    | Some (abs, false, true) -> 
       res := !res + abs;
       cntb := !cntb + 1
    | Some (abs, false, false) -> res := !res + abs
    | _ -> ()
  done;
  !res + (min !cnta !cntb) |> print_int
  
