e-Market

No attempts yetTime limit1sMemory limit128 MB

Problem

Hakodate opened a commodity exchange market. To take part, a dealer sends an order over the Internet holding four fields: the dealer's name, the type of the order (buy or sell), the name of the commodity, and the quoted price.

A deal is made only when the price of a sell order is lower than or equal to the price of a buy order. The price of the deal is the mean of the two quoted prices, rounded down to the nearest integer. To rule out dishonest deals, a sell order and a buy order from the same dealer never trade with each other.

The market keeps a list of the orders that have not traded yet, and processes each new order like this.

  • A new sell order trades with the buy order that has the highest price among the buy orders in the list that satisfy the conditions. If several buy orders share that price, the earliest one trades.
  • A new buy order trades with the sell order that has the lowest price among the sell orders in the list that satisfy the conditions. If several sell orders share that price, the earliest one trades.

Once a deal is made, both orders leave the list. When no order in the list satisfies the conditions, the new order joins the end of the list and waits.

The market opens at 7:00 and closes at 22:00 every day. Every order still in the list at closing time is cancelled, and the system stores every order it received that day.

Write a program that reports the activity of the market. The report has two parts. For each commodity it gives the lowest, the average, and the highest price among the successful deals. For each dealer it gives the amount the dealer paid and the amount the dealer received.

Input

The input holds several data sets, and each data set is the record of one day.

The first line of a data set holds an integer nn (n<1000n < 1000), the number of orders in the record. Each of the next nn lines describes one order as the name of the dealer, the type of the order, the name of the commodity, and the quoted price, separated by single space characters.

The name of a dealer consists of capital letters and is less than 10 characters long. The type of an order is the string BUY or SELL. The name of a commodity is a single capital letter. The quoted price is a positive integer less than 1000.

The orders in a record appear in the order they were received, so the first line of a record is the oldest order.

The end of the input is a line holding a single zero.

Output

The output for each data set has two parts, separated by a line holding two hyphen characters (--).

The first part covers commodities. For each commodity, print its name and then the lowest, the average, and the highest price among the successful deals for it, separated by single space characters. The average price is rounded down to the nearest integer. Print only the commodities that had at least one deal, in alphabetical order.

The second part covers dealers. For each dealer, print the name and then the amount the dealer paid and the amount the dealer received, separated by single space characters. Print every dealer who sent an order, including one who never traded, in lexicographic order of the names.

After the output for a data set, print a line holding ten hyphen characters (----------).