In competitive programming one is often faced with the task to simulate what I call a "buy-sell" (or craft-melt) process where in the first step the player spends a certain amount of resources $$$a$$$ from his budget $$$n$$$ and in the second step he acquires $$$b$$$ units of the resource back by selling what he bought or crafted earlier where the relationship
stands.