#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, ans = 1 << 30; 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]; } } for(int i = 0; i < (1 << (n + 2)); i++){ int need = m - __builtin_popcount(i); if(need > n) continue; int s = 0; vector b(n); bool nnm1 = i >> n & 1, nnm2 = (i >> (n + 1)) & 1; for(int y = 0; y < n; y++){ for(int x = 0; x < n; x++){ if(i >> x & 1){ s += A[y][x]; continue; } if(nnm1 && y == x){ s += A[y][x]; continue; } if(nnm2 && y + x == n - 1){ s += A[y][x]; continue; } b[y] += A[y][x]; } } sort(b.begin(), b.end()); for(int y = 0; y < need; y++)s += b[y]; ans = min(ans, s); } cout << ans << '\n'; }