#include #include #include constexpr int X = 10000; constexpr int INF = 1 << 30; void solve() { int n; std::cin >> n; std::vector dp(X + 1, 0); while (n--) { int y; std::cin >> y; int min = INF; for (int x = 0; x <= X; ++x) { min = std::min(min, dp[x]); dp[x] = min + std::abs(y - x); } } std::cout << *std::min_element(dp.begin(), dp.end()) << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }