use proconio::{input, marker::Chars}; use std::collections::HashMap; fn main() { let M = 998244353; input! { n: Chars, } /* let s: Vec = n .chars() .map(|c| c.to_digit(10).unwrap() as i128) .collect(); */ let mut s: Vec = vec![]; for x in &n { s.push(x.to_digit(10).unwrap() as i128); } let mut count: HashMap = HashMap::new(); for x in &s { *count.entry(*x).or_insert(0) += 1; } let mut f: Vec = vec![1]; for i in 1..=n.len() { f.push((f[f.len() - 1] * i as i128) % M); } let mut cnt = 0_i128; for i in 1..10 { let v = count.get(&i).unwrap_or(&0); if *v <= 0 { //if count_p <= 0 { continue; } let mut d = f[n.len() - 1]; for j in 0..10 { let mut x = 0; if i == j { let v = count.get(&i).unwrap_or(&0); x = *v - 1; } else { let v = count.get(&j).unwrap_or(&0); x = *v; } d = d * modpow(f[x as usize], -1, M); d %= M } cnt += d; cnt %= M; } println!("{cnt}"); } fn modpow(mut a: i128, mut e: i128, m: i128) -> i128 { let mut r = 1; a %= m; while e > 0 { if e & 1 == 1 { r = (r * a) % m; } a = (a * a) % m; e >>= 1; } r }