Maya the Bee
InterviewTime limit1sMemory limit1024 MB
Three flowers hold A, B, C bees in nondecreasing order; move bees so each flower holds the same number, minimizing total meters flown.
- Level
Medium4 of 10
- Topics
- Greedy, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Bees have landed on three flowers arranged in a row, 1 meter apart. The left flower has no more bees than the middle one, and the middle flower has no more bees than the right flower.
Maya the Bee leads all of them. She has calculated that if she sends some of the bees to move, the three flowers will each hold an equal number of bees. Unfortunately, the hardworking bees must conserve their strength. So Maya first wants to work out the minimum number of meters that can be flown, and only then will she decide which bee moves to which flower.
To help Maya the Bee, write a program bee that prints this minimum number of meters.
Input
The first line of standard input contains three integers A, B, and C, the number of bees on the left, middle, and right flower respectively. The numbers are separated by a single space.
Output
On a single line of standard output, the program must print one integer: the minimum total number of meters flown by the bees.
Constraints
- 0 ≤ A ≤ B ≤ C ≤ 100
- A+B+C > 0
Hint
Explanation of the example: 3 bees move from the rightmost flower to the leftmost flower, and then each flower holds 3 bees. Each bee that moves flies 2 meters. Therefore the total number of meters flown is 6.