#include using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) int a[6][10000]; int mx1[6], mx2[6][6], mx3[6][6][6]; int main() { int n; cin >> n; rep(i, n) rep(s, 6) cin >> a[s][i]; rep(s1, 6) { int mx = 0; rep(i, n) { int tmp = a[s1][i]; if (tmp > mx) mx = tmp; } mx1[s1] = mx; } rep(s1, 6) rep(s2, s1) { int mx = 0; rep(i, n) { int tmp = a[s1][i] * a[s2][i]; if (tmp > mx) mx = tmp; } mx2[s1][s2] = mx; } rep(s1, 6) rep(s2, s1) rep(s3, s2) { int mx = 0; rep(i, n) { int tmp = a[s1][i] * a[s2][i] * a[s3][i]; if (tmp > mx) mx = tmp; } mx3[s1][s2][s3] = mx; } long long ans = 0; rep(s1, 6) rep(s2, s1) rep(s3, s2) rep(s4, s3) { long long mx = max({(long long)mx2[s1][s2] * mx2[s3][s4], (long long)mx2[s1][s3] * mx2[s2][s4], (long long)mx2[s1][s4] * mx2[s2][s3]}); int b = 63 ^ (1 << s1) ^ (1 << s2) ^ (1 << s3) ^ (1 << s4); while(b) { int k = __builtin_ctz(b); mx *= mx1[k]; b ^= 1 << k; } ans = max(ans, mx); } rep(s1, 6) rep(s2, s1) rep(s3, s2) { long long mx = mx3[s1][s2][s3]; int b = 63 ^ (1 << s1) ^ (1 << s2) ^ (1 << s3); while(b) { int k = __builtin_ctz(b); mx *= mx1[k]; b ^= 1 << k; } ans = max(ans, mx); } cout << ans << endl; }