// ---------- begin ModInt ---------- mod modint { #[allow(dead_code)] pub struct Mod; impl ConstantModulo for Mod { const MOD: u32 = 998_244_353; } use std::marker::*; use std::ops::*; pub trait Modulo { fn modulo() -> u32; } pub trait ConstantModulo { const MOD: u32; } impl Modulo for T where T: ConstantModulo, { fn modulo() -> u32 { T::MOD } } pub struct ModInt(pub u32, PhantomData); impl Clone for ModInt { fn clone(&self) -> Self { ModInt::new_unchecked(self.0) } } impl Copy for ModInt {} impl Add for ModInt { type Output = ModInt; fn add(self, rhs: Self) -> Self::Output { let mut d = self.0 + rhs.0; if d >= T::modulo() { d -= T::modulo(); } ModInt::new_unchecked(d) } } impl AddAssign for ModInt { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; } } impl Sub for ModInt { type Output = ModInt; fn sub(self, rhs: Self) -> Self::Output { let mut d = T::modulo() + self.0 - rhs.0; if d >= T::modulo() { d -= T::modulo(); } ModInt::new_unchecked(d) } } impl SubAssign for ModInt { fn sub_assign(&mut self, rhs: Self) { *self = *self - rhs; } } impl Mul for ModInt { type Output = ModInt; fn mul(self, rhs: Self) -> Self::Output { let v = self.0 as u64 * rhs.0 as u64 % T::modulo() as u64; ModInt::new_unchecked(v as u32) } } impl MulAssign for ModInt { fn mul_assign(&mut self, rhs: Self) { *self = *self * rhs; } } impl Neg for ModInt { type Output = ModInt; fn neg(self) -> Self::Output { if self.0 == 0 { Self::zero() } else { Self::new_unchecked(T::modulo() - self.0) } } } impl std::fmt::Display for ModInt { fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl From for ModInt { fn from(val: usize) -> ModInt { ModInt::new_unchecked((val % T::modulo() as usize) as u32) } } #[allow(dead_code)] impl ModInt { pub fn new_unchecked(d: u32) -> Self { ModInt(d, PhantomData) } pub fn zero() -> Self { ModInt::new_unchecked(0) } pub fn one() -> Self { ModInt::new_unchecked(1) } pub fn is_zero(&self) -> bool { self.0 == 0 } } #[allow(dead_code)] impl ModInt { pub fn new(d: u32) -> Self { ModInt::new_unchecked(d % T::modulo()) } pub fn pow(&self, mut n: u64) -> Self { let mut t = Self::one(); let mut s = *self; while n > 0 { if n & 1 == 1 { t *= s; } s *= s; n >>= 1; } t } pub fn inv(&self) -> Self { assert!(self.0 != 0); self.pow(T::modulo() as u64 - 2) } } } // ---------- end ModInt ---------- use modint::*; type M = ModInt; const MIN_N: usize = 1; const MAX_N: usize = 200_000; const MIN_M: usize = 1; const MAX_M: usize = 200_000; fn read() -> (usize, Vec) { let mut s = String::new(); use std::io::Read; std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let mut next = |l: usize, r: usize| -> usize { let v = it.next().unwrap().parse::().unwrap(); assert!(l <= v && v <= r); v }; let n = next(MIN_N, MAX_N); let m = next(MIN_M, MAX_M); let mut a = vec![0; m]; for a in a.iter_mut() { *a = next(0, n); } assert!(it.next().is_none()); (n, a) } fn naive(n: usize, a: &[usize]) -> M { assert!(n <= 500); let mut mat = vec![vec![M::zero(); n]; n]; for i in 0..n { for j in 0..i { mat[i][j] = M::one(); } } let p = M::from(n).inv(); let q = M::from(n - 2) * p; let mut ans = M::from(a.len()); for &a in a.iter() { if a == 0 { ans += M::from(n - 1) * M::new(2).inv(); for i in 0..n { for j in 0..i { mat[i][j] = q * mat[i][j] + p; mat[j][i] = q * mat[j][i] + p; } } } else { let a = a - 1; ans += mat[a].iter().fold(M::zero(), |s, a| s + *a); for j in 0..n { if a != j { mat[a][j] = M::zero(); mat[j][a] = M::one(); } } } } ans } fn main() { let (n, a) = read(); let ans = naive(n, &a); println!("{}", ans); }