#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int a[20][20]; int s[40]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { s[2 * n] += a[i][i]; s[2 * n + 1] += a[i][n - i - 1]; for (int j = 0; j < n; j++) { s[i] += a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { s[n + i] += a[j][i]; } } int ans = 0; for (int i = 0; i < m; i++) { int ans1 = 1000000007, n1; for (int j = 0; j < 2 * n + 2; j++) { if (ans1 > s[j]) { ans1 = s[j]; n1 = j; } } if (n1 == 2 * n + 1) { for (int j = 0; j < n; j++) { s[j] -= a[j][n - j - 1]; s[2 * n - j - 1] -= a[j][n - j - 1]; } } else if (n1 == 2 * n) { for (int j = 0; j < n; j++) { s[j] -= a[j][j]; s[n + j] -= a[j][j]; } } else if (n1 >= n) { for (int j = 0; j < n; j++) { s[j] -= a[j][n1 - n]; } } else { for (int j = 0; j < n; j++) { s[n + j] -= a[n1 - n][j]; } } s[n1] = 1000000007; ans += ans1; } cout << ans << endl; }