Skip to main content
Back to problems
Codeforces
Medium
Arrays
Math
Greedy
Table Decorations

Arrange colored table decorations so that no two adjacent decorations have the same color, while using as many items as possible.

Acceptance 0%
Problem Statement

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.

Input Format

The input contains three integers aa, bb, and cc — the counts of the three decoration types.

Output Format

Print one integer — the maximum number of decorations that can be arranged so that adjacent decorations are always of different types.

Constraints

  • 0a,b,c0 \le a, b, c
  • The counts fit in standard 32-bit signed integers
  • The answer is an integer between $0andanda+b+c$
Examples
Sample cases returned by the problem API.

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

Unlock deeper context for this problem

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.