#!/usr/bin/env python3 from typing import List class Solution: def __init__(self) -> None: self.lines: List[str] = [] self.left_array: List[int] = [] self.right_array: List[int] = [] self.result: int = 0 def read(self) -> None: with open("input") as f: self.lines = f.readlines() def clean(self) -> None: for i in range(len(self.lines)): self.lines[i] = self.lines[i].strip() def split_lines(self) -> None: for line in self.lines: elements: List[str] = line.split() clean_element: int = int(elements[0]) self.left_array.append(clean_element) clean_element: int = int(elements[1]) self.right_array.append(clean_element) def sort_lists(self) -> None: self.left_array.sort() self.right_array.sort() def calculate_difference(self) -> None: for i in range(len(self.left_array)): difference: int = abs(self.right_array[i] - self.left_array[i]) self.result += difference def main() -> None: solver: Solution = Solution() solver.read() solver.clean() solver.split_lines() solver.sort_lists() solver.calculate_difference() print(solver.result) if __name__ == "__main__": main()