gets t=gets.to_i a=gets.split.map &:to_i d=(0..n=a.size-1).map{[]} d[n][t]=1 n.downto(2){|i|1.upto(t){|x|d[i-1][x]=d[i][x+a[i]]||d[i][x*a[i]]}} x=a[0] 1.upto(n){|i|f=d[i][y=x+a[i]];print f ??+:?*;x=f ?y:x*a[i]}