use std::io::{BufRead, Write}; use std::cmp; fn main() { const INF: i32 = 1 << 30; const MAXY: usize = 10_000; let stdin = std::io::stdin(); let stdout = std::io::stdout(); let mut reader = std::io::BufReader::new(stdin.lock()); let mut writer = std::io::BufWriter::new(stdout.lock()); let n: usize = { let mut buf = String::new(); reader.read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; let y: Vec = { let mut buf = String::new(); reader.read_line(&mut buf).unwrap(); let iter = buf.split_whitespace(); iter.map(|x| x.parse().unwrap()).collect() }; let mut dp = vec![INF; MAXY as usize + 1]; dp[0] = 0; for i in 0..n { let mut min = INF; for j in 0..(MAXY + 1) { min = cmp::min(min, dp[j]); dp[j] = min + (y[i] - j as i32).abs(); } } let ans = dp.iter().min().unwrap(); writeln!(writer, "{}", ans).unwrap(); }