n=gets.chomp.to_i
s=[]
n.times do
  s.push(gets.chomp)
end
ed_a=0
ft_b=0
ryouhou=0
count=0
for i in 0..n-1 do
  slen=s[i].length
  ft=s[i][0]
  ed=s[i][slen-1]
  if ed=="A" && ft=="B"
    ryouhou+=1
  elsif ed=="A"
    ed_a+=1
  elsif ft=="B"
    ft_b+=1
  end
  for cha in 0..slen-2
    count+=1 if s[i][cha]=="A" && s[i][cha+1]=="B"
  end
end
sa=(ed_a-ft_b).abs
tasu=0
puts "count:#{count}"
if ryouhou==0
  tasu=ed_a>ft_b ? ft_b : ed_a
else
  if ed_a>0 ||ft_b>0
    tasu=ryouhou/2+1+(ed_a>ft_b ? ft_b : ed_a)
  else
    tasu=ryouhou/2+(ed_a>ft_b ? ft_b : ed_a)
  end
end

puts count+tasu