对于一个 nnn 阶排列 ppp,我们建立一张无向简单图 G(p)G(p)G(p),有 nnn 个节点,标号从 111 到 nnn,每个点向左右两侧最近的比它大的点以及比它小的点连边。
形式化地,在 G(p)G(p)G(p) 中,∀u<v\forall u<v∀u<v,边 (u,v)(u,v)(u,v) 存在当且仅当以下四个条件至少一个成立:
- pu<pvp_u<p_vpu<pv,且不存在 u<i<vu<i<vu<i<v 满足 pu<pip_u<p_ipu<pi;
- pu>pvp_u>p_vpu>pv,且不存在 u<i<vu<i<vu<i<v 满足 pu>pip_u>p_ipu>pi;
- pu<pvp_u<p_vpu<pv,且不存在 u<i<vu<i<vu<i<v 满足 pi<pvp_i<p_vpi<pv;
- pu>pvp_u>p_vpu>pv,且不存在 u<i<vu<i<vu<i<v 满足 pi>pvp_i>p_vpi>pv。
现在在所有的 nnn 阶排列中随机选择一个排列 ppp,请求出 G(p)G(p)G(p) 中三元简单环的期望个数,答案对 998244353998244353998244353 取模。
For an nnn-order permutation ppp, we set up an undirected simple graph G(p)G(p)G(p) with nnn vertices numbered from 111 to nnn.
We create an edge between each vertice iii and the nearest vertices in each side which correspond a greater (or less) ppp value than pip_ipi.
Formally,in this graph, ∀u<v\forall u<v∀u<v, the edge (u,v)(u, v)(u,v) exists iff at least one of the following four conditions hold:
- pu<pvp_u<p_vpu<pv, and no u<i<vu<i<vu<i<v exists such that pu<pip_u<p_ipu<pi;
- pu>pvp_u>p_vpu>pv, and no u<i<vu<i<vu<i<v exists such that pu>pip_u>p_ipu>pi;
- pu<pvp_u<p_vpu<pv, and no u<i<vu<i<vu<i<v exists such that pi<pvp_i<p_vpi<pv;
- pu>pvp_u>p_vpu>pv, and no u<i<vu<i<vu<i<v exists such that pi>pvp_i>p_vpi>pv.
Now we randomly choose a permutation ppp from all nnn-order permutations. Your task is to calculate the expected number of the 333-cycles in G(p)G(p)G(p). You only need to output the answer modulo 998244353998244353998244353.