N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] def f(a, b): return sum(abs(p-q) for p, q in zip(a, b)) ans = 10**18 for i in range(N): p = A[i] for j in range(i+1): q = A[j] r = [(x+y)//2 for x, y in zip(p, q)] ct = sum(f(r, a) for a in A) ans = min(ans, ct) print(ans)