def calculate_total_distance_from_input(input_data):
# Parse the input into two lists
left_list = []
right_list = []
for line in input_data.strip().split("\n"):
left, right = map(int, line.split())
left_list.append(left)
right_list.append(right)
# Sort both lists
left_sorted = sorted(left_list)
right_sorted = sorted(right_list)
# Calculate the total distance
total_distance = 0
for left, right in zip(left_sorted, right_sorted):
total_distance += abs(left - right)
return total_distance
# Example Input
input_data = """
76309 75213
79731 28444
29583 71339
60992 99148
34680 74530
45691 82519
55358 22047
95523 45384
37661 82208
33464 91461
26897 96393
76556 76554
82316 98880
92079 23082
55539 10033
65931 66060
98880 60464
19348 41458
72003 84074
78401 78856
53187 72003
"""
# Calculate and print the result
result = calculate_total_distance_from_input(input_data)
print("Total Distance:", result)
ZGVmIGNhbGN1bGF0ZV90b3RhbF9kaXN0YW5jZV9mcm9tX2lucHV0KGlucHV0X2RhdGEpOgogICAgIyBQYXJzZSB0aGUgaW5wdXQgaW50byB0d28gbGlzdHMKICAgIGxlZnRfbGlzdCA9IFtdCiAgICByaWdodF9saXN0ID0gW10KICAgIAogICAgZm9yIGxpbmUgaW4gaW5wdXRfZGF0YS5zdHJpcCgpLnNwbGl0KCJcbiIpOgogICAgICAgIGxlZnQsIHJpZ2h0ID0gbWFwKGludCwgbGluZS5zcGxpdCgpKQogICAgICAgIGxlZnRfbGlzdC5hcHBlbmQobGVmdCkKICAgICAgICByaWdodF9saXN0LmFwcGVuZChyaWdodCkKICAgIAogICAgIyBTb3J0IGJvdGggbGlzdHMKICAgIGxlZnRfc29ydGVkID0gc29ydGVkKGxlZnRfbGlzdCkKICAgIHJpZ2h0X3NvcnRlZCA9IHNvcnRlZChyaWdodF9saXN0KQogICAgCiAgICAjIENhbGN1bGF0ZSB0aGUgdG90YWwgZGlzdGFuY2UKICAgIHRvdGFsX2Rpc3RhbmNlID0gMAogICAgZm9yIGxlZnQsIHJpZ2h0IGluIHppcChsZWZ0X3NvcnRlZCwgcmlnaHRfc29ydGVkKToKICAgICAgICB0b3RhbF9kaXN0YW5jZSAr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