integer N
character(10) S
integer AB
integer CA,BC
integer BCA
integer Hosei
integer L
read*,N
AB=0;CA=0;BC=0;BCA=0
do i=1,N
  read*,S
  L=LEN_TRIM(S)
  do j=2,L
    if(S(j-1:j)=="AB")AB=AB+1
  end do
  if(S(1:1)=="B")BC=BC+1
  if(S(L:L)=="A")CA=CA+1
  if(S(1:1)=="B".and.S(L:L)=="A")BCA=BCA+1
end do

Hosei=0
if(BC==CA.and.BC==BCA)Hosei=0

print"(i0)",AB+min(BC,CA)-Hosei

end