N = int(input()) l = [] for _ in range(N): s = list(map(int,input().split())) l.append(s) M = [-10 ** 16] * 32 m = [10 ** 16] * 32 for s in l: for bit in range(32): tmp = 0 for i in range(5): if bit >> i & 1: tmp += s[i] else: tmp -= s[i] if tmp > M[bit]:M[bit] = tmp if tmp < m[bit]:m[bit] = tmp for s in l: ans = 0 for bit in range(32): tmp = 0 for i in range(5): if bit >> i & 1: tmp += s[i] else: tmp -= s[i] t = abs(M[bit] - tmp) if t > ans:ans = t t = abs(m[bit] - tmp) if t > ans: ans = t print(ans)