Balls and Bins
Sakurako is a young programmer working on a robotics project.
She has built three smart bins, each starting with , , and balls, respectively. The bins are designed to pass balls between each other, and her task is to write a program that makes the number of balls in all three bins equal.
Sakurako can instruct a non-empty bin to take one ball out and give it to another. However, she's curious to know if it's even possible to balance the bins, and if so, how many moves it would take. Can you help her design an efficient solution?
Let's say she has three bins; the first bin has ball, the second bin has balls, and the third bin has ball. Below, you can find the illustration for such an example.
Yellow arrows show the ball we take and where we put it. In this case, we perform two operations.
Input
The only line contains three integers , , and .
Output
If it is impossible to make the number of balls in all three bins equal, output "-1
".
Otherwise, output the minimum number of moves required to balance the balls over the bins.
Examples
Note
In the second example, it might be shown that it is impossible to distribute the balls among the bins as described in the statement.
In the third example, all the bins are empty, which implies that all of them have the same amount of balls; hence, the output is zero.
In the fourth example, we may follow the strategy described below:
what takes us exactly operations. We may prove that it is impossible to balance the bins in less than operations.
Scoring
You will receive at least points if your solution works correctly for and ; that is, the second and third bins are empty.
You will receive at least points if your solution works correctly for and .