# 嘘 from sys import stdin input=lambda :stdin.readline()[:-1] n=int(input()) a=[list(map(int,input().split())) for i in range(n)] c=[(sum(a[i]),i) for i in range(n)] c.sort() use=[] for i in range(100): if c: use.append(c.pop()[1]) c=c[::-1] for i in range(100): if c: use.append(c.pop()[1]) for i in range(n): ans=0 for j in use: diff=0 for k in range(5): diff+=abs(a[i][k]-a[j][k]) ans=max(ans,diff) print(ans)