#K68097. Calculate Net Profit

    ID: 32788 Type: Default 1000ms 256MiB

Calculate Net Profit

Calculate Net Profit

You are given a list of transactions. Each transaction is represented by a type and an amount. The type can be either sale or purchase. A sale increases the profit while a purchase decreases it. The net profit is calculated by the formula: $$Net\ Profit = \sum (\text{sale amounts}) - \sum (\text{purchase amounts})$$. Your task is to compute the net profit from the provided transactions. Note that the net profit can be negative.

inputFormat

The input is read from standard input (stdin) and has the following format:

N
operation_1 amount_1
operation_2 amount_2
... 
operation_N amount_N

Where:

  • N is an integer representing the number of transactions.
  • Each of the next N lines contains a transaction consisting of a string operation (either sale or purchase) and an integer amount.

outputFormat

Output the net profit as a single integer to standard output (stdout).

## sample
3
sale 500
purchase 300
sale 200
400

</p>