n = int(input())
a = []
b = []
c = []
for _ in range(n):
ai, bi, ci = map(int, input().split())
a.append(ai)
b.append(bi)
c.append(ci)
a = sorted(a)
b = sorted(b)
c = sorted(c)
x = a[n//2]
y = b[n//2]
z = c[n//2]
print(sum([abs(a[i] - x) + abs(b[i] - y) + abs(c[i] - z) for i in range(n)]))