#include #include #include #include #include #include #include static int const INF{100000000}; int count(auto const& map, auto const& as, int depth) { int ans{as[0]}; for(int i{}; i < depth; ++i) { if(map[i] == 1) { ans += as[i + 1]; } else { ans *= as[i + 1]; } } return ans; } void solve(auto& map, auto const& as, int max_depth, int depth, int total, int current) { if(depth == max_depth) { if(total == current) return; for(int i{max_depth - 1}; i >= 0; --i) { if(map[i] == 1) { solve(map, as, max_depth, i, total, count(map, as, i)); return; } map[i] = 0; } throw "never come"; } if(map[depth] == 0) { map[depth] = 1; if(total >= current + as[depth + 1]) { solve(map, as, max_depth, depth + 1, total, current + as[depth + 1]); } else { solve(map, as, max_depth, depth, total, current); } } else if(map[depth] == 1) { map[depth] = 2; if(total >= current * as[depth + 1]) { solve(map, as, max_depth, depth + 1, total, current * as[depth + 1]); } else { solve(map, as, max_depth, depth, total, current); } } else { map[depth] = 0; if(map[depth - 1] == 1) { solve(map, as, max_depth, depth - 1, total, current - as[depth]); } else if(map[depth - 2] == 2) { solve(map, as, max_depth, depth - 1, total, current / as[depth]); } } } int main(int, char**) { int n; std::cin >> n; int total; std::cin >> total; std::vector as(n); for(int i{}; i < n; ++i) { std::cin >> as[i]; } std::vector map(n - 1, 0); // 0: unknown, 1: plus, 2: mul solve(map, as, n - 1, 0, total, as[0]); for(auto e: map) { std::cout << (e == 1 ? '+' : '*'); } std::cout << std::endl; return 0; }