A series of streams runs down the side of a mountain. The mountainside is very rocky, so the streams split and rejoin many times. At the foot of the mountain, several streams emerge as rivers. Your job is to compute how much water flows in each river.
At any given elevation there are $m$ streams, labelled $1$ to $m$ from left to right. As we proceed down the mountainside, one stream may split into a left fork and a right fork, increasing the total number of streams by $1$, or two streams may rejoin, reducing the total number of streams by $1$. After a split or a rejoining occurs, the streams are renumbered consecutively from left to right. There is always at least one stream, and there are never more than $100$ streams.
The first line contains $n$, the initial number of streams at some high altitude. The next $n$ lines give the flow in each stream from left to right. Proceeding down the mountainside, several split or join locations are encountered.
Each split location is described by three lines:
99 (to indicate a split)Each join location is described by two lines:
88 (to indicate a join)The flow from both joined streams is combined. After the last split or join location, a single line containing 77 marks the end of input.
Determine how many streams emerge at the foot of the mountain and what the flow is in each. Output the flow in rivers $1$ through $m$, each rounded to the nearest integer (rounding a value of exactly $0.5$ up), separated by single spaces on one line.