Maximum Length of necklace

Necklace maker has currently b -blue rubies, g -green rubies, r-red rubies and y -yellow rubies. He has to arrange the rubies next to each other in a straight line to make the necklace. But, there are a couple of rules to be followed while making this necklace:

A blue ruby should be followed by either a blue ruby or a red ruby
A green ruby should be followed by either a green ruby or a yellow ruby
A red ruby should be followed by either a green ruby or a yellow ruby
A yellow ruby should be followed by either a blue ruby or a red ruby


Can you tell what is the maximum possible length of the necklace that Necklace maker can make. The length of a necklace is the number of rubies in it.

Input Format
The first line contains an integer representing b.
The second line contains an integer representing g.
The third line contains an integer representing r.
The fourth line contains an integer representing y.

Constraints
0 <= b, g, r, y <= 3000
At least one of b, g, r, y is greater than 0

Output Format
A single integer which is the answer to the problem.

Author: geeky49
Login to Answer
Sort By:
Oldest
|
Newest
|
Vote
|
My Answer