#arc146e. [arc146_e]Simple Speed

[arc146_e]Simple Speed

Problem Statement

You are given a sequence of NN positive integers: A=(A1,A2,dots,AN)A=(A_1,A_2,\\dots,A_N).

How many integer sequences BB consisting of integers between 11 and NN (inclusive) satisfy all of the following conditions? Print the count modulo 998244353998244353.

  • For each integer ii such that 1leileN1 \\le i \\le N, there are exactly AiA_i occurrences of ii in BB.
  • For each integer ii such that 1leileB11 \\le i \\le |B|-1, it holds that BiBi+1=1|B_i - B_{i+1}|=1.

Constraints

  • 1leNle2times1051 \\le N \\le 2 \\times 10^5
  • 1leAile2times1051 \\le A_i \\le 2 \\times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN A1A_1 A2A_2 dots\\dots ANA_N

Output

Print the answer.


Sample Input 1

3
2 3 1

Sample Output 1

6

BB can be the following six sequences.

  • (1,2,1,2,3,2)(1,2,1,2,3,2)
  • (1,2,3,2,1,2)(1,2,3,2,1,2)
  • (2,1,2,1,2,3)(2,1,2,1,2,3)
  • (2,1,2,3,2,1)(2,1,2,3,2,1)
  • (2,3,2,1,2,1)(2,3,2,1,2,1)
  • (3,2,1,2,1,2)(3,2,1,2,1,2)

Thus, the answer is 66.


Sample Input 2

1
200000

Sample Output 2

0

There may be no sequence that satisfies the conditions.


Sample Input 3

6
12100 31602 41387 41498 31863 12250

Sample Output 3

750337372