Millie's Restaurant

On most days, the staff of Millie's Restaurant prepares one or more servings of one or more dishes before the restaurant is opened for business. At the end of the day, each serving (which was prepared fresh on that day but not sold) is individually packaged, labeled, and placed in the freezer. The label identifies the dish and the day on which it was prepared.

When a customer orders a particular dish, the waitress will first try to fill the customer's order from the servings which were prepared fresh on that day. If a serving of a particular dish is not found among the freshly prepared dishes, then it will be taken out of the freezer. In that case, if there are servings with different preparation dates in the freezer, the serving taken out of the freezer is chosen to be one that has been in the freezer for the longest time.

The input contains, respectively, day-by-day listings of dishes prepared and sold, separately by a -1 on a line by itself. Here is an example:

1 10 Southern Fried Chicken
1 14 Alaskan King Crab
1 15 Vegetarian Lasagna
2 3 Vegetarian Lasagna
2 2 Southern Fried Chicken
4 4 Vegetarian Lasagna
4 7 Alaskan King Crab
4 8 Southern Fried Chicken
7 6 Vegetarian Lasagna
-1
1 8 Southern Fried Chicken
2 4 Alaskan King Crab
2 3 Southern Fried Chicken
3 2 Vegetarian Lasagna
3 10 Alaskan King Crab
5 3 Alaskan King Crab
5 2 Southern Fried Chicken
5 15 Vegetarian Lasagna

The input has such format as follows.

In columns 1..3 the day of preparation (or sale) is right-justified. The days are numbered starting at 1. The largest number of days is 999.

Column 4 is blank.

In columns 5..6 the number of servings of a dish is right-justified. The largest number of servings that can appear on one line is 99.

Column 7 is blank.

In columns 8-37, the name of a dish prepared (or sold) is left-justified.

The days on successive lines will be in non-decreasing order (which means increasing, with possible repetitions).

In the prepared dishes there will be at least one entry for day 1.

There may be days on which no dish was prepared but some dishes were sold (days 3 and 5 in the above example).

There may be days on which no dish was sold but some dishes were prepared (day 4 in the above example).

There may be days of total inactivity, such as day 6 in the above example.

You may assume that all servings that appear in the sold dishes were actually present (either as freshly prepared or as frozen dishes) on the day of sale.

No dish will appear more than once within the span of one day.

There is no specific limit on the number of different dishes that may appear in the prepared dishes, but at no time will the number of different dishes (whether freshly prepared or frozen) exceed 20.

There is no explicit limit on the number of lines in the input, except for limits that can be deduced from previously stated limits.

The largest day number in the prepared dishes may be less than, equal to, or greater than that in the sold dishes.

The output will be a sequence of daily reports on the freezer's contents. The output corresponding to the above input is listed below.

Problem 8 by team x

Frozen dishes at the end of day 1:

Dish Prepared on day Quantity

Alaskan King Crab 1 14
Southern Fried Chicken 1 2
Vegetarian Lasagna 1 15

Frozen dishes at the end of day 2:

Dish Prepared on day Quantity

Alaskan King Crab 1 10
Southern Fried Chicken 1 1
Vegetarian Lasagna 1 15
2 3

Frozen dishes at the end of day 3:

Dish Prepared on day Quantity

Southern Fried Chicken 1 1
Vegetarian Lasagna 1 13
2 3

Frozen dishes at the end of day 4:

Dish Prepared on day Quantity

Alaskan King Crab 4 7
Southern Fried Chicken 1 1
4 8
Vegetarian Lasagna 1 13
2 3
4 4

Frozen dishes at the end of day 5:

Dish Prepared on day Quantity

Alaskan King Crab 4 4
Southern Fried Chicken 4 7
Vegetarian Lasagna 2 1
4 4

Frozen dishes at the end of day 6:

Dish Prepared on day Quantity

Alaskan King Crab 4 4
Southern Fried Chicken 4 7
Vegetarian Lasagna 2 1
4 4

Frozen dishes at the end of day 7:

Dish Prepared on day Quantity

Alaskan King Crab 4 4
Southern Fried Chicken 4 7
Vegetarian Lasagna 2 1
4 4
7 6
End of problem 8 by team x

Starting with day 1, the output will contain the report for each day, through the last day of the period, which is either the last day in the prepared dishes , or the last day in the sold dishes, whichever occurred later.

For each day, the daily report will begin with the following four lines:

one blank line (there are no other blank lines in the output),

one line which identifies the day;

the day number is right-justified in a field of width 4 following the word "day";

there is no blank between the day number and the colon which follows it;

a header line,

a line of 50 equal signs.

The line of equal signs will be followed by a list of the dishes of which there are currently servings in the freezer, along with the day on which those servings were prepared, and the number of servings.

The dishes will be listed in lexicographic order under each day.

No dish name will appear more than once under one day.

There may be servings of a dish which were prepared on different days. (In the above example, on day 4, there are servings of Southern Fried Chicken which were prepared on days 1 and 4, and servings of Vegetarian Lasagna which were prepared on days 1, 2, and 4.) In this case the information about days of preparation and numbers of servings will be listed in increasing order of the preparation day, without repeating the name of the dish (the name of the dish appears only on the first line for that particular dish).

Under one dish, no preparation day will appear more than once.

The names of the dishes will be left-justified in columns 1..30.

The preparation days will be right-justified and aligned with the field headers (see the formatting template shown below).

Pay close attention to every detail of the output, such as wording and punctuation, upper/lower case variations and number of blank spaces. A few lines of the above output are reproduced here with a formatting template:

     1         2         3         4         5

12345678901234567890123456789012345678901234567890
Frozen dishes at the end of day 3:

Dish Prepared on day Quantity

Southern Fried Chicken 1 1
Vegetarian Lasagna 1 13
2 3

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1214