use proconio::input; type Mint = kekenx::ModInt<998244353>; fn main() { input! { m: u64, n: usize, mut x: [u64; n], } x.push(m + 1); let mut prev = 0; let mut ans = Mint::new(0); let inv = Mint::new(6).inv(); for i in x { let j = Mint::new(i - prev - 1); ans += j * (Mint::new(1) + j) * (Mint::new(2) * j + Mint::new(1)) * inv; prev = i; } println!("{ans}"); } pub mod kekenx { use std::fmt; use std::{ convert::{TryFrom, TryInto}, iter::{Product, Sum}, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}, }; #[derive(Eq, PartialEq, Clone, Copy, Hash)] pub struct ModInt(u64); impl ModInt { pub fn new(val: u64) -> ModInt { ModInt(val % M) } pub fn val(&self) -> u64 { self.0 } pub fn pow(&self, mut e: u64) -> ModInt { let mut r = ModInt::new(1); let mut x = *self; while e > 0 { if e % 2 == 1 { r *= x; } x *= x; e >>= 1; } r } pub fn inv(&self) -> ModInt { self.pow(M - 2) } } macro_rules! impl_from { ($t: ty) => { impl From<$t> for ModInt { fn from(from: $t) -> Self { let mut x = from.into(); if x >= M { x %= M; } Self(x) } } }; } macro_rules! impl_try_from { ($t: ty) => { impl TryFrom<$t> for ModInt { type Error = (); fn try_from(from: $t) -> Result { let mut x = from.try_into().unwrap(); if x >= M { x %= M; } Ok(Self(x)) } } }; } // Signed to ModInt impl_try_from!(i16); impl_try_from!(i32); impl_try_from!(i64); // Unsigned to ModInt impl_from!(u8); impl_from!(u16); impl_from!(u32); impl AddAssign for ModInt { fn add_assign(&mut self, rhs: Self) { self.0 += rhs.0; if self.0 >= M { self.0 -= M; } } } impl Add for ModInt { type Output = Self; fn add(self, rhs: Self) -> Self::Output { let mut ret = self; ret += rhs; ret } } impl SubAssign for ModInt { fn sub_assign(&mut self, rhs: Self) { if rhs.0 > self.0 { self.0 += M; } self.0 -= rhs.0; } } impl Sub for ModInt { type Output = Self; fn sub(self, rhs: Self) -> Self::Output { let mut ret = self; ret -= rhs; ret } } impl MulAssign for ModInt { fn mul_assign(&mut self, rhs: Self) { self.0 *= rhs.0; if self.0 > M { self.0 %= M; } } } impl Mul for ModInt { type Output = Self; fn mul(self, rhs: Self) -> Self::Output { let mut ret = self; ret *= rhs; ret } } impl DivAssign for ModInt { fn div_assign(&mut self, rhs: Self) { self.mul_assign(rhs.inv()); } } impl Div for ModInt { type Output = Self; fn div(self, rhs: Self) -> Self::Output { let mut ret = self; ret /= rhs; ret } } impl fmt::Display for ModInt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) } } impl fmt::Debug for ModInt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{{ModInt: {}, modulo: {}}}", self.0, M) } } impl Default for ModInt { fn default() -> Self { ModInt::new(0) } } impl Product for ModInt { fn product>(iter: I) -> Self { iter.fold(ModInt::::new(1), |a, b| a * b) } } impl Sum for ModInt { fn sum>(iter: I) -> Self { iter.fold(ModInt::::new(0), |a, b| a + b) } } }