use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let _n: usize = it.next().unwrap().parse().unwrap(); let a: Vec = it.map(|s| s.parse().unwrap()).collect(); let w = 10000; let mut dp = vec![0i32; w + 1]; for i in 0..=w { dp[i] = (i as i32 - a[0]).abs(); } for &a in a.iter().skip(1) { let mut next = vec![std::i32::MAX / 10; w + 1]; let mut val = std::i32::MAX / 10; for i in 0..=w { val = std::cmp::min(val, dp[i]); next[i] = val + (a - i as i32).abs(); } dp = next; } let ans = dp.into_iter().min().unwrap(); println!("{}", ans); } fn main() { run(); }