N = gets.to_i
ss = $stdin.readlines.map(&:chomp)

ab_counts = ss.map {|s| s.scan(/AB/).length }
a_end_count = ss.select {|s| s[-1] == 'A' }.length
b_beg_count = ss.select {|s| s[0] == 'B' }.length

ans = ab_counts + a_end_count * b_beg_count
puts ans