#include using namespace std; const long long INF = 1000000000000000000; struct slope_trick{ long long mn; priority_queue L; priority_queue, greater> R; slope_trick(){ mn = 0; L.push(-INF); R.push(INF); } long long get_min(){ return mn; } void add_right(long long a){ mn += max(L.top() - a, (long long) 0); L.push(a); R.push(L.top()); L.pop(); } void add_left(long long a){ mn += max(a - R.top(), (long long) 0); R.push(a); L.push(R.top()); R.pop(); } }; int main(){ 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; } slope_trick f; for (int i = 0; i < N; i++){ f.add_left(A[i]); f.add_right(A[i]); while (!f.R.empty()){ f.R.pop(); } f.R.push(INF); } cout << f.mn << endl; }