#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>
#include <cassert>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define sz(a) int((a).size())
#define rep(i, s, n) for(int i = s; i <= (n); ++i)
#define rev(i, n, s) for(int i = (n); i >= s; --i)
#define fore(x, a) for(auto &&x : a)
typedef long long ll;
const int mod = 1000000007;
const int N = 655;
typedef long double DOUBLE;
typedef vector<DOUBLE> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;
const DOUBLE EPS = 1e-9;
struct LPSolver {
int m, n;
VI B, N;
VVD D;
LPSolver(const VVD &A, const VD &b, const VD &c) :
m(b.size()), n(c.size()), N(n + 1), B(m), D(m + 2, VD(n + 2)) {
for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) D[i][j] = A[i][j];
for (int i = 0; i < m; i++) { B[i] = n + i; D[i][n] = -1; D[i][n + 1] = b[i]; }
for (int j = 0; j < n; j++) { N[j] = j; D[m][j] = -c[j]; }
N[n] = -1; D[m + 1][n] = 1;
}
void Pivot(int r, int s) {
for (int i = 0; i < m + 2; i++) if (i != r)
for (int j = 0; j < n + 2; j++) if (j != s)
D[i][j] -= D[r][j] * D[i][s] / D[r][s];
for (int j = 0; j < n + 2; j++) if (j != s) D[r][j] /= D[r][s];
for (int i = 0; i < m + 2; i++) if (i != r) D[i][s] /= -D[r][s];
D[r][s] = 1.0 / D[r][s];
swap(B[r], N[s]);
}
bool Simplex(int phase) {
int x = phase == 1 ? m + 1 : m;
while (true) {
int s = -1;
for (int j = 0; j <= n; j++) {
if (phase == 2 && N[j] == -1) continue;
if (s == -1 || D[x][j] < D[x][s] || D[x][j] == D[x][s] && N[j] < N[s]) s = j;
}
if (D[x][s] >= -EPS) return true;
int r = -1;
for (int i = 0; i < m; i++) {
if (D[i][s] <= 0) continue;
if (r == -1 || D[i][n + 1] / D[i][s] < D[r][n + 1] / D[r][s] ||
D[i][n + 1] / D[i][s] == D[r][n + 1] / D[r][s] && B[i] < B[r]) r = i;
}
if (r == -1) return false;
Pivot(r, s);
}
}
DOUBLE Solve(VD &x) {
int r = 0;
for (int i = 1; i < m; i++) if (D[i][n + 1] < D[r][n + 1]) r = i;
if (D[r][n + 1] <= -EPS) {
Pivot(r, n);
if (!Simplex(1) || D[m + 1][n + 1] < -EPS) return -numeric_limits<DOUBLE>::infinity();
for (int i = 0; i < m; i++) if (B[i] == -1) {
int s = -1;
for (int j = 0; j <= n; j++)
if (s == -1 || D[i][j] < D[i][s] || D[i][j] == D[i][s] && N[j] < N[s]) s = j;
Pivot(i, s);
}
}
if (!Simplex(2)) return numeric_limits<DOUBLE>::infinity();
x = VD(n);
for (int i = 0; i < m; i++) if (B[i] < n) x[B[i]] = D[i][n + 1];
return D[m][n + 1];
}
};
int a[N];
int main() {
#ifdef loc
if(!freopen((string(FOLDER) + "inp.txt").c_str(), "r", stdin)) {
assert(0);
}
freopen((string(FOLDER) + "out.txt").c_str(), "w", stdout);
#endif
boost;
int n, k;
cin >> n >> k;
n *= 3;
int m = n + n - n / 3 + 1;
rep(i, 0, n - 1) {
cin >> a[i];
}
VVD A(m, VD(n,0.0));
VD B(m,0.0);
VD C(n, 0.0);
rep(i, 0, n - 1) {
C[i] = a[i];
}
rep(i, 0, n - n / 3) {
rep(j, i, i + n/3 - 1) {
A[i][j] = 1.0;
}
B[i] = k;
}
rep(i, 0, n - 1) {
A[i + n - n / 3 + 1][i] = 1.0;
B[i + n - n / 3 + 1] = 1.0;
}
VD X;
LPSolver solver(A, B, C);
double val = solver.Solve(X);
int res = (int)(val + 0.5);
cout << res << endl;
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4K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dW3NdOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtICsgMjsgaSsrKSBpZiAoaSAhPSByKSBEW2ldW3NdIC89IC1EW3JdW3NdOwogICAgRFtyXVtzXSA9IDEuMCAvIERbcl1bc107CiAgICBzd2FwKEJbcl0sIE5bc10pOwogIH0KICBib29sIFNpbXBsZXgoaW50IHBoYXNlKSB7CiAgICBpbnQgeCA9IHBoYXNlID09IDEgPyBtICsgMSA6IG07CiAgICB3aGlsZSAodHJ1ZSkgewogICAgICBpbnQgcyA9IC0xOwogICAgICBmb3IgKGludCBqID0gMDsgaiA8PSBuOyBqKyspIHsKICAgICAgICBpZiAocGhhc2UgPT0gMiAmJiBOW2pdID09IC0xKSBjb250aW51ZTsKICAgICAgICBpZiAocyA9PSAtMSB8fCBEW3hdW2pdIDwgRFt4XVtzXSB8fCBEW3hdW2pdID09IERbeF1bc10gJiYgTltqXSA8IE5bc10pIHMgPSBqOwogICAgICB9CiAgICAgIGlmIChEW3hdW3NdID49IC1FUFMpIHJldHVybiB0cnVlOwogICAgICBpbnQgciA9IC0xOwogICAgICBmb3IgKGludCBpID0gMDsgaSA8IG07IGkrKykgewogICAgICAgIGlmIChEW2ldW3NdIDw9IDApIGNvbnRpbnVlOwogICAgICAgIGlmIChyID09IC0xIHx8IERbaV1bbiArIDFdIC8gRFtpXVtzXSA8IERbcl1bbiArIDFdIC8gRFtyXVtzXSB8fAogICAgICAgICAgRFtpXVtuICsgMV0gLyBEW2ldW3NdID09IERbcl1bbiArIDFdIC8gRFtyXVtzXSAmJiBCW2ldIDwgQltyXSkgciA9IGk7CiAgICAgIH0KICAgICAgaWYgKHIgPT0gLTEpIHJldHVybiBmYWxzZTsKICAgICAgUGl2b3Qociwgcyk7CiAgICB9CiAgfQogIERPVUJMRSBTb2x2ZShWRCAmeCkgewogICAgaW50IHIgPSAwOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBtOyBpKyspIGlmIChEW2ldW24gKyAxXSA8IERbcl1bbiArIDFdKSByID0gaTsKICAgIGlmIChEW3JdW24gKyAxXSA8PSAtRVBTKSB7CiAgICAgIFBpdm90KHIsIG4pOwogICAgICBpZiAoIVNpbXBsZXgoMSkgfHwgRFttICsgMV1bbiArIDFdIDwgLUVQUykgcmV0dXJuIC1udW1lcmljX2xpbWl0czxET1VCTEU+OjppbmZpbml0eSgpOwogICAgICBmb3IgKGludCBpID0gMDsgaSA8IG07IGkrKykgaWYgKEJbaV0gPT0gLTEpIHsKICAgICAgICBpbnQgcyA9IC0xOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDw9IG47IGorKykKICAgICAgICAgIGlmIChzID09IC0xIHx8IERbaV1bal0gPCBEW2ldW3NdIHx8IERbaV1bal0gPT0gRFtpXVtzXSAmJiBOW2pdIDwgTltzXSkgcyA9IGo7CiAgICAgICAgUGl2b3QoaSwgcyk7CiAgICAgIH0KICAgIH0KICAgIGlmICghU2ltcGxleCgyKSkgcmV0dXJuIG51bWVyaWNfbGltaXRzPERPVUJMRT46OmluZmluaXR5KCk7CiAgICB4ID0gVkQobik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG07IGkrKykgaWYgKEJbaV0gPCBuKSB4W0JbaV1dID0gRFtpXVtuICsgMV07CiAgICByZXR1cm4gRFttXVtuICsgMV07CiAgfQp9OwoKaW50IGFbTl07CgppbnQgbWFpbigpIHsKI2lmZGVmIGxvYwogIGlmKCFmcmVvcGVuKChzdHJpbmcoRk9MREVSKSArICJpbnAudHh0IikuY19zdHIoKSwgInIiLCBzdGRpbikpIHsKICAgIGFzc2VydCgwKTsKICB9CiAgZnJlb3Blbigoc3RyaW5nKEZPTERFUikgKyAib3V0LnR4dCIpLmNfc3RyKCksICJ3Iiwgc3Rkb3V0KTsKI2VuZGlmCiAgYm9vc3Q7CiAgaW50IG4sIGs7CiAgY2luID4+IG4gPj4gazsKICBuICo9IDM7CiAgaW50IG0gPSBuICsgbiAtIG4gLyAzICsgMTsKICByZXAoaSwgMCwgbiAtIDEpIH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