a = gets.chomp.split(" ") b = gets.chomp.split(" ") c = gets.chomp.split(" ") aa = a.map(&:to_i) bb = b.map(&:to_i) cc = c.map(&:to_i) h = { "A" => aa[0], "B" => bb[0], "C" => cc[0]} w = { "A" => aa[1], "B" => bb[1], "C" => cc[1]} hh = h.sort { |(key1, val1),(key2, val2)| val2 <=> val1 } ww = w.sort { |(key1, val1),(key2, val2)| val1 <=> val2 } lank = 30 previous = 0 score = {"A" => 0, "B" => 0, "C" => 0} hh.each { |key, val| if previous > val then lank -= 10 end previous = val score[key] = lank } lank2 = 4 previous2 = 0 score2 = {"A" => 0, "B" => 0, "C" => 0} ww.each { |key, val| if previous2 < val then lank2 -= 1 end previous2 = val score2[key] = lank2 } score3 = score.merge(score2){|key, v0, v1| v0 + v1 } score4 = score3.sort { |(key1, val1),(key2, val2)| val2 <=> val1 } puts score4[0][0] puts score4[1][0] puts score4[2][0]