cswork / OAOpen practice workspace

AmazonOA #357

Warehouse Robots with Threshold

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

Each robot has its own identity and is in exactly one state, running or waiting. A running robot requires the total number of running robots r≥its own threshold; a waiting robot requires the total number of waiting robots n−r to be strictly less than its own threshold. Find the number of valid identity configurations, without taking any modulus.

Input

The first line contains n and the second line contains n thresholds. The original bounds are 1≤n≤100000, 1≤a[i]≤n. The original int return signature cannot hold the actual result, so this site explicitly outputs an arbitrary-precision decimal integer of up to about 30103 digits.

Output

Output a single integer, the answer.

Example 1

Input:

2
1 2

Output:

2

Example 2

Input:

2
2 2

Output:

1

Example 3

Input:

3
2 2 2

Output:

4

Example notes

The outputs of the three public examples are 2; 1; and 4, checked by independent enumeration or direct simulation.

Editorial

Loading solution…