use proconio::input; fn main() { input! { h: usize, w: usize, mut a: [[usize; w]; h], } for i in 0..h - 1 { for j in 0..w - 1 { if a[i][j] == 1 { for di in 0..2 { for dj in 0..2 { a[i + di][j + dj] ^= 1; } } } } } let mut ans = a.iter().flatten().sum::(); let mut bottomright = 0; for di in 0..2 { for dj in 0..2 { bottomright += a[h - 2 + di][w - 2 + dj]; } } if bottomright == 3 { ans -= 2; } println!("{ans}"); }