def calc(total, current, list, point) if point == list.size if total == current return "" else return nil end end # + next_current = current + list[point] if next_current <= total if next_calc = calc(total, next_current, list, point + 1) return "+" + next_calc end end # * next_current = current * list[point] if next_current <= total if next_calc = calc(total, next_current, list, point + 1) return "*" + next_calc end end return nil end n = gets.to_i total = gets.to_i list = gets.split.map &:to_i puts calc(total, list[0], list, 1)