Under construction

Still being built. Things may change

Hoofball

Interview

Time limit2sMemory limit512 MB

Summary
Sort cows by position, then find the minimum number of starting balls so every cow receives the ball at least once under the nearest-cow passing rule.
Level

Medium4 of 10

Topics
Sorting, Graph, Greedy
Solved
No attempts yet

Problem

In preparation for the upcoming hoofball tournament, Farmer John is drilling his NN cows in passing the ball. The cows are numbered 11 through NN, where 1≤N≤1001 \leq N \leq 100. They all stand along a very long line on one side of the barn, and cow ii stands xix_i units away from the barn (1≤xi≤10001 \leq x_i \leq 1000). No two cows stand at the same location.

When cow ii receives a ball, either from Farmer John or from another cow, she passes it to the cow nearest her. If several cows are equally near, she passes it to the leftmost of them. So that every cow gets at least a little passing practice, Farmer John wants each cow to hold a ball at least once. Assuming he can hand the balls to any set of cows he likes at the start, find the minimum number of balls he must distribute.

Input

The first line contains NN. The second line contains NN space separated integers, where the iith integer is xix_i.

Output

Print the minimum number of balls Farmer John must distribute at the start so that every cow holds a ball at least once.

Hint

Take the case N=5N = 5 with the cows standing at x=7,1,3,11,4x = 7, 1, 3, 11, 4. Farmer John gives one ball to the cow at x=1x = 1 and one ball to the cow at x=11x = 11. The cow at x=1x = 1 passes to the cow at x=3x = 3, and from then on that ball moves back and forth between the cows at x=3x = 3 and x=4x = 4. The cow at x=11x = 11 passes to the cow at x=7x = 7, who passes to the cow at x=4x = 4, and that ball also ends up moving between x=3x = 3 and x=4x = 4. Every cow then holds a ball at least once, whether from Farmer John or from another cow.

There is no single cow such that giving her one ball makes every cow hold a ball.

Examples2

  1. Example 1

    Input
    5
    7 1 3 11 4
    
    Expected output
    2
    
  2. Example 2

    Input
    1
    1000
    
    Expected output
    1