fn is_ok(s: &Vec, t: &Vec) -> bool { let m = s.len(); let diff_point = (0..=m).filter(|&i| if i == m { true } else { s[i] != t[i] }).nth(0).unwrap(); !(diff_point..m).any(|i| s[i] != t[i+1]) } fn main() { let mut nm = String::new(); std::io::stdin().read_line(&mut nm).ok(); let nm: Vec = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nm[0]; let m = nm[1]; let words = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp = temp.trim(); temp.chars().collect::>() }) .collect::>(); let s1 = &words[0]; let s2 = &words[1]; let same_s = (0..m).filter(|&i| s1[i] != s2[i]).nth(0).unwrap(); let same_e = (0..m).rev().filter(|&i| s1[i] != s2[i]).nth(0).unwrap()+1; let t1 = format!("{}{}{}{}", (0..same_s).map(|i| s1[i].to_string()).collect::>().join(""), (same_s..same_e).map(|i| s1[i].to_string()).collect::>().join(""), s2[same_e-1], (same_e..m).map(|i| s1[i].to_string()).collect::>().join("") ) .chars().collect::>(); let t2 = format!("{}{}{}{}", (0..same_s).map(|i| s1[i].to_string()).collect::>().join(""), (same_s..same_e).map(|i| s2[i].to_string()).collect::>().join(""), s1[same_e-1], (same_e..m).map(|i| s1[i].to_string()).collect::>().join("") ) .chars().collect::>(); let mut result = 0usize; if (0..n).filter(|&i| is_ok(&words[i], &t1)).count() == n { result += 1; } if (0..n).filter(|&i| is_ok(&words[i], &t2)).count() == n { result += 1; } println!("{}", result); }