#include using namespace std; using ll = long long; template struct slope_trick { T minv, offsetL, offsetR; std::priority_queue pqL; std::priority_queue, std::greater> pqR; slope_trick() : minv(0), offsetL(0), offsetR(0) {} void add_relu(T x) { pqL.push(x - offsetL); minv += (pqL.top() + offsetL) - x; pqR.push(pqL.top() + offsetL - offsetR); pqL.pop(); } void add_irelu(T x) { pqR.push(x - offsetR); minv += x - (pqR.top() + offsetR); pqL.push(pqR.top() + offsetR - offsetL); pqR.pop(); } void L_shift(T x){ offsetL += x; } void R_shift(T x){ offsetR += x; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; slope_trick st; vector a(n); for(auto &&v : a) cin >> v; sort(a.begin(), a.end()); for(int i = 0; i < n; i++){ st.add_relu(a[i] - i); st.add_irelu(a[i] - i); while(!st.pqR.empty())st.pqR.pop(); } cout << st.minv << '\n'; }