import numpy as np
N = int(input())
loc = np.array([[0,0]], dtype = "int32")
for i in range(N):
    tmp = np.array([int(j) for j in input().split()]).reshape(1,2)
    loc = np.append(loc, tmp, axis = 0)

    
mat = np.zeros((N,N), dtype = "int32")
for i in range(N):
    for j in range(N):
        mat[i,j] = np.min(abs(loc[i]-loc[j]))
        if i == j:
            mat[i,j] = int(1e9)
res = np.min(mat, axis = 0)
print(np.sum(res))
