mod io { #[macro_export] macro_rules! scan { ($r:expr, [$t:tt; $n:expr]) => ( (0..$n).map(|_| scan!($r, $t)).collect::>() ); ($r:expr, ($($t:tt),*)) => (($(scan!($r, $t)),*)); ($r:expr, Usize1) => (scan!($r, usize) - 1); ($r:expr, String) => (String::from_utf8(scan!($r, Bytes)).unwrap()); ($r:expr, Bytes) => (io::scan($r)); ($r:expr, Chars) => (scan!($r, String).chars().collect::>()); ($r:expr, $t:ty) => (scan!($r, String).parse::<$t>().unwrap()); } use std::io::{BufRead, ErrorKind}; pub fn scan(r: &mut R) -> Vec { let mut buf = Vec::new(); loop { let (done, used) = { let available = match r.fill_buf() { Ok(n) => n, Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, Err(e) => panic!(e), }; match available.iter().position(u8::is_ascii_whitespace) { Some(i) => { buf.extend_from_slice(&available[..i]); (buf.len() > 0, i + 1) } None => { buf.extend_from_slice(available); (false, available.len()) } } }; r.consume(used); if done || used == 0 { return buf; } } } } use std::io::{BufRead, Write}; fn run(reader: &mut R, writer: &mut W) { let n = scan!(reader, usize); let mut c = scan!(reader, [i64; n]); let sum = c.iter().sum::(); if sum > 0 { c.sort_by(|a, b| b.cmp(a)); } else { c.sort(); } let a = c.iter().step_by(2).sum::(); let b = c.iter().skip(1).step_by(2).sum::(); let ans = a.abs() - b.abs(); writeln!(writer, "{}", ans).ok(); } fn main() { let (stdin, stdout) = (std::io::stdin(), std::io::stdout()); let mut reader = std::io::BufReader::new(stdin.lock()); let mut writer = std::io::BufWriter::new(stdout.lock()); run(&mut reader, &mut writer); }