Transaction Processing

No attempts yetTime limit1sMemory limit128 MB

Problem

Write a program that performs one of the initial steps in posting transactions to a general ledger.

The central principle of double-entry bookkeeping is that the sum of all debits must equal the sum of all credits, and this must hold for every transaction.

In this program, positive numbers represent debits and negative numbers represent credits. For example, 2.00 is a two-dollar debit and -2.00 is a two-dollar credit.

The goal of the program is to check whether each transaction balances and to report any transaction that does not.

Input

The input has two parts.

The first part is the list of general-ledger accounts: up to 100 accounts, one per line, in the format

nnnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

where nnn is a three-digit account number and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is a 1-to-30 character account name. This part ends with a record that starts with 000, which is never used as an account number.

The second part consists of 15-character records, one per line, in the format

sssnnnxxxxxxxxx

where sss is a three-digit sequence number, nnn is a three-digit account number, and xxxxxxxxx is a nine-digit amount in dollars and cents with the decimal point omitted (that is, an integer value in cents). Each record is one entry of a transaction, and a transaction consists of between two and ten entries that share the same sequence number. The entries of each transaction appear consecutively in the input. This part ends with a record whose sequence number is 000.

Output

For a transaction that balances, print nothing.

For a transaction that does not balance, print an exception report in the form

*** Transaction sss is out of balance ***
nnn xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vvvvvvv.vv
nnn xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vvvvvvv.vv
...
999 Out of Balance                 vvvvvvv.vv

where nnn is an account number, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is the corresponding account name, and vvvvvvv.vv is the amount. Format each line as: the three-digit account number, one space, the account name left-justified in a 30-character field, one space, and the amount right-justified in a 10-character field. List the entries in the order they were received in the input.

The last line of the report is one you create to make the transaction balance: it uses the special account number 999 (the suspense account) with the name Out of Balance, and its amount offsets the sum of the other entries. Print a blank line between consecutive exception reports.