n, t = read_line.split.map(&.to_i64) a = Array(Int64).new(n) { read_line.to_i64 } # Initialize DP table dp = Array(Array(Bool)).new(n + 1) { Array(Bool).new(t + 1, false) } dp[n][t] = true # Fill DP table backwards (n - 1).downto(0) do |i| (1..t).each do |j| if dp[i + 1][j] if j - a[i] >= 0 dp[i][j - a[i]] = true end if j % a[i] == 0 dp[i][j // a[i]] = true end end end end unless dp[0][0] puts -1 else ans = "" s = a[0] (1...n).each do |i| if s + a[i] <= t && dp[i + 1][s + a[i]] ans += '+' s += a[i] elsif s * a[i] <= t && dp[i + 1][s * a[i]] ans += '*' s *= a[i] else raise "Invalid state" end end raise "Invalid result" unless s == t puts ans end