Tables and Legs
Time limit2sMemory limit1024 MB
Given how many square tables have 0 to 4 legs, find the minimum minutes to unscrew and rescrew legs so that no table is left with 1, 2, or 3 legs.
Statement
A factory makes square tables with four legs each. Its conveyor that screws legs onto tables broke unexpectedly. The old conveyor cannot be repaired, so a new machine was bought. The new machine only works on tables with no legs and outputs finished tables with four legs. As a result, tables with one, two, or three legs are no longer useful.
To avoid throwing away nearly finished products, an experimental robot is used. Its goal is to unscrew legs from some tables and screw them onto others, so that the number of tables with one, two, or three legs becomes zero.
In one minute, the robot can either unscrew one leg from a table, or screw one previously removed leg onto another table. Find the minimum time the robot needs to complete the task.
Input
The first line contains five integers separated by spaces. is the number of tables with legs ().
Output
Print one number: the answer to the problem.