N = int(input()) ls = [list(map(int, input().split())) for _ in range(N)] ls2 = [] for i in range(1 << 5): tmp = [] for j in range(N): s = 0 for k in range(5): if (i >> k) & 1 == 0: s += ls[j][k] else: s -= ls[j][k] tmp.append((s, j)) tmp.sort() ls2.append(tmp[0][1]) ls2.append(tmp[-1][1]) for k in range(N): ans = 0 for i in ls2: s = 0 for j in range(5): s += abs(ls[k][j] - ls[i][j]) ans = max(ans, s) print(ans)