#include #include #include using namespace atcoder; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 int main(){ int n; cin>>n; vector a(n,vector(6)); rep(i,n){ rep(j,6)cin>>a[i][j]; } vector dp(5,vector(1<<6,0)); dp[0][0] = 1; rep(i,n){ vector ndp(5,vector(1<<6,0)); rep(cnt,5){ rep(j,1<<6){ ndp[cnt][j] = max(ndp[cnt][j],dp[cnt][j]); if(cnt==4)continue; rep(k,1<<6){ if(j&k)continue; long long v =dp[cnt][j]; rep(l,6){ if((k>>l)&1)v *= a[i][l]; } ndp[cnt+1][j|k] = max(ndp[cnt+1][j|k],v); } } } swap(dp,ndp); } cout<