#include <stdio.h>
#include <list>
#include <iostream>
#include <fstream>

using namespace std;

list<int> listOne{};
list<int> listTwo{};

int totalDistance = 0;

int main(){

    ifstream puzzle("input.txt");

    int tempOne, tempTwo;

    while (puzzle >> tempOne >> tempTwo)
    {
        listOne.push_back(tempOne);
        listTwo.push_back(tempTwo);
    }

    puzzle.close();

    listOne.sort();
    listTwo.sort();

    for (int x=0; !listOne.empty();x++){
        totalDistance += abs(listOne.front() - listTwo.front());
        listOne.pop_front();
        listTwo.pop_front();
    }

    printf("total distance: %i\n", totalDistance);
}