All problems

Problem 663

Maximum Score From Removing Stones

Medium · 20 pts · Math, Greedy, Heap

Problem

You have three piles of stones with A, B and C stones. In one move you take one stone from each of two different non-empty piles and score 1 point. The game ends when fewer than two piles are non-empty. Find the maximum score. If the largest pile is at least as big as the other two together, every move must use it and the answer is the sum of the two smaller piles; otherwise you can pair stones almost perfectly and the answer is floor((A + B + C) / 2).

Input

A single line with A, B and C.

Output

Print the maximum score.

Constraints

1 <= A, B, C <= 10^5

Example input

2 4 6

Example output

6

Explanation

With piles 2, 4 and 6, the total is 12 and the largest pile (6) is not bigger than the other two together (6). So all stones can be paired and the score is 12 / 2 = 6.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Partition Array into Disjoint Intervals Next: Two Furthest Houses With Different Colors