#C339. Maximum Earnings from Procure and Request Events

    ID: 46811 Type: Default 1000ms 256MiB

Maximum Earnings from Procure and Request Events

Maximum Earnings from Procure and Request Events

You are given a sequence of n events. Each event is represented as a string with two parts: an action and a weight. The action is either procure or request, and the weight is a positive integer.

When a procure event occurs, an item with the specified weight is added to your inventory. When a request event occurs, if there is an item in the inventory with a matching weight, you fulfill the request by removing that item and earning an amount equal to the weight. Otherwise, the request is ignored.

Mathematically, if you denote the earnings as \(E = \sum_{i=1}^{k} w_i\), where each \(w_i\) is the weight of a successfully fulfilled request, your task is to compute \(E\) after processing all events in order.

inputFormat

The first line contains an integer \(n\) indicating the number of events. The next \(n\) lines each contain an event in the following format:

action weight

Here, action is either procure or request and weight is a positive integer.

outputFormat

Output a single integer which is the maximum earnings, i.e. the sum of the weights of all requests that could be successfully fulfilled.

## sample
5
procure 5
procure 10
request 10
procure 7
request 7
17