This page is still under construction.

Parts of this page are still being built. What you see may change.

Exercise

Interview

Time limit1sMemory limit128 MB

Summary
For each machine, multiply each exercise level's energy rate by its duration and sum the totals per person.
Level

Easy2 of 10

Topics
Simulation, Implementation, Array
Solved
No attempts yet

Problem

A gym has several exercise machines, and each machine offers a number of levels. Harder levels burn more energy per minute than easier ones. If a person exercises at level ℓ\ell for dd minutes, the energy used is Eℓ×dE_\ell \times d, where EℓE_\ell is the energy burned per minute at level ℓ\ell. Your task is to compute the total energy each person uses while working out on a machine.

Input

The input consists of several scenarios. Each scenario describes one machine and the people who exercise on it.

Each scenario begins with an integer nn (0<n<100 < n < 10), the number of levels on the machine. The next nn lines give the energy burned per minute at each level: the first line is level 1, the second is level 2, and so on.

The people who used the machine follow. Each person is given on one line as their name (a single word of 2 to 10 letters, of which only the first may be uppercase) and an integer ee (0<e≤500 < e \le 50), the number of exercises they performed, separated by a space. The next ee lines each give one exercise as its level and its duration dd in minutes, separated by a space.

The list of people for a machine ends with a line # 0, which must not be processed.

The input ends with a scenario whose nn is 0; this scenario must not be processed.

Output

Print one section per machine. Number the machines starting from 1. For each machine, first print a line Machine k (where kk is the machine number), then one line for each person who used that machine, in the order they appear in the input. Each person's line contains their name, a space, and the total energy they burned across all of their exercises.

Examples1

  1. Example 1

    Input
    3
    10
    20
    30
    Bill 3
    1 5
    2 20
    1 5
    Jason 2
    1 10
    3 30
    # 0
    2
    50
    25
    Susan 4
    1 5
    2 20
    1 5
    2 15
    Li 2
    2 20
    1 60
    # 0
    0
    
    Expected output
    Machine 1
    Bill 500
    Jason 1000
    Machine 2
    Susan 1375
    Li 3500