The Curious Kid and the Number Game

The Curious Kid and the Number Game

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Time Limit: 1.0 s

Memory Limit: 128.0 MB

Description

A curious kid loves playing with numbers. One day, he invents a fun game using a list of numbers. He calls a number in the list 'special' if it follows at least one of these two rules:

  • There are at least a[i] numbers greater or equal than a[i] on its right.
  • There are at least a[i] numbers smaller or equal than a[i] on its left.

The kid wants to know how many numbers in the list are special.

Can you help him figure it out?

Input

  • The first line contains an integer n (1 ≤ n ≤ 10⁵) — the number of elements in the list.
  • The second line contains n space-separated integers a₁, a₂, ..., aₙ (0 ≤ a[i] ≤ n−1) — the elements of the list.

Output

  • Print a single integer — the number of special numbers in the list.

Sample

Input Output
6
1 1 3 1 5 1
4

Brain Booster #9

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
9
Start at
2025-04-06 15:30
End at
2025-04-06 18:00
Duration
2.5 hour(s)
Host
Partic.
90