OpenKattis
Saudi IOI: Intensive Selection Contest 1 (Greedy)

Start

2018-12-31 12:15 CET

Saudi IOI: Intensive Selection Contest 1 (Greedy)

End

2018-12-31 15:45 CET
The end is near!
Contest is over.
Not yet started.
Contest is starting in -2182 days 15:48:55

Time elapsed

3:30:00

Time remaining

0:00:00

Problem B
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

\includegraphics[width=7cm]{tunnelbana1.pdf}
An optimal placement in Sample 1 (the dashed lines show the groups of contestants).

\includegraphics[width=7cm]{tunnelbana2.pdf}
An optimal placement in Sample 2 – here, only 2 groups were needed.

\includegraphics[width=7cm]{tunnelbana3.pdf}
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