Monkey Business
Three monkeys have made off with all of Jono's bananas, as well as his Zbox Series Z, which he really needs to play a large upcoming game.
Jono has observed that the monkeys will not let him have his console back until at least one of the monkeys has eaten all of their bananas and needs to go hunting for more.
Jono knows how many bananas each monkey currently has. Each monkey eats exactly one banana per day.
However, the monkeys have a strange habit. At the start of each day, the monkey with the most bananas gives one banana to the monkey with the fewest bananas.
There are a few rules regarding this:
- If all three monkeys have the same number of bananas, no banana is given away.
- If multiple monkeys are tied for having the fewest bananas, only one of them receives the banana.
- Similarly, if multiple monkeys are tied for having the most bananas, only one of them gives away a banana.
- The monkey giving away a banana and the monkey receiving it must be different monkeys.
Jono wants to know how many days it will take until at least one monkey has no bananas remaining, allowing him to finally get his console back.
Input
The input consists of three integers (
), representing the amount of bananas initially held by each of the three monkeys.
Output
Output a single integer representing the number of days until at least one monkey has no bananas remaining.
Example
Input 1
10 5 2
Output 1
5
The progression of the bananas is as follows:
start : 10 5 2
end of day 1: 8 4 2
end of day 2: 6 3 2
end of day 3: 4 2 2
end of day 4: 2 1 2
end of day 5: 0 1 1
Input 2
1 1 1
Output 2
1
The progression of the bananas is as follows:
start : 1 1 1
end of day 1: 0 0 0
Comments