Jeju Chocolate Guard
Time limit1sMemory limit512 MB
After each eating event, print the remaining chocolate total in a base set by the previous total's ones digit, then list the kinds with nonzero counts sorted by count.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Sorting
- Solved
- No attempts yet
Problem
Last week, a teacher who visited Jeju Island hid Jeju chocolates in the refrigerator and has been eating them in secret.

Photo 1. A photo of the inside of the teacher's actual refrigerator
Sharp-eyed students noticed and stole some of the chocolates! The teacher wants to write the number of remaining chocolates on a sticky note so that students stop eating them. Students could change the number, so the teacher will write it according to a specific rule.
There are 5 kinds of chocolate: Hallabong (H), tangerine (T), Baengnyeoncho (C), kiwi (K), and green tea (G).
The rule for writing the remaining count is as follows.
- On the first line, write the total number of remaining chocolates, followed directly by
7H(a word that renders the Korean counter 개 in ASCII characters).- Write the total in the base equal to the ones digit of the total from the previous step.
- If the ones digit of the previous total is 0 or 1, write it in decimal.
- On the second line, write the letter for each kind in order of remaining count, largest first, with no spaces.
- Do not write the letter for a kind with 0 remaining.
- If several kinds have the same count, the one whose letter comes first alphabetically goes first.
- If the total remaining count is 0, write
NULL.
Write a program that prints the counts to put on the sticky note.
Input
The first line contains the remaining counts of each kind , , , , . , , , , are the remaining counts of Hallabong, tangerine, Baengnyeoncho, kiwi, and green tea chocolates, respectively.
The second line contains the number of times chocolates are eaten, .
From the third line through line , each line gives the number of each kind eaten in one eating event: , , , , . These are the numbers of Hallabong, tangerine, Baengnyeoncho, kiwi, and green tea chocolates eaten.
Output
Print the output in the format described in the problem, using a total of lines.
Constraints
- The sum of eaten chocolates of each kind is guaranteed to be less than or equal to the initial count of that kind.