[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let countAB (s: string) =
    let t = s.Replace("AB", "")
    (s.Length - t.Length) / 2

[<EntryPoint>]
let main _ =
    let N = read int
    let SS = List.init N (fun _ -> read string)
    let xa =
        List.filter (fun (x: string) ->
            not (x.StartsWith("B")) && x.EndsWith("A")) SS
        |> List.length
    let bx =
        List.filter (fun (x: string) ->
            x.StartsWith("B") && not (x.EndsWith("A"))) SS
        |> List.length
    let ba =
        List.filter (fun (x: string) ->
            (x.StartsWith("B")) && x.EndsWith("A")) SS
        |> List.length
    let inc = List.sumBy countAB SS

    let m = min xa bx
    let d = abs (xa - bx)
    let n = min d ba

    if (xa, bx) = (0, 0) then
        printfn "%i" (inc + ba - 1)
    else
        inc + m + n + (ba - n)
        |> printfn "%i"
    0