#K50257. Transaction Balance Calculator

    ID: 28824 Type: Default 1000ms 256MiB

Transaction Balance Calculator

Transaction Balance Calculator

You are given a series of financial transactions. Each transaction consists of a user's name and an integer amount (which could be positive or negative). The task is to compute the final balance for each user by summing up all the transaction amounts.

The final result should list each user and their balance, sorted in lexicographical order of the users' names. For each line, output the user's name followed by a space and their final balance.

Mathematically, for each user u, compute

\( \text{balance}(u) = \sum_{i=1}^{n_u} a_i \)

where \(a_i\) is the amount in the i-th transaction of user \(u\), and \(n_u\) is the total number of transactions for user \(u\).

inputFormat

The input is provided via stdin with the following format:

  • The first line contains an integer \(N\) representing the number of transactions.
  • The following \(N\) lines each contain a string and an integer separated by a space, representing the user's name and the transaction amount respectively.

outputFormat

Output the final balance for each user on a new line. Each line should have the user name and their balance separated by a space. Output the users in lexicographical order.

## sample
5
alice 50
bob 100
alice -20
alice 30
bob -50
alice 60

bob 50

</p>