Under construction

Still being built. Things may change

Master of Array Construction

Time limit4sMemory limit1024 MB

Summary
Count the ways to replace each 0 in an array of length N with a value from 1 to N so that each value x appears at most x times, modulo 998244353.
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

An array AA of length NN consists of integers from 00 to NN.

Jiro wants to replace every element with value 00 with an integer from 11 to NN. The resulting array must satisfy the following condition.

  • For each integer xx from 11 to NN, the number of times xx appears in array AA is at most xx.

Find the number of arrays Jiro can build that satisfy the condition, modulo 998244353998244353. 998244353998244353 is prime.

Input

The first line contains the length NN of array AA. (1≤N≤30001 \le N \le 3000)

The second line contains A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N, separated by spaces. (0≤Ai≤N0 \le A_i \le N)

Output

Print the number of arrays Jiro can build that satisfy the condition, modulo 998244353998244353.

Examples2

  1. Example 1

    Input
    3
    1 0 0
    
    Expected output
    4
    
  2. Example 2

    Input
    2
    1 1
    
    Expected output
    0