This is a riddle where the left-hand side represents the amount spent and the right-hand side represents the balance.
We have that:
Adding the values in the balance column is not really necessary; in fact, it is coincidental in this case that the balances add up to 51.