// yukicoder: No.265 数学のテスト // 2019.4.19 bal4u #include #include #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { int n = 0; int c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } void ins(char *s) { do *s = gc(); while (*s++ > ' '); *--s = 0; } void out(long long n) { int i; char ob[50]; if (!n) pc('0'); else { if (n < 0) pc('-'), n = -n; i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10; while (i--) pc(ob[i]); } } char S[50005]; int N; int d; char *factor(long long *k, int *i, char *s) { int n = 0; long long t = 1, a; while (*s) { if (*s == 'x') s++, n++; else if (isdigit(*s)) { a = 0; while (isdigit(*s)) { a = a * 10 + (*s++ & 0xf); } t *= a; } else if (*s == '*') s++; else break; } *k = t, *i = n; return s; } void parse(long long *x, char *s) { int i; long long y[11]; char *p; memset(x, 0, sizeof(long long)*(d+1)); while (*s) { if (*s == 'd') { int max = 1, t = 1; s += 2, p = s++; while (*s) { if (*s == '{') { t++; if (t > max) max = t; } else if (*s == '}') { if (--t == 0) { if (max < 2000) { *s = 0; parse(y, p); for (i = 1; i <= d; i++) { if (y[i] != 0) x[i-1] += y[i]*i; } } s++; break; } } s++; } } else if (*s == 'x' || isdigit(*s)) { long long k; s = factor(&k, &i, s); x[i] += k; } else if (*s == '+') s++; } } int main() { int i; long long x[11]; N = in(), d = in(); ins(S); parse(x, S); out(x[0]); for (i = 1; i <= d; i++) pc(' '), out(x[i]); pc('\n'); return 0; }