Under construction

Still being built. Things may change

Babbling Brooks

Interview

Time limit1sMemory limit128 MB

Summary
Simulate a sequence of splits and joins on a list of streams and print the resulting flows after each split divides flow by a percentage and each join merges neighbors.
Level

Easy3 of 10

Topics
Implementation, Simulation, Array
Solved
No attempts yet

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 mm streams, labelled 11 to mm 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 11, or two streams may rejoin, reducing the total number of streams by 11. 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 100100 streams.

Input

The first line contains nn, the initial number of streams at some high altitude. The next nn 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 00 and 100100, 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 11 through mm, each rounded to the nearest integer (rounding a value of exactly 0.50.5 up), separated by single spaces on one line.

Examples1

  1. Example 1

    Input
    3
    10
    20
    30
    99
    1
    50
    88
    3
    88
    2
    77
    
    Expected output
    5 55