Under construction

Still being built. Things may change

Slot Machine

Time limit2sMemory limit1024 MB

Summary
Given a table of winning combinations with prizes and m machine results, find the net change in capital when each game costs 10 rubles.
Level

Easy2 of 10

Topics
Hash map, Implementation
Solved
No attempts yet

Problem

A new slot machine was recently installed in a game arcade in one of the remote corners of our country. It works simply: insert a token (costing 10 rubles) and pull the lever, after which four digits appear on the screen. So each game on the machine costs 10 rubles.

A table of winning combinations determines whether an attempt paid out. Afanasy wants to try the new machine, but he is weak at mental arithmetic, so he asked you for help.

Write a program that computes how Afanasy's capital changed over the evening. You may assume Afanasy has enough money to buy tokens for all of his attempts.

Input

The first line contains nn (1≤n≤10001 \le n \le 1000), the number of entries in the winning table. Each of the next nn lines contains two values: cic_i, the combination, and wiw_i, the prize for it. No combination appears in the table more than once. cic_i is exactly four digits, and 1≤wi≤10000001 \le w_i \le 1000000.

The next line contains mm (1≤m≤10001 \le m \le 1000), the number of times Afanasy tried his luck. Each of the following mm lines contains the combination that appeared on the machine.

Output

Print the change in Afanasy's capital over these mm games on the machine.

Examples1

  1. Example 1

    Input
    2
    9999 2
    0001 3
    4
    0101
    0001
    9999
    0001
    
    Expected output
    -32