#C12976. Banking System Simulation

    ID: 42462 Type: Default 1000ms 256MiB

Banking System Simulation

Banking System Simulation

This problem simulates a basic banking system. You are given a series of commands to perform on the bank account. The available operations are:

  • deposit x: Deposit an integer amount x into the account.
  • withdraw x: Withdraw an integer amount x from the account. If the withdrawal amount exceeds the current balance, the system should immediately output an error message.
  • balance: Check the current balance. (This operation does not change the balance.)

If a withdrawal is attempted that exceeds the balance, output Error: Insufficient funds. Otherwise, after processing all commands, output the final balance.

inputFormat

The input is given via standard input (stdin). The first line contains an integer N (1 ≤ N ≤ 104), which denotes the number of commands. The following N lines each contain a command. Each command is one of the following formats:

  • deposit x — deposits an amount x into the account (where x is a non-negative integer).
  • withdraw x — withdraws an amount x from the account (where x is a non-negative integer).
  • balance — indicates that after processing all commands, the current balance should be output.

outputFormat

Print a single line to standard output (stdout). If every withdrawal is successful, print the final balance as an integer. If any withdrawal operation requests more than the current balance, immediately output Error: Insufficient funds.

## sample
3
deposit 100
withdraw 30
balance
70