gets; tops, bottoms = Hash.new(0), Hash.new(0) gets.chomp.chars do |i| tops[i.to_s] += 1 end gets.chomp.chars do |i| bottoms[i.to_s] += 1 end print [tops["A"], bottoms["A"]].min + [tops["B"], bottoms["B"]].min