No Birch Here~
Time limit1sMemory limit1024 MB
Given N item names with quantities, sum the quantities of every item whose name contains the substring S.
- Level
Easy2 of 10
- Topics
- String, String matching, Implementation
- Solved
- No attempts yet
Problem
Tokka and his friend Dolldori were searching for trees to build a house in the game Minecraft. Dolldori wanted birch wood for the floor, but the game started in the middle of a jungle, and after wandering for a long time they could not find any birch. Exhausted, Dolldori returned home and muttered a short report of the scouting results.
"Um⋯ there is no birch~"
Immediately, as if by magic, every game item whose name contains the word , which means birch, was deleted. Tokka and Dolldori could still play with few items, but they soon realized that some of the items in the chest had birch in their names. Dolldori had sorted the items well and memorized their names and quantities. Using this, find the total quantity of deleted items.
Input
The first line contains the number of item kinds that Dolldori memorized and the word that means birch, separated by a space. has a length from to and consists only of lowercase English letters.
From the second line through line , each line contains an item name and its quantity, separated by a space. An item name is no longer than characters. The quantity is an integer from to . Item names are distinct. An item name does not start or end with a separator, and two separators never appear in a row.
Output
Print the total quantity of items deleted from the game.
Hint
This problem has a large amount of input, so reading input and writing output slowly may cause a time limit exceeded verdict.