COCI 2008/2009, Contest #1

Task SKOCIMIS

Three kangaroos are playing in the desert. They are playing on a number line, each occupying a different integer. In a single move, one of the outer kangaroos jumps into the space between the other two. At no point may two kangaroos occupy the same position.

Help them play as long as possible.

Input

Three integers A, B and C (0 < A < B < C < 100), the initial positions of the kangaroos.

Output

Output the largest number of moves the kangaroos can make.

Examples

Input

2 3 5

Output

1

Input

3 5 9

Output

3

All Submissions
Best Solutions


Point Value: 5
Time Limit: 1.00s
Memory Limit: 32M
Added: Oct 18, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

find out the bigger difference between he first and second kangaroo and second and third kangaroo.

Three positions are given initially(x<y<z).x can jump between y and z and similarly z can jump between x and y.In first case(x jumping) x can take position from y+1,y+2,y+3...till (z-1).Similarly if z jumping it can take position from (x+1,x+2x+3...till (y-1)).

I get Time Limit Exceeded for test case 1 and test case 9. That is all.

There is a much simpler way to do this problem without loops.
However, I can't see anything wrong with your code except maybe you're going into an infinite loop. Try the smallest test cases, and then some bigger ones.

You get TLE, which of course means your program runs forever. This is caused by your whole program being wrong - debug it and observe the values of your 3 position variables, and see if they satisfy a<b<c (as your program requires them to).

Thx

Hint: What do you notice about the last two numbers and the output?

Oh. I see you got the problem. Nvm then.

Is there a specific formula for it like chocolate bar?
if so, can someone give me test cases?

The distinction between "formula" and "algorithm" is blurred. Anyway, look at the point value. This problem's only worth 5 points, so there's a good chance that the solution is short and simple. Try working out some test cases by hand and maybe you'll see a pattern.

Come on just one test case i really need the points...

How will testcases help? Each one is just 3 numbers, you can come up with those yourself.

so if there is a kangaroo at 1 and 3 and 5;

the one on 1 cna jump any where between 3 and 5? or between 1 and 5??

Just between 3 and 5 (between the other two!)

and to maximize the num of jumps, it is practically going to occupy the space of 4 on the number line.

does that mean that the kangaroos can jump above each other?

if x<y<z then x can jump between z and y?

yea if x<y<z then either x jumps at any spot between y and z or z jumps at any spot between x and y

can someone tell me what am I doing wrong?

Does the question mean that these kangaroos cant jump away from one another? like can one of them go towards the end of the number line?

In a certain sense the kangaroos indeed cannot jump away from one another. I thought the problem statement was very clear. If the kangaroos are at positions x, y, z, where x < y < z, then either the kangaroo at x may jump to any position y+1, y+2, ... z-2, z-1 or the kangaroo at z may jump to any position x+1, x+2, ... y-2, y-1.