Woburn Challenge 2002
So how is the monkeys' meeting going, you ask? Well, the Head-Monkey is quite big on food and whenever there's a meeting atop the Enchanted Tree, it is a necessity that dinner is served (pun intended). What the monkeys don't realize is that the Head-Monkey is not really a good cook. But then, how many army leaders are good cooks? The answer is, none. This time, the Head-Monkey has purchased a cookbook. The cookbook has a certain number of recipes, but any recipe may require an ingredient that must be prepared according to some other recipe! This is all quite confusing for the Head-Monkey. She wants you to tell her how much of each base ingredient she needs for her recipe.
Input Specification
The first line of input will contain a single integer,
The first line of each test case will contain
For each non-basic ingredient, a recipe for one serving of that
ingredient will follow (format: an integer
Finally, there will be an ingredient name - you are to determine the amount of each basic ingredient required to make one serving of that ingredient.
The name of each ingredient will consist of either all lowercase or all uppercase English
letters and possibly spaces.
The name of each ingredient will have at most
Output Specification
A series of lines of the form [number of servings of ingredient required, space, ingredient required], containing only basic ingredients. Output them in the same order as they were listed in the input.
Each real value in your output should have an absolute or relative error from the reference solution of no more than
Sample Input
1
10
CHEESE
milk
SAMMICH
salt
turkey
ham
egg
vinegar
MAYO
bread
2
1.5 milk
0.25 salt
5
2.2 CHEESE
1 bread
1 turkey
1 ham
0.3 MAYO
3
0.2 egg
0.1 vinegar
0.1 salt
SAMMICH
Sample Output
3.3 milk
0.58 salt
1 turkey
1 ham
0.06 egg
0.03 vinegar
1 bread
Comments