#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector > a(n, vector(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; int ret = 1<<30; for (int mask = 0; mask < 1< cols(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ((mask & 1 << i) || (l && i == j) || (r && i + j == n - 1)) cost += a[i][j]; else cols[j] += a[i][j]; } } sort(cols.begin(), cols.end()); int tot = __builtin_popcountll(mask) + l + r; for (int i = 0; i < m - tot; i++) cost += cols[i]; ret = min(ret, cost); } } } cout << ret << endl; return 0; }