#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template struct SlopeTrick { const T inf; explicit SlopeTrick( const T min_f = 0, const T inf = std::numeric_limits::max()) : inf(inf), added_l(0), added_r(0), min_f(min_f) {} T min() const { return min_f; } std::pair argmin() const { return {top_l(), top_r()}; } template U f(const U x) { U f_x = min_f; std::vector tmp; for (; top_l() > x; l.pop()) { const T t = top_l(); f_x += t - x; tmp.emplace_back(t); } for (; !tmp.empty(); tmp.pop_back()) { emplace_l(tmp.back()); } for (; top_r() < x; r.pop()) { const T t = top_r(); f_x += x - t; tmp.emplace_back(t); } for (; !tmp.empty(); tmp.pop_back()) { emplace_r(tmp.back()); } return f_x; } void constant_function(const T c) { min_f += c; } void x_minus_a(const T a) { const T t = top_l(); if (t <= a) { emplace_r(a); } else { min_f += t - a; emplace_l(a); l.pop(); emplace_r(t); } } void a_minus_x(const T a) { const T t = top_r(); if (a <= t) { emplace_l(a); } else { min_f += a - t; emplace_r(a); r.pop(); emplace_l(t); } } void abs_x_minus_a(const T a) { x_minus_a(a); a_minus_x(a); } void cumulative_min() { while (!r.empty()) r.pop(); added_r = 0; } void rcumulative_min() { while (!l.empty()) l.pop(); added_l = 0; } void translate(const T a) { sliding_window_minimum(a, a); } void sliding_window_minimum(const T a, const T b) { assert(a <= b); added_l += a; added_r += b; } private: T added_l, added_r, min_f; std::priority_queue l; std::priority_queue, std::greater> r; void emplace_l(const T a) { l.emplace(a - added_l); } void emplace_r(const T a) { r.emplace(a - added_r); } T top_l() const { return l.empty() ? -inf : l.top() + added_l; } T top_r() const { return r.empty() ? inf : r.top() + added_r; } }; int main() { int n; cin >> n; vector a(n); REP(i, n) cin >> a[i]; ranges::sort(a); SlopeTrick slope_trick(0); REP(i, n) { slope_trick.cumulative_min(); slope_trick.abs_x_minus_a(a[i] - i); } cout << slope_trick.min() << '\n'; return 0; }