#include //#include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define rep2(i, a, b) for (int i = (int)a; i < (int)(b); ++i) #define rrep2(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i) template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int MAX_N = 100000; constexpr ll INF = 6000000000000000; ll A[MAX_N][5]; ll min_right[MAX_N][32]; int main(){ int N; scanf("%d", &N); rep(i, N) rep(j, 5) scanf("%lld", &A[i][j]); fill(min_right[N-1],min_right[N-1]+32,INF); rrep(i, N){ if(i){ copy(min_right[i],min_right[i]+32,min_right[i-1]); rep(j, 32){ ll sum = 0; rep(k, 5) sum += j>>k&1 ? A[i][k] : -A[i][k]; chmin(min_right[i-1][j], sum); } } } ll min_left[32]; fill(min_left,min_left+32,INF); rep(i, N){ ll ans = 0; rep(j, 32){ ll sum = 0; rep(k, 5) sum += j>>k&1 ? A[i][k] : -A[i][k]; chmax(ans, sum - min(min_left[j], min_right[i][j])); chmin(min_left[j], sum); } printf("%lld\n", ans); } return 0; }