use proconio::{input, marker::Chars}; fn main() { input! { h: usize, w: usize, mut s: [Chars; h], } if w < 6 { for s in s { println!("{}", s.iter().collect::()); } return; } for i in 0..h { let mut j = 0; while j + 5 < w { if &s[i][j..j + 6] == &['y', 'i', 'w', 'i', 'y', '9'] { s[i][j + 4] = 'Y'; j += 6 } else if &s[i][j..j + 6] == &['9', 'y', 'i', 'w', 'i', 'y'] { s[i][j + 1] = 'Y'; j += 6 } else { j += 1; } } println!("{}", s[i].iter().collect::()); } }