The Curious Kid and the Number Game
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 |
---|---|
|
|
Information
- ID
- 1184
- Difficulty
- 5
- Category
- (None)
- Tags
- (None)
- # Submissions
- 102
- Accepted
- 33
- Accepted Ratio
- 32%
- Uploaded By
Related
In following contests: