s=$<.map(&:chomp)

ab = s.map {|ss| c_s(ss)}.inject(:+)

s.map! do |m|
    mm = 0
    mm += 1 if m.end_with?('A')
    mm += 2 if m.start_with?('B')
    mm
end
a = s.count(1)
b = s.count(2)
a_b = s.count(3)
if a == 0 && b == 0 && a_b > 0
    puts ab + a_b - 1
else 
    puts ab + [a,b].min
end