The problem of finding the next term of a given sequence of numbers is usually proposed in QI tests. We want to generate the N terms of a sequence from a given codification of the sequence. Let S = (Si)i∈IN denote a sequence of real numbers whose i-order term is Si. We codify a constant sequence with the following operator: S = [n] meaning that Si = n ∀i ∈ IN, where n ∈ ZZ. We also define the following operators on a given sequence of numbers S = (Si)i∈IN: V = [m + S] meaning that Vi = { m , i = 1 Vi−1 + Si−1 , i > 1 ; V = [m ∗ S] meaning that Vi = { m ∗ S1 , i = 1 Vi−1 ∗ Si , i > 1 ; where m ∈ IN. For example we have the following codifications: [2 + [1]] = 2, 3, 4, 5, 6 · · · [1 + [2 + [1]]] = 1, 3, 6, 10, 15, 21, 28, 36 · · · [2 ∗ [1 + [2 + [1]]]] = 2, 6, 36, 360, 5400, 113400 · · · [2 ∗ [5 + [−2]]] = 10, 30, 30, −30, 90, −450, 3150 · · · Given a codification, the problem is to write the first N terms of the sequence.
The input file contains several test cases. For each of them, the program input is a single line containing the codification, without any space, followed by an integer N (2 ≤ N ≤ 50).
For each test case, the program output is a single line containing the list of first N terms of the sequence. Examples Input Output [1+[2+[1]]] 5 1 3 6 10 15 [2*[1+[2+[1]]]] 6 2 6 36 360 5400 113400
範例輸入 1
[2+[1]] 3 [2*[5+[-2]]] 7
範例輸出 1
2 3 4 10 30 30 -30 90 -450 3150
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.