#![allow(unused_imports)] #![allow(non_snake_case, unused)] // ---------- begin input macro ---------- // https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254 より pub fn readln() -> String { let mut line = String::new(); ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e)); line } macro_rules! read { ($($t:tt),*; $n:expr) => {{ let stdin = ::std::io::stdin(); let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| { let line = line.unwrap(); let mut it = line.split_whitespace(); _read!(it; $($t),*) }).collect::>(); ret }}; ($($t:tt),*) => {{ let line = readln(); let mut it = line.split_whitespace(); _read!(it; $($t),*) }}; } macro_rules! _read { ($it:ident; [char]) => { _read!($it; String).chars().collect::>() }; ($it:ident; [u8]) => { Vec::from(_read!($it; String).into_bytes()) }; ($it:ident; usize1) => { $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::().unwrap_or_else(|e| panic!("{}", e)) - 1 }; ($it:ident; [usize1]) => { $it.map(|s| s.parse::().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::>() }; ($it:ident; [$t:ty]) => { $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::>() }; ($it:ident; $t:ty) => { $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e)) }; ($it:ident; $($t:tt),+) => { ($(_read!($it; $t)),*) }; } // ---------- end input macro ---------- use std::cmp::*; use std::collections::*; use std::ops::*; use std::marker::*; const INF: i64 = std::i64::MAX/100; // const MOD: i64 = 1_000_000_007; const MOD: i64 = 998_244_353; fn main() { let c = read!([char]); let k = read!(usize); let ans = solve(0,&c); println!("{}",ans[k]); } fn solve(s: usize, c: &Vec) -> Vec { if c[s]=='?' { return vec![1,1,1,(s+1) as i64]; } if c[s]=='0' { return vec![1,0,0,(s+1) as i64]; } if c[s]=='1' { return vec![0,1,0,(s+1) as i64]; } if c[s]=='2' { return vec![0,0,1,(s+1) as i64]; } if c[s..s+3]==['m','a','x'] { let ret = func(s+4,&c); let mut ans = vec![0;4]; for i in 0..3 { for j in 0..3 { ans[max(i,j)] += ret[i][j]; ans[max(i,j)] %= MOD; } } ans[3] = ret[0][3]+1; return ans; } if c[s..s+3]==['m','e','x'] { let ret = func(s+4,&c); let mut ans = vec![0;4]; for i in 0..3 { for j in 0..3 { for k in 0..3 { if k!=i&&k!=j { ans[k] += ret[i][j]; ans[k] %= MOD; break; } } } } ans[3] = ret[0][3]+1; return ans; } let ret = func(s+4,&c); let mut ans = vec![0;4]; for i in 0..3 { for j in 0..3 { for k in 0..3 { if k!=i&&k!=j { ans[k] += ret[i][j]; ans[k] %= MOD; break; } } } } for i in 0..3 { for j in 0..3 { ans[max(i,j)] += ret[i][j]; ans[max(i,j)] %= MOD; } } ans[3] = ret[0][3]+1; return ans; } fn func(s: usize, c: &Vec) -> Vec> { let x = solve(s,&c); let y = solve(x[3] as usize + 1, &c); let mut ans = vec![vec![0;4];4]; for i in 0..3 { for j in 0..3 { ans[i][j] += x[i]*y[j]; ans[i][j]%=MOD; } } ans[0][3] = y[3]; return ans; }