#K34922. Calculate Final Balance
Calculate Final Balance
Calculate Final Balance
You are given a series of financial transactions. Each transaction consists of a transaction type and an amount. There are two types of transactions:
- deposit: The amount is added to the total balance.
- withdrawal: The amount is subtracted from the total balance.
The final balance, (B), is computed by summing the signed amounts:
[ B = \sum_{i=1}^{n} a_i ]
where (a_i) is the amount for the (i)-th transaction (positive for deposits and negative for withdrawals).
Your task is to process all transactions and output the final balance.
inputFormat
The first line contains an integer (n) representing the number of transactions. The following (n) lines each contain a transaction description with two values separated by a space: a string (either "deposit" or "withdrawal") and an integer amount.
outputFormat
Print the final balance as an integer.## sample
4
deposit 100
withdrawal 50
deposit 200
withdrawal 130
120