fn main() { const MOD93: usize = 998244353; input!{ m: usize, n: usize, mut x: [usize; n], } x.insert(0, 0); x.push(m+1); // 番兵を入れる let mut diff_list = vec![0; n+1]; for i in 0..n+1 { diff_list[i] = x[i+1] - x[i]; } // (各階差-1)の2乗の和を数え上げ let mut ans = 0; for i in 0..n+1 { ans += multi_sum_calc(diff_list[i]-1, MOD93); ans %= MOD93; } println!("{}", ans); } fn multi_sum_calc(x: usize, mods: usize) -> usize { // (1/6)*x*(x+1)*(2x+1) let mut ret = x; ret *= x+1; ret %= mods; ret *= 2*x+1; ret %= mods; ret = div(ret, 6, mods); ret } // 繰り返し二乗法 fn mod_pow(mut a: usize, mut b: usize, mods: usize) -> usize { let mut res = 1; while b > 0 { if b % 2 == 1 { res *= a; res %= mods; } a *= a; a %= mods; b >>= 1; } res } // 繰り返し二乗法による除算 fn div(a: usize, b: usize, mods: usize) -> usize { let mut ans = a; let x = mod_pow(b, mods - 2, mods); ans *= x; ans %= mods; ans } // const MOD17: usize = 1000000007; // const INF: usize = 1 << 60; // let dx = vec![!0, 0, 1, 0]; // 上左下右 // let dy = vec![0, !0, 0, 1]; // 上左下右 // let d = vec!{(!0, 0), (0, !0), (1, 0), (0, 1)}; // 上左下右 #[allow(unused)] use proconio::{input, marker::Chars, marker::Usize1}; #[allow(unused)] use std::{ mem::swap, cmp::min, cmp::max, cmp::Reverse, collections::HashSet, collections::BTreeSet, collections::HashMap, collections::BTreeMap, collections::BinaryHeap, collections::VecDeque, iter::FromIterator, };