/* -*- coding: utf-8 -*- * * 1792.cc: No.1792 科学の甲子園 - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 10000; const int M = 6; const int MBITS = 1 << M; const int MMSK = MBITS - 1; const int K = 4; /* typedef */ typedef long long ll; /* global variables */ int ps[MAX_N][M]; ll sps[MBITS], dp[2][K + 1][MBITS]; /* subroutines */ inline void setmax(ll &a, ll b) { if (a < b) a = b; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; j < M; j++) scanf("%d", ps[i] + j); dp[0][0][0] = 1; int cur = 0, nxt = 1; for (int i = 0; i < n; i++) { for (int bits = 0; bits < MBITS; bits++) { ll mp = 1; for (int j = 0, bj = 1; j < M; j++, bj <<= 1) if (bits & bj) mp *= ps[i][j]; sps[bits] = mp; } memset(dp[nxt], 0, sizeof(dp[nxt])); for (int k = 0; k <= K; k++) for (int bits = 0; bits < MBITS; bits++) if (dp[cur][k][bits] > 0) { setmax(dp[nxt][k][bits], dp[cur][k][bits]); if (k < K) for (int bits1 = 1; bits1 < MBITS; bits1++) if (! (bits & bits1)) setmax(dp[nxt][k + 1][bits | bits1], dp[cur][k][bits] * sps[bits1]); } swap(cur, nxt); } ll maxd = 0; for (int k = 0; k <= K; k++) setmax(maxd, dp[cur][k][MMSK]); printf("%lld\n", maxd); return 0; }