Counting problem (3) P84639


Statement
 

pdf   zip

Given a sequence of nn integer numbers x1xnx_1 \dots x_n, count how many ii’s, with 1in1 \le i \le n, follow the property

|{j:1j<ixj>xi}|=i/2.\vert \{ j : 1 \le j < i \wedge x_j > x_i \} \vert = \lfloor i/2 \rfloor \enspace .

Input

The input consists of several cases. Each case begins with nn, followed by the nn integer numbers x1xnx_1 \dots x_n. Assume 0n1050 \le n \le 10^5.

Output

For each case, print the number of indices ii that fulfill the condition above.

Public test cases
  • Input

    4   2 3 5 7
    4   7 2 5 3
    3   -7 -7 -7
    

    Output

    1
    4
    1
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++