import sys from collections import defaultdict def add_poly(a, b): res = defaultdict(int) for deg in a: res[deg] += a[deg] for deg in b: res[deg] += b[deg] return res def multiply_poly(a, b): res = defaultdict(int) for deg_a, coeff_a in a.items(): for deg_b, coeff_b in b.items(): res[deg_a + deg_b] += coeff_a * coeff_b return res def derivative(poly): res = defaultdict(int) for deg, coeff in poly.items(): if deg == 0: continue res[deg - 1] += coeff * deg return res def parse_expression(s, i): poly, i = parse_term(s, i) while i < len(s) and s[i] == '+': i += 1 term_poly, i = parse_term(s, i) poly = add_poly(poly, term_poly) return poly, i def parse_term(s, i): poly, i = parse_factor(s, i) while i < len(s) and s[i] == '*': i += 1 factor_poly, i = parse_factor(s, i) poly = multiply_poly(poly, factor_poly) return poly, i def parse_factor(s, i): if s[i] == 'd' and i + 1 < len(s) and s[i+1] == '{': i += 2 expr_poly, i = parse_expression(s, i) if i >= len(s) or s[i] != '}': raise ValueError("Missing closing }") i += 1 derived = derivative(expr_poly) return derived, i elif s[i] == 'x': poly = defaultdict(int) poly[1] = 1 return poly, i + 1 elif s[i].isdigit(): num = int(s[i]) poly = defaultdict(int) poly[0] = num return poly, i + 1 else: raise ValueError(f"Unexpected character at {i}: {s[i]}") def main(): input = sys.stdin.read().split() N = int(input[0]) d = int(input[1]) S = input[2] poly, _ = parse_expression(S, 0) result = [] for degree in range(d + 1): result.append(str(poly.get(degree, 0))) print(' '.join(result)) if __name__ == '__main__': main()