def scan; gets.split.map(&:to_i); end q = ['+','-','*'] k = gets.to_i; aa = scan s = -999999999 q.repeated_permutation(k-1){|qq| e = "("*(k-1)+aa[0].to_s (k-1).times{|j| e << qq[j] << "#{aa[j+1]})" } s = [s,eval(e)].max } p s