Subway Seats
The Baltic Olympiad in Informatics – the programming contest for the countries aronud the Baltic Sea – will in the Spring 2017 be organized in Stockholm, and the participants will be taking the subway between their hostel and the contest site.
On the subway there are groups of $4$ seats each. Now, a number of groups of contestants wants to sit down. Each group of contestants has either $1$, $2$, $3$ or $4$ contestants. Preferably, all the contestants in a group wants to sit in the same group of seats.
How many groups of $4$ seats do you need for this to be possible?
Input
The input contains a single line with four integers $a_1, a_2, a_3, a_4$ – the number of groups of each size. All of the numbers are between $0$ and $100$.
Output
Output a single number – the smallest number of groups of $4$ seats needed for all the groups of contestant to sit down, so that everyone in a group gets to sit together.
Grading
In test cases worth $20$ points, there are no groups of
size 1.
In test cases worth another $20$ points, there are no groups of
size 2.
In test cases worth another $20$ points, there are no groups of
size 3.
In test cases worth another $40$ points, no additional
restrictions apply.
Explanations of the Samples
An optimal placement in Sample 1 (the dashed lines show the
groups of contestants).
An optimal placement in Sample 2 – here, only 2 groups were
needed.
An optimal placement in Sample 3..
Sample Input 1 | Sample Output 1 |
---|---|
1 1 1 1 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
1 2 1 0 |
2 |
Sample Input 3 | Sample Output 3 |
---|---|
0 1 2 0 |
3 |