N = gets.chomp.to_i
texts = []
count = 0
right_hand = 0
left_hand = 0
double_hand = 0
N.times do |i|
    hands = [0,0]
    text = gets.chomp
    count += text.scan("AB").length
    text = text.split("").map(&:to_s)
    text = [text.first,"X",text.last]
    if text.last == "A"
        if text.first == "B"
            double_hand += 1
        else
            right_hand += 1
        end
    elsif text.first == "B"
        left_hand += 1
    end
end


left_hand += double_hand/2
right_hand += double_hand/2
count += double_hand/2
double_hand = double_hand%2


if left_hand >= right_hand
    count += right_hand
    left_hand = left_hand - right_hand
    if double_hand >= left_hand
        count += left_hand
        double_hand = double_hand - left_hand
        count += double_hand/2
    else
        count += double_hand
    end
else
    count += left_hand
    right_hand = right_hand - left_hand
    if double_hand >= right_hand
        count += right_hand
        double_hand = double_hand - right_hand
        count += double_hand/2
    else
        count += double_hand
    end
end
p count

