A local company, "DVDs R Us", needs your help with a stock-management system. They sell DVDs online from a local warehouse and need to know, at any moment, how many DVDs of each title they have in stock.
Each DVD title has a stock code and is allocated a certain amount of storage space in the warehouse. The more popular a title is, the more space it is allocated. DVDs are continually being sold and replaced, so the company needs a system that tracks how many of each title remain in stock.
Given the starting stock for several titles and a list of sale and restock transactions for each, report the final number of DVDs in stock for every title.
The input describes several DVD titles. The data for one title is given as follows:
S or R), a space, and a positive integer less than $1000$.
S is a sale: the number tells how many DVDs were sold. If the sale is for more than the current stock, only the DVDs currently in stock are sold (the stock cannot go below $0$).R is a restock: the number tells how many DVDs are added. If this would raise the stock above the maximum $M$, the extra items are sent back (the stock cannot exceed $M$).The input ends with a line containing a single # in place of a stock code; do not process this title.
For each DVD title, print its stock code, a single space, and the number of DVDs in stock after all of its transactions have been applied.