Leon has recently purchased a defective printer that won't stop printing! Once powered on, the printer immediately draws from the initial feed of paper and spews it out the front once every second.
He plans to perform actions during the printer's operation: for the action, paper will be either added to or removed from the feed at seconds since powering on the printer.
Keep in mind that the feed has a maximum capacity of paper that it can hold - additional paper forced into the feed would cause a paper jam!
However, if at any given second the printer's feed is empty, it will attempt (but fail) to continuously draw paper. As a result, the printer will rapidly overheat, causing it to quickly melt after a full second (unfortunately short-circuiting, like CCC Junior, doesn't pay).
What will become of Leon's printer?
Input Specification
The first line contains two spaced integers and , the initial paper amount and the maximum printer feed capacity, respectively.
The next line contains an integer , the number of actions to follow.
The next lines contain two spaced integers and , describing that paper was either added to or removed from the feed at seconds. Actions are listed in chronological order, and only one action can occur in a second. A negative value means that paper is to be taken away from the feed. You may assume that Leon will never remove more paper from the feed than there currently is. Note that during each second, starting from , Leon performs his action, if any, first, before the printer tries to draw from the feed.
Output Specification
When and how Leon's printer breaks. Follow the output formats shown below.
Sample Input 1
4 10
3
2 6
5 -2
8 11
Sample Output 1
The printer jams at 8 second(s).
Sample Input 2
4 10
3
2 6
5 -3
8 11
Sample Output 2
The printer melts at 8 second(s).
Comments
Does the printer print if paper is removed/added into the feed?
Yes, the printer prints while paper is removed/added to the feed.
How much paper is "spewed" out the front every second?
One piece of paper is spewed out at the end of every second.