#include #include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repll(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep2(i, n, m) for (int i = n; i < (int)(m); i++) #define repll2(i, n, m) for (long long i = n; i < (long long)(m); i++) #define all(v) v.begin(),v.end() using ll=long long; using ld=long double; using vi=vector; using vvi=vector; using vvvi=vector; using vl=vector; using vvl=vector; using vvvl=vector; using vld=vector; using vvld=vector; int dx[8]={1,0,-1,0,1,1,-1,-1}; int dy[8]={0,1,0,-1,1,-1,1,-1}; const double PI = acos(-1); //const ll MOD=1e9+7; //const ll MOD=998244353; const ll INF=(1LL<<60); const int INF2=(1<<30); //using mint=modint1000000007; //using mint=modint998244353; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n;cin>>n; vvl arr(n); //vector> vmst(32); vector> vtop2(32,vl(2,-INF)); rep(i,n){ ll a[5]; rep(j,5)cin>>a[j]; rep(j,1<<5){ ll s=0; rep(k,5){ if(j&(1<=vtop2[j][0]){ vtop2[j][1]=vtop2[j][0]; vtop2[j][0]=s; } else if(s>vtop2[j][1]){ vtop2[j][1]=s; } arr[i].push_back(s); } } rep(i,n){ //rep(j,1<<5){ // vmst[j].erase(vmst[j].lower_bound(arr[i][j])); //} ll ans=-INF; rep(j,1<<5){ ll v=arr[i][j],vs=arr[31-i][j]; ll u0=vtop2[31-j][0],u1=vtop2[31-j][1]; if(u0==vs)ans=max(ans,u1+v); else ans=max(ans,v+u0); } cout<