class Integer def combination(k) self.factorial/(k.factorial*(self-k).factorial) end def permutation(k) self.factorial/(self-k).factorial end def factorial return 1 if self == 0 (1..self).inject(:*) end end class Yukicoder def initialize hash = Hash.new(0) 26.times do |i| hash[(97+i).chr] = gets.to_i end answer = 1 %w(d e h l o r w).each do |ch| if ch == 'l' max_val = 0 1.upto(hash[ch]-2) do |n| max_val = [max_val, (hash[ch]-n).combination(2) * n].max end answer *= max_val elsif ch == 'o' max_val = 0 1.upto(hash[ch]-1) do |n| max_val = [max_val, (hash[ch]-n) * n].max end answer *= max_val else answer *= hash[ch] end end puts answer end end Yukicoder.new