#include using namespace std; #define rep(i, n) for (int i=0; i> N >> M; int A[N][N]; rep(i, N) rep(j, N) cin >> A[i][j]; int ans = 1000000; rep(S, 1<<(N+2)) { int cnt = 0; bool flag[N][N]; rep(i, N) rep(j, N) flag[i][j] = false; rep(i, N+2) if ((S>>i)&1) { cnt++; if (iM) continue; int cand = 0; rep(i, N) rep(j, N) if (flag[i][j]) cand += A[i][j]; vector needs; rep(i, N) { int need = 0; rep(j, N) if (!flag[i][j]) need += A[i][j]; needs.pb(need); } sort(needs.begin(), needs.end()); rep(i, M-cnt) cand += needs[i]; ans = min(ans, cand); } cout << ans << endl; }