#include #include #include #include #include #include using namespace std; int n, d; string s; int getDegree(int idx) { if (s[idx] != 'x') { return 0; } int degree = 1; while(idx < n - 2) { if (s[idx + 1] == '*' && s[idx + 2] == 'x') { degree++; idx += 2; } else { break; } } return degree; } int main() { cin >> n >> d; cin >> s; s += "+"; vector coefficient(d + 1, 0); n = s.size(); int depth = 0; int product = 1; int degree = 0; for (int i = 0; i < n; i++) { // printf("i %d %c\n", i, s[i]); if (isdigit(s[i])) { product = s[i] - '0'; if (s[i + 1] == '*') { i++; continue; } } else if (s[i] == 'd') { i++; // { depth++; } else if (s[i] == 'x') { int degree_now = getDegree(i); degree = degree_now - depth; if (degree >= 0) { for (int i = 0; i < depth; i++) { product *= degree_now - i; } } else { product *= 0; } // printf("degrees %d %d %d\n", degree, degree_now, product); i += (degree_now - 1) * 2; continue; } else { // + } if (s[i] == '}') { depth--; } if (isdigit(s[i - 1]) || s[i - 1] == 'x') { // printf("add %d %d\n", degree, product); coefficient[degree] += product; product = 1; } } } for (int i = 0; i <= d; i++) { cout << coefficient[i]; if (i != d) { cout << " "; } else { cout << endl; } } return 0; }