program diverta2019c
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,l
    character(10),allocatable:: s(:)
    integer(int64):: i,j, ca, cb, cab,ans

    ca=0; cb=0; cab=0; ans=0
    read*, n
    allocate(s(n))
    do i=1,n
        read*, s(i)
    end do

    do i=1,n
        do j=1,len_trim(s(i))-1
            if (s(i)(j:j+1) == 'AB') ans=ans+1
        end do
    end do

    do i=1,n
        l = len_trim(s(i))
        if (s(i)(1:1) /= 'B' .and. s(i)(l:l) /= 'A') cycle

        if (s(i)(1:1) == 'B' .and. s(i)(l:l) == 'A') then
            cab=cab+1
        else if (s(i)(1:1) == 'B') then
            cb=cb+1
        else
            ca=ca+1
        end if
    end do
    if (ca+cb==0)then
        print'(i0)', max(ans+cab-1,0)
    else
        print'(i0)', ans+cab+min(ca,cb)
    end if


end program diverta2019c