#![allow(unused_imports, dead_code, unused_macros, unused_variables, non_snake_case, unused_parens)] use proconio::{input,marker::{Bytes, Chars, Usize1,Isize1}}; use std::cmp::*; use std::mem::swap; use std::collections::*; const MOD:u64 = 998244353; const INF:i64 = 0x3fff_ffff_ffff_ffff; macro_rules! min {($a:expr $(,)*) => {{$a}};($a:expr, $b:expr $(,)*) => {{std::cmp::min($a, $b)}};($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::min($a, min!($($rest),+))}};} macro_rules! max {($a:expr $(,)*) => {{$a}};($a:expr, $b:expr $(,)*) => {{std::cmp::max($a, $b)}};($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::max($a, max!($($rest),+))}};} macro_rules! chmin {($base:expr, $($cmps:expr),+ $(,)*) => {{let cmp_min = min!($($cmps),+);if $base > cmp_min {$base = cmp_min;true} else {false}}};} macro_rules! chmax {($base:expr, $($cmps:expr),+ $(,)*) => {{let cmp_max = max!($($cmps),+);if $base < cmp_max {$base = cmp_max;true} else {false}}};} macro_rules! mulvec {($x:expr; $s:expr) => {vec![$x; $s]};($x:expr; $s0:expr; $( $s:expr );+) => {mulvec![vec![$x; $s0]; $( $s );+ ]};} macro_rules! outputln {($var:expr)=>{println!("{}",$var)};($var:expr,$($vars:expr),+)=>{print!("{} ",$var);outputln!($($vars),+);};} macro_rules! debug {($($a:expr),* $(,)*) => {eprintln!(concat!($("| ",stringify!($a), "={:?} "),*, "|"),$(&$a),*);};} fn solve() { input! { N:usize, mut A:[String;N], } let mut pow10 = vec![1]; for _ in 0..20 { pow10.push(pow10[pow10.len()-1]*10%MOD); } A.sort_by(|a,b| (a.clone()+b).partial_cmp(&(b.clone()+a)).unwrap()); let mut ans = 0; for a in A { let n = a.len(); let a:u64 = a.parse().unwrap(); ans *= pow10[n]; ans += a; ans %= MOD; } outputln!(ans); } fn main() { std::thread::Builder::new() .stack_size(128 * 1024 * 1024) .spawn(|| solve()).unwrap() .join().unwrap(); }