#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template class SlopeTrick { public: SlopeTrick() { min_f = 0; add_l = 0; add_r = 0; } void add_pos(T a){ // add max(x-a, 0) l.push(a-add_l); T l0 = l.top()+add_l; l.pop(); r.push(l0-add_r); min_f += max(l0-a, 0); } void add_neg(T a){ // add max(a-x, 0) r.push(a-add_r); T r0 = r.top()+add_r; r.pop(); l.push(r0-add_l); min_f += max(a-r0, 0); } void slide_neg(T a){ add_l += a; } void slide_pos(T a){ add_r += a; } T get_min(){ return min_f; } void clear_right(){ while(!r.empty()) r.pop(); } /** * be careful that this method takes O(NlonN) time (N := r.size()+l.size()). */ T eval(T x) { T ans = min_f; vector buf; while(!l.empty()){ buf.push_back(l.top()); l.pop(); } for(T a: buf){ l.push(a); ans += max(a+add_l-x, 0); } buf.clear(); while(!r.empty()){ buf.push_back(r.top()); r.pop(); } for(T a: buf){ r.push(a); ans += max(x-a-add_r, 0); } return ans; } private: priority_queue l; priority_queue, greater> r; T min_f; T add_l; T add_r; }; using P = pair; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector a(n); for(int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); for(int i = 0; i < n; i++) a[i] -= i; SlopeTrick st; for(int i = 0; i < n; i++){ st.clear_right(); st.add_pos(a[i]); st.add_neg(a[i]); } cout << st.get_min() << endl; }