use std::io::{self, Read as _, Write as _}; struct Scanner<'a>(std::str::SplitWhitespace<'a>); impl<'a> Scanner<'a> { fn new(s: &'a str) -> Self { Self(s.split_whitespace()) } fn next(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, { let s = self.0.next().expect("found EOF"); match s.parse() { Ok(v) => v, Err(msg) => { println!( "parse error. T = {}, s = \"{}\": {:?}", std::any::type_name::(), s, msg ); panic!() } } } } pub mod fp { use std::convert::From; use std::iter; use std::ops; pub const P: u32 = 998244353; #[derive(Copy, Clone, Debug)] pub struct Fp(pub u32); impl Fp { pub fn pow(mut self, mut exp: u32) -> Fp { let mut res = Fp(1); while exp != 0 { if exp % 2 != 0 { res *= self; } self *= self; exp /= 2; } res } } impl From for Fp { fn from(mut x: i64) -> Fp { x %= P as i64; if x < 0 { x += P as i64; } Fp(x as u32) } } impl iter::Product for Fp { fn product(iter: I) -> Fp where I: Iterator, { iter.fold(Fp(1), |b, i| b * i) } } impl iter::Sum for Fp { fn sum(iter: I) -> Fp where I: Iterator, { iter.fold(Fp(0), |b, i| b + i) } } impl ops::Add for Fp { type Output = Fp; fn add(mut self, rhs: Fp) -> Fp { self += rhs; self } } impl ops::AddAssign for Fp { fn add_assign(&mut self, rhs: Fp) { self.0 += rhs.0; if self.0 >= P { self.0 -= P; } } } impl ops::Mul for Fp { type Output = Fp; fn mul(mut self, rhs: Fp) -> Fp { self *= rhs; self } } impl ops::MulAssign for Fp { fn mul_assign(&mut self, rhs: Fp) { self.0 = (self.0 as u64 * rhs.0 as u64 % P as u64) as u32; } } impl ops::Neg for Fp { type Output = Fp; fn neg(self) -> Fp { Fp(match self.0 { 0 => 0, s => P - s, }) } } impl ops::Sub for Fp { type Output = Fp; fn sub(mut self, rhs: Fp) -> Fp { self -= rhs; self } } impl ops::SubAssign for Fp { fn sub_assign(&mut self, rhs: Fp) { if self.0 < rhs.0 { self.0 += P; } self.0 -= rhs.0; } } impl ops::Div for Fp { type Output = Fp; fn div(self, rhs: Fp) -> Fp { self * Fp::pow(rhs, P - 2) } } impl ops::DivAssign for Fp { fn div_assign(&mut self, rhs: Fp) { *self = *self / rhs; } } use std::str::FromStr; impl FromStr for Fp { type Err = ::Err; fn from_str(s: &str) -> Result::Err> { u32::from_str(s).map(|x| Fp(x)) } } use std::fmt; impl fmt::Display for Fp { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.0.fmt(f) } } } use fp::Fp; struct FpUtility { fact_: Box<[Fp]>, inv_fact_: Box<[Fp]>, } impl FpUtility { pub fn new(n: usize) -> Self { let mut fact_ = vec![Fp(0); n + 1]; let mut inv_fact_ = vec![Fp(0); n + 1]; fact_[0] = Fp(1); for i in 1..=n { fact_[i] = fact_[i - 1] * Fp(i as u32); } inv_fact_[n] = Fp(1) / fact_[n]; for i in (1..=n).rev() { inv_fact_[i - 1] = inv_fact_[i] * Fp(i as u32); } Self { fact_: fact_.into_boxed_slice(), inv_fact_: inv_fact_.into_boxed_slice(), } } pub fn fact(&self, n: usize) -> Fp { self.fact_[n] } pub fn inv_fact(&self, n: usize) -> Fp { self.inv_fact_[n] } pub fn perm(&self, n: usize, r: usize) -> Fp { self.fact_[n] * self.inv_fact_[n - r] } pub fn binom(&self, n: usize, r: usize) -> Fp { self.fact_[n] * self.inv_fact_[r] * self.inv_fact_[n - r] } pub fn homo(&self, n: usize, r: usize) -> Fp { self.fact_[n + r - 1] * self.inv_fact_[r] * self.inv_fact_[n - 1] } } fn main() { let mut stdin = String::new(); std::io::stdin().read_to_string(&mut stdin).unwrap(); let mut sc = Scanner::new(&stdin); let stdout = io::stdout(); let mut stdout = io::BufWriter::new(stdout.lock()); // writeln!(stdout, ""); let n: usize = sc.next(); let c = FpUtility::new(n); let mut ans = Fp(0); for k in 0..=n - 2 { let l = n - 2 - k; ans += c.binom(n, k) * Fp(n as u32).pow(l as u32) * c.inv_fact(l); } writeln!( stdout, "{}", ans * c.fact(n - 2) / Fp(n as u32).pow((n - 2) as u32) ) .unwrap(); stdout.flush().unwrap(); }