n = gets.to_i
hs = Hash.new(0)
res = 0
n.times do
  s = gets.chomp
  pr = s[0]
  su = s[-1]
  res += s.scan("AB").size
  if pr + su == "BA"
    hs["BA"] += 1
  elsif su == "A"
    hs[".*A"] += 1
  elsif pr == "B"
    hs["B.*"] += 1
  end
end

cnt = [hs[".*A"], hs["BA"], hs["B.*"]].min
res += 2 * cnt
hs[".*A"] -= cnt
hs["BA"] -= cnt
hs["B.*"] -= cnt

res += hs["BA"] + [hs[".*A"], hs["B.*"]].min
puts res