class Yukicoder def initialize l = gets.chomp.split.map(&:to_i) box = [] l.each_with_index do |a, i| box << 2 * (a + l[(i+1)%l.size]) end r, b, y = gets.chomp.split.map(&:to_i) answer = 0 box.sort.zip([r,b,y].sort.reverse).each do |a| answer += a[0] * a[1] end puts answer end end Yukicoder.new