N = gets.to_i

a = 0
b = 0
ab = 0
res = 0

N.times do
  s = gets.chomp
  if s[0] == 'B' && s[-1] == 'A'
    ab += 1
  elsif s[0] == 'B'
    b += 1
  elsif s[-1] == 'A'
    a += 1
  end
  (0...(s.length)).each do |i|
    if s.slice(i, 2) == 'AB'
      res += 1
    end
  end
end


if a > 0
  while a > 0 do
    a -= 1
    res += ab
    ab = 0

    if b > 0
      b -= 1
      res += 1
    end
  end
else
  if ab >= 2
    res += ab-1
    if b > 0
      res += 1
    end
  elsif ab >= 1
    if b > 0
      res += 1
    end
  end
end

puts res
