S = gets.chomp puts (0 ... S.size).select{|i| S[i] == ?A }.each_with_index.inject(0){|sum,(j,i)| sum + (j - i) }