#define ENABLE_DEBUG 1 // Kana's kitchen {{{ #include #define ALL(v) std::begin(v),std::end(v) #define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++) using i32 = std::int_least32_t; using i64 = std::int_least64_t; using u32 = std::uint_least32_t; using u64 = std::uint_least64_t; using usize = std::size_t; template using pair = std::pair; template using diag_pair = std::pair; template using tuple = std::tuple; template using vec = std::vector; template using numr = std::numeric_limits; #ifdef NGTKANA #include #else #define DEBUG(...)(void)0 #endif /*}}}*/ auto cmn = [](auto& x, auto y){ if (x>y) { x=y; return true; } return false; }; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::setprecision(15) << std::fixed; i64 max = 10'000; i64 n; std::cin >> n; vec dp(max+1); while (n--) { i64 x; std::cin >> x; for (i64 i=0; i<=max; i++) { dp.at(i) += std::abs(i - x); } for (i64 i=1; i<=max; i++) { cmn(dp.at(i), dp.at(i-1)); } } std::cout << dp.at(max) << '\n'; }