Under construction

Still being built. Things may change

Counting DFS Trees

Interview

Time limit1sMemory limit2048 MB

Summary
Count the distinct preorder depth sequences of trees with n nodes whose leaves all sit at depth K, then multiply f(A_i) for all queries modulo 998244353.
Level

Medium5 of 10

Topics
Dynamic programming, Prefix sum, Combinatorics
Solved
No attempts yet

문제

You are studying the Depth First Search (DFS) tree traversal algorithm. Consider a rooted tree of nn nodes, numbered from 11 to nn, with depth KK (levels numbered from 11 to KK). The root, the node at depth 11, is node 11. All leaves are located at the same depth, that is, depth KK. Node ii has an array of children cic_i, which may be empty if ii is a leaf. The algorithm is written in pseudocode below.

DFS(u, depth):
  let res be an empty array
  append depth to res

  for each v in c[u]:
    let D be an array initialized with DFS(v, depth + 1)
    for each x in D:
      append x to res

return res

In the trees shown in the illustration, the return values of DFS(1, 1) are [1,2,3,3,3][1, 2, 3, 3, 3] for the left tree and [1,2,3,2,3][1, 2, 3, 2, 3] for the right tree.

Let fK(n)f_K(n) be the number of distinct return values of DFS(1, 1) over all trees with nn nodes in which all leaves are at depth KK. You are given MM integers A1,A2,…,AMA_1, A_2, \dots, A_M. Find the value of fK(A1)×fK(A2)×⋯×fK(AM)f_K(A_1) \times f_K(A_2) \times \cdots \times f_K(A_M) modulo 998 244 353998\,244\,353.

입력

The first line contains two integers KK and MM (1≤K,M≤100 0001 \le K, M \le 100\,000). The second line contains MM integers A1,A2,…,AMA_1, A_2, \dots, A_M (K≤Ai≤200 000K \le A_i \le 200\,000).

출력

Print the value of fK(A1)×fK(A2)×⋯×fK(AM)f_K(A_1) \times f_K(A_2) \times \cdots \times f_K(A_M) modulo 998 244 353998\,244\,353.

Examples2

  1. Example 1

    Input
    3 2
    5 6
    
    Expected output
    6
    
  2. Example 2

    Input
    100000 1
    200000
    
    Expected output
    269130693