n = gets.not_nil!.to_i num = gets.not_nil!.to_i64 a = Array(Int32).new(n) { gets.not_nil!.to_i } dp = Array(Set(Int64)).new(n + 1) { Set(Int64).new } dp[n] = Set{num} n.downto(1) do |i| x = a[i - 1].to_i64 dp[i].each do |y| dp[i - 1] << (y - x) if y - x >= 0 dp[i - 1] << (y // x) if y % x == 0 end end raise "Assertion failed: dp[0] should contain 0" unless dp[0].includes?(0) ans = "" x = 0_i64 (1..n).each do |i| y = a[i - 1].to_i64 if dp[i].includes?(x + y) x += y ans += '+' else x *= y ans += '*' end end puts ans[1..]