use std::io::{stdin, Read};
use libc::{clock_gettime, timespec, CLOCK_PROCESS_CPUTIME_ID};

fn main() {
    let mut data = String::new();
    stdin().read_to_string(&mut data).unwrap();

    let mut begin = timespec {
        tv_sec: 0,
        tv_nsec: 0,
    };
    unsafe {
        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mut begin);
    };

    let mut num1 = vec![];
    let mut num2 = vec![];

    for line in data.lines() {
        let numbers: Vec<&str> = line.split("   ").collect();
        let num11: i32 = numbers[0].parse().unwrap();
        let num22: i32 = numbers[1].parse().unwrap();
        num1.push(num11);
        num2.push(num22);
    }
    num1.sort_unstable();
    num2.sort_unstable();

    let mut sum = 0;
    for i in 0..num1.len() {
        let num_sum = num1[i].abs_diff(num2[i]);
        sum += num_sum;
    }

    let mut end = timespec {
        tv_sec: 0,
        tv_nsec: 0,
    };
    unsafe {
        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mut end);
    };
    println!("{sum:?}");
    println!(
        "time: {:.6}ms",
        (end.tv_nsec - begin.tv_nsec) as f32 / 1000.0 / 1000.0
    );
}
