Willson the Canada Goose is like any other Canada goose - he likes to eat grass. But, as anyone knows, there are different types of grass (e.g. green, blue, white, corn). Additionally, some humans like to feed geese with other foodstuffs (e.g. bread, pizza, hot dogs).
Each food type can provide energy to Willson or drain it away if it's unhealthy. Willson's energy can become negative. Willson must use up one unit of energy in order to move one meter. Willson cannot move if he has zero or negative energy, but he can still eat. You know the energy values of food types - the food type is named and has an energy value of .
Willson sees food items in front of him. The food type of item is and the item is located meters away from Willson's initial location. Willson will eat any food item that he encounters.
How many food items can Willson eat?
Input Specification
The first line of input will contain .
lines of input will follow. The line will contain a string and an integer . All are pairwise unique.
The next line of input will contain .
lines of input will follow. The line will contain a string and an integer . It is guaranteed that is equal to some .
All strings will be at most 10 characters long and will only contain lowercase English letters.
It is guaranteed that .
Output Specification
Output a single integer, the number of food items that Willson can eat.
Sample Input
3
grass 5
bread 10
metal -100
5
bread 5
grass 0
grass 6
bread 10
metal 9
Sample Output
4
Explanation for Sample Output
Willson first eats the food item, providing him energy. Just as he runs out of energy, he encounters the food item, which provides him energy. He passes the food item, providing him more energy. However, he eats the food item, which completely drains all of his energy and leaves him unable to move.
Comments