import numpy as np # Load both columns into numpy arrays of type int left, right = np.loadtxt("input", dtype=int).T # Sort both lists (ASC) left.sort() right.sort() # Just calculate the distances. distances = np.abs(left - right) distance = np.sum(distances) print(f"The total distance is {distance}.")