Babbling Brooks

No attempts yetTime limit1sMemory limit128 MB

Problem

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.

Input

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:

  • a line containing 99 (to indicate a split)
  • a line containing an integer, the number of the stream that is split
  • a line containing an integer between $0$ and $100$, the percentage of the split stream's flow that goes to the left fork (the rest goes to the right fork)

Each join location is described by two lines:

  • a line containing 88 (to indicate a join)
  • a line containing an integer, the number of the stream that is rejoined with the stream to its right

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.

Output

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.