class Yukicoder def initialize goo, choki, par = gets.chomp.split(' ').map(&:to_i) enemy = Hash.new(0) s = gets.chomp.split('') s.each do |i| enemy[i] += 1 end score = 0 goo_win = [goo, enemy['C']].min choki_win = [choki, enemy['P']].min par_win = [par, enemy['G']].min score += 3 * (goo_win + choki_win + par_win) goo -= goo_win choki -= choki_win par -= par_win enemy['C'] -= goo_win enemy['P'] -= choki_win enemy['G'] -= par_win goo_draw = [goo, enemy['G']].min choki_draw = [choki, enemy['C']].min par_draw = [par, enemy['P']].min score += goo_draw + choki_draw + par_draw puts score end end Yukicoder.new