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

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

  if b > 0
    b -= 1
    res += 1
  end
end

puts res
