use std::io::*; const INF: usize = 1usize << 60; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let m: usize = itr.next().unwrap().parse().unwrap(); let a: Vec> = (0..n) .map(|_| { (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect() }) .collect(); let mut ans = INF; for S in 0..1 << n + 2 { let cnt = (S as u32).count_ones() as usize; if cnt + n < m || cnt > m { continue; } let mut used = vec![vec![false; n]; n]; let mut cost = 0; for i in 0..n { if S >> i & 1 == 1 { for j in 0..n { cost += a[i][j]; used[i][j] = true; } } } if S >> n & 1 == 1 { for i in 0..n { if !used[i][i] { cost += a[i][i]; used[i][i] = true; } } } if S >> n + 1 & 1 == 1 { for i in 0..n { if !used[n - 1 - i][i] { cost += a[n - 1 - i][i]; used[n - 1 - i][i] = true; } } } let mut b = Vec::new(); for j in 0..n { let mut tmp = 0; for i in 0..n { if !used[i][j] { tmp += a[i][j]; } } b.push(tmp); } b.sort(); for i in 0..m - cnt { cost += b[i]; } ans = std::cmp::min(ans, cost); } println!("{}", ans); }