atcoder#ARC160C. [ARC160C] Power Up

[ARC160C] Power Up

Score : 500500 points

Problem Statement

You are given a multiset of positive integers with NN elements: A={A1,A2,,AN}A=\lbrace A_1,A_2,\dots,A_N \rbrace.

You may repeat the following operation any number of times (possibly zero).

  • Choose a positive integer xx that occurs at least twice in AA. Delete two occurrences of xx from AA, and add one occurrence of x+1x+1 to AA.

Find the number, modulo 998244353998244353, of multisets that AA can be in the end.

Constraints

  • 1N2×1051 \le N \le 2 \times 10^5
  • 1Ai2×1051 \le A_i \le 2 \times 10^5

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.

4
1 1 2 4
3

AA can be one of the three multisets $\lbrace 1,1,2,4 \rbrace,\lbrace 2,2,4 \rbrace,\lbrace 3,4 \rbrace$ in the end.

You can make A={3,4}A = \lbrace 3,4 \rbrace as follows.

  • Choose x=1x = 1. Delete two 11s from AA and add one 22 to AA, making A={2,2,4}A=\lbrace 2,2,4 \rbrace.
  • Choose x=2x = 2. Delete two 22s from AA and add one 33 to AA, making A={3,4}A=\lbrace 3,4 \rbrace.
5
1 2 3 4 5
1
13
3 1 4 1 5 9 2 6 5 3 5 8 9
66