Arrange colored table decorations so that no two adjacent decorations have the same color, while using as many items as possible.
You are given counts of three types of decorations. Your task is to arrange some of them in a row so that no two neighboring decorations have the same type.
Find the maximum number of decorations that can be placed in such an arrangement. You do not need to output the arrangement itself, only its maximum possible length.
The key challenge is balancing the three counts so that the most frequent type does not dominate the sequence.
The input contains three integers , , and — the counts of the three decoration types.
Print one integer — the maximum number of decorations that can be arranged so that adjacent decorations are always of different types.
Example 1
Input
2 2 1
Output
5
Explanation
One valid arrangement is 1 2 1 3 2, which uses all 5 decorations and has no equal adjacent pair.
Example 2
Input
7 1 1
Output
5
Explanation
Even though there are 9 decorations total, the first type is too frequent. At most 5 can be arranged without equal neighbors, for example 1 2 1 3 1.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.