def calc(A, index): ans = 0 for i in range(5): ans += A[i] * (index % 2 * 2 - 1) index //= 2 return ans N = int(input()) items = [None for i in range(N)] dp = [-float('inf') for i in range(2 ** 5)] for i in range(N): items[i] = list(map(int, input().split())) for j in range(2 ** 5): dp[j] = max(dp[j], calc(items[i], j)) for i in range(N): ans = -float('inf') for j in range(2 ** 5): ans = max(ans, dp[j] - calc(items[i], j)) print(ans)