use proconio::{input, marker::Bytes}; fn main() { let n = 8; input! { mut a: [Bytes; n], } a.iter_mut().flatten().for_each(|x| *x -= b'0'); let ans = dfs(&a, 1, &mut a[0].clone()); println!("{}", if ans { "Yes" } else { "No" }); } fn dfs(a: &Vec>, i: usize, current: &mut Vec) -> bool { let n = a.len(); if i == n { let res = current.iter().all(|&x| x == 0); return res; } let mut row = a[i].clone(); let mut res = false; for _ in 0..n { let possible = (0..n).all(|j| current[j] >= row[j]); if possible { for j in 0..n { current[j] -= row[j]; } res |= dfs(a, i + 1, current); for j in 0..n { current[j] += row[j]; } } row.rotate_left(1); } res }