Under construction

Still being built. Things may change

No Birch Here~

Time limit1sMemory limit1024 MB

Summary
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 SS, which means birch, was deleted. Tokka and Dolldori could still play with few items, but they soon realized that some of the NN 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 N(1≤N≤100 000)N(1 \le N \le 100\,000) that Dolldori memorized and the word SS that means birch, separated by a space. SS has a length from 11 to 5050 and consists only of lowercase English letters.

From the second line through line N+1N+1, each line contains an item name and its quantity, separated by a space. An item name is no longer than 5050 characters. The quantity is an integer from 11 to 6464. 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.

Examples2

  1. Example 1

    Input
    5 birch
    birch_tree 6
    dirt 30
    stone 12
    sand 45
    cobblestone 12
    
    Expected output
    6
    
  2. Example 2

    Input
    2 stone
    stone 64
    cobblestone 32
    
    Expected output
    64