# frozen_string_literal: true count = 0 result = 0 gets.chomp.chars.map { |i| i == 'A' }.each_with_index do |a, i| if a result += i - count count += 1 end end p result