Counting problem (4)

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}|=|{j:1j<ixj>xi}|.\vert \{ j : 1 \le j < i \wedge x_j < x_i \} \vert = \vert \{ j : 1 \le j < i \wedge x_j > x_i \} \vert \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.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:19:42.649Z

© Jutge.org, 2006–2026.
https://jutge.org