def find_ab(str)
    return str.include?('A') || str.include?('B')
end

count = 0
N = (gets).to_i
strs = []
N.times do
    strs << gets.strip.gsub(/[^AB]+/, "-")
end
#puts strs

strs.map! { |str| str.gsub(/AB/) { count += 1; "" } }
#puts strs

strs.select! { |a| (a.length > 0) && find_ab(a) }
strs.sort!

# 別に律義にくっつけてみる必要もなく、先頭と末尾を見れば
# 何個できそうかわかる
n_b_ = 0
n__a = 0
n_b_a = 0
strs.each do |str|
    if str=~/^B.*A$/ then
        n_b_a += 1
    elsif str=~/^B/ then
        n_b_ += 1
    elsif str=~/A$/ then
        n__a += 1
    end
end

ct = [n_b_, n__a].min
count += ct
n_b_ -= ct
n__a -= ct

1.upto(n_b_a) do |nba|
    if (n_b_ > 0) then
        count += 1
        n_b_ -= 1
    elsif (nba < n_b_a) then
        n_b_a -= 1
        count += 1
    end
    if (n__a > 0) then
        count += 1
        n__a -= 1
    elsif (nba < n_b_a) then
        n_b_a -= 1
        count += 1
    end
end

puts count
