# Initialize the lists to hold the numbers list1 = [] list2 = [] # Open the file for reading with open('input.txt', 'r') as file: for line in file: # Strip the line of leading/trailing whitespace stripped_line = line.strip() # Check if the line contains two numbers separated by three whitespaces if stripped_line.count(' ') == 1: # Ensure exactly three whitespaces parts = stripped_line.split(' ') if len(parts) == 2: # Ensure there are exactly two parts try: # Convert parts to numbers and add to respective lists num1 = int(parts[0]) num2 = int(parts[1]) list1.append(num1) list2.append(num2) except ValueError: # Skip lines where conversion fails continue # Output the results list1.sort() list2.sort() zipped = zip(list1,list2) total_distance = 0 similarity_score = 0 for pair in zipped: total_distance += abs(pair[0]-pair[1]) similarity_score += pair[0]*list2.count(pair[0]) print(total_distance,similarity_score)