Find the LCA

아직 제출이 없습니다시간 제한7초메모리 제한1024 MB

문제

You are given an integer sequence A_1,A_2,,A_NA\_1,A\_2,\ldots,A\_N. You'll make a rooted tree with NN vertices numbered from 11 through NN. The vertex 11 is the root, and for each vertex ii (2iN2 \leq i \leq N), its parent p_ip\_i must satisfy p_i\<ip\_i\<i.

You define the score of a rooted tree as follows:

  • Let xx be the lowest common ancestor of the vertex N1N-1 and the vertex NN. Then, the score is _v(subtree rooted at x)A_v\prod\_{v \in (\text{subtree rooted at $x$})} A\_v Note that we consider xx itself is in the subtree rooted at xx

There are (N1)!(N-1)! ways to make a tree. Find the sum of scores of all possible trees, modulo 998244353998244353.

입력

The first line contains an integer NN (3N2500003 \leq N \leq 250000).

The second line contains integers A_1,A_2,,A_NA\_1,A\_2,\ldots,A\_N (1A_i<9982443531 \leq A\_i < 998244353).

출력

Print the answer.