V = gets.split.take(4).map(&:to_i) $dp = {} def f(v, a, b, c) $dp[[v,a,b,c]] ||= if v < 0 1.0/0 elsif v == 0 0 else [a, b, c].map{|d| f(v - d, a, b, c) }.min + 1 end end p [*1..30].combination(3).inject(1.0/0){|r, (a, b, c)| [r, V.map{|v|f(v, a, b, c)}.sum].min }