Supermarket bill X12575


Statement
 

pdf   zip

thehtml

Write a program that, provided a price table, computes the bill of a shopping basket.

Input

The input has one or more cases separated by an empty line. Each case consists of a price table and a shopping basket. The price table begins with a non negative integer n and after that n pairs, formed by a product name and price, follow. The shopping basket consists of a non negative integer m followed by m pairs formed by the number of purchased units and the product name. We assume all product names in the shopping basket are in the price table. All product names consist of a word of lowercase letters. All quantities (prices and purchased units) are non negative integers.

Output

For each case, the program has to print in a line the cost of the shopping basket. See the examples below.

Public test cases
  • Input

    5
    milk 1 potato 2 bread 1 beer 1 wine 3
    4
    2 wine 3 potato 4 milk 2 bread 
    
    3
    butter 2 ham 3 coke 1
    2
    5 coke 2 ham
    
    4
    butter 2 ham 3 bread 1 wine 3
    4
    2 bread  3 butter 1 wine 1 ham 
    
    

    Output

    18
    11
    14
    
  • Information
    Author
    Language
    English
    Official solutions
    Python
    User solutions
    Python