fn main() { use std::io::prelude::*; let cin = std::io::stdin(); let reader = std::io::BufReader::new(cin.lock()); let mut lines = reader.lines(); lines.next(); let mut a: Vec = lines.next().unwrap().unwrap().split_whitespace().map(|x| x.parse().unwrap()).collect(); a.sort(); let m = a[a.len() / 2]; let ans = a.into_iter().fold(0, |acc, x| acc + (x - m).abs()); println!("{}", ans); }