use proconio::input; use proconio::marker::Chars; fn main () { input! { n: usize, b: [Chars;n], } //println!("{:?}",b); let mut ans = 0; let b = b.iter() .map(|row| { row.iter() .map(|&c| { match c { 'A' => 1, 'B' => -1, _ => 0, } }) .collect::>() }) .collect::>>(); ans += b.iter() .filter(|&row| { row.iter() .fold(0, |sum, &x| { sum + x }) == (n-1) as i32 }) .count(); ans += (0..n) .filter(|&col| { b.iter() .fold(0, |sum, row| { sum + row[col] }) == (n-1) as i32 }) .count(); let mut tmp = 0; for i in 0..n { tmp += b[i][i]; } if tmp == (n-1) as i32 {ans += 1;} tmp = 0; for i in 0..n { tmp += b[n-1-i][i]; } if tmp == (n-1) as i32 {ans += 1;} println!("{}", ans); }