In preparation for the upcoming hoofball tournament, Farmer John is drilling hiscows (conveniently numbered , where ) in passing the ball. The cows are all standing along a very long line on one side of the barn, with cow standing units away from the barn ( ). Each cow is standing at a distinct location.
At the beginning of the drill, Farmer John will pass several balls to different cows. When cowreceives a ball, either from Farmer John or from another cow, she will pass the ball to the cow nearest her (and if multiple cows are the same distance from her, she will pass the ball to the cow farthest to the left among these). So that all cows get at least a little bit of practice passing, Farmer John wants to make sure that every cow will hold a ball at least once. Help him figure out the minimum number of balls he needs to distribute initially to ensure this can happen, assuming he hands the balls to an appropriate initial set of cows.
INPUT FORMAT (file hoofball.in):
The first line of input contains. The second line contains space-separated integers, where the th integer is .
OUTPUT FORMAT (file hoofball.out):
Please output the minimum number of balls Farmer John must initially pass to the cows, so that every cow can hold a ball at least once.
5 7 1 3 11 4
In the above example, Farmer John should pass a ball to the cow atand pass a ball to the cow at . The cow at will pass her ball to the cow at , after which this ball will oscillate between the cow at and the cow at . The cow at will pass her ball to the cow at , who will pass the ball to the cow at , after which this ball will also cycle between the cow at and the cow at . In this way, all cows will be passed a ball at least once (possibly by Farmer John, possibly by another cow).
It can be seen that there is no single cow to whom Farmer John could initially pass a ball so that every cow would eventually be passed a ball.
Problem credits: Dhruv Rohatgi