N = int(input()) ABC = [list(map(int, input().split())) for _ in range(N)] X = [[0] * 32 for _ in range(N)] INF = 10 ** 16 MAXX = [-INF] * 32 for i in range(N): A = ABC[i] for j in range(32): tmp = 0 x = j for k in range(5): if x & 1: tmp += A[k] else: tmp -= A[k] x >>= 1 X[i][j] = tmp MAXX[j] = max(MAXX[j], X[i][j]) for i in range(N): ans = 0 for j in range(32): ans = max(ans, MAXX[j] - X[i][j]) print(ans)