#![allow(non_snake_case)] use proconio::{input}; mod mod_int { use core::iter::Sum; use core::ops::*; #[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)] pub struct ModInt { value: i32 } impl ModInt { fn normalize(v: i64) -> i32 { if 0 <= v && v < MOD as i64 { v as i32 } else { let v1 = (v % MOD as i64) as i32; if v1 < 0 { v1 + MOD } else { v1 } } } pub fn new(v: i64) -> ModInt { ModInt{ value: Self::normalize(v) } } pub fn inverse(self) -> Self { let mut x = MOD as i64; let mut y = self.value as i64; let mut p = 1; let mut q = 0; let mut r = 0; let mut s = 1; while y != 0 { let u = x / y; let x0 = y; y = x - y * u; x = x0; let r0 = p - r * u; let s0 = q - s * u; p = r; r = r0; q = s; s = s0; } ModInt::new(q) } } impl std::fmt::Display for ModInt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.value) } } impl Add for ModInt { type Output = Self; fn add(self, rhs: Self) -> Self { let value = self.value as i64 + rhs.value as i64; let value = (if value < MOD as i64 { value } else { value - MOD as i64 }) as i32; ModInt{ value } } } impl Add for ModInt { type Output = Self; fn add(self, rhs: i64) -> Self { self + ModInt::new(rhs) } } impl Sub for ModInt { type Output = Self; fn sub(self, rhs: Self) -> Self { let value = self.value as i64 - rhs.value as i64; let value = (if value >= 0 { value } else { value + MOD as i64 }) as i32; ModInt{ value } } } impl Sub for ModInt { type Output = Self; fn sub(self, rhs: i64) -> Self { self - ModInt::new(rhs) } } impl AddAssign for ModInt { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs } } impl AddAssign for ModInt { fn add_assign(&mut self, rhs: i64) { *self = *self + rhs } } impl Mul for ModInt { type Output = Self; fn mul(self, rhs: Self) -> Self { Self::new(self.value as i64 * rhs.value as i64) } } impl MulAssign for ModInt { fn mul_assign(&mut self, rhs: Self) { *self = *self * rhs } } impl Div for ModInt { type Output = Self; fn div(self, rhs: Self) -> Self { self * rhs.inverse() } } impl Div for ModInt { type Output = Self; fn div(self, rhs: i64) -> Self { self / ModInt::new(rhs) } } impl Sum for ModInt { fn sum>(iter: I) -> Self { iter.fold(Self::new(0), |a, b| a + b) } } } const MOD: i32 = 998244353; type MInt = mod_int::ModInt::; fn main() { input!{ n: usize, a: [usize; n] } // { // let mut b = a.clone(); // for _ in 0..1000 { // let mut c = b.clone(); // for i in 0..n { // c[i] = if { // (b[(i + n - 1) % n] == 1 && b[i] == 0) || // (b[i] == 1 && b[(i + 1) % n] == 1) // } { // 1 // } else { // 0 // } // } // for x in &c { eprint!("{x} "); } // eprintln!(""); // b = c; // } // } let s = a.iter().sum::(); if s <= n / 2 { println!("{}", MInt::new(s as i64) / MInt::new(n as i64)) } else { println!("{}", MInt::new((n - s) as i64) / MInt::new(n as i64)) } }