Honest politicians

In a distant country, judges are busy trying to find out how much money
several politicians have earned as the result of some money movements.
There are three kinds of transactions:

- R name number: Politician name receives number money (from some
  unknown bank).

- G name number: Politician name gives number money (to some unknown
  relative).

- P name1 number name2: Politician name1 pays number money to politician
  name2, where name1 and name2 are different.

Could you please compute the final earnings of every politician?

Input

Input consists of several cases. Each case begins with a natural number
r. Follow between 1 and 10⁴ transactions. Every case ends with “END”.
You can assume that r is between 1 and the number of different names in
the case, that all the names are strings made up of an uppercase letter
followed by between 1 and 10 lowercase letters, and that all given
numbers are natural numbers between 1 and 10⁵.

Output

For every case, print r rows with the name and the final money of every
politician. Names should be alphabetically sorted by columns. Every
column has to be as narrow as possible, with names aligned to the left,
money aligned to the right, and at least one space separating them.
Separate columns with a vertical bar surronded by two spaces. The last
column may be partially empty: always leave those empty positions at the
bottom of the column. Print a line with 40 ‘’ after every case. Take a
look at the sample output to exactly follow its format. Note that no
line should end with any space.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:49:21.688Z

© Jutge.org, 2006–2026.
https://jutge.org
