A steam locomotive's boiler burns coal drawn only from its main bunker; a separate auxiliary tender car carries backup coal that cannot be burned directly. Coal is consumed continuously from the main bunker as the locomotive runs. Every time a running total of exactly 5 sacks of coal have been burned from the main bunker since the last such event, the crew immediately shovels exactly 1 sack of coal from the auxiliary tender into the main bunker, provided the tender still holds at least 1 sack at that moment; a shoveled sack can later be burned itself and may trigger further shovels. Each sack of coal burned from the main bunker propels the locomotive exactly 10 kilometers. Given how many sacks are initially loaded into the main bunker and into the auxiliary tender, determine the total distance the locomotive can travel before the main bunker is completely emptied and no further coal can be shoveled into it (any coal still sitting unused in the tender at that point does not count).
A single line containing two integers: mainBunker and auxiliaryTender.
Print a single integer: the total distance traveled, in kilometers.
Example 1
Input
5 10
Expected
60
Explanation
Burning the first 5 sacks from the main bunker (0 left) covers 50 km and, because a full 5 were burned and the tender has coal, triggers a shovel from the tender (9 left there), bringing the main bunker back to 1 sack. That last sack is burned for another 10 km; since only 1 sack was burned this time (not a full 5), no further shovel happens and the main bunker is empty. Total distance: 50 + 10 = 60 km.
Example 2
Input
1 2
Expected
10
Explanation
The main bunker holds only 1 sack, so burning it covers 10 km and empties the main bunker immediately — since fewer than 5 sacks were burned, no coal is shoveled from the tender. Total distance: 10 km.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →