xs={} readlines.map(&:to_i).each.with_index {|n,i| xs[(97+i).chr] = n } ans = xs['h'] * xs['e'] * xs['w'] * xs['r'] * xs['d'] def c2(n) n*(n-1)/2 end def o(n) (n/2) * (n - n/2) end def l(n) m = 0 for k in 1..n m = [c2(n-k) * k, m].max end m end ans *= o(xs['o']) ans *= l(xs['l']) p ans