Let us follow Alice's wallet.
She starts with hryvnias. Bob and Svitlana pay back their debts, so and hryvnias are added. Then Alice pays her debt to Dmytro, and hryvnias are subtracted.
In total we get
The statement guarantees that the result is non-negative, so the case of «not enough money» needs no separate handling. All values are at most , so there is no overflow and no real numbers here.