#include #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll ILL=2167167167167167167; const int INF=2100000000; const int mod=998244353; #define rep(i,a,b) for (ll i=a;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";} template void vec_out(vector &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} namespace po167{ template struct slope_trick{ std::priority_queue left_pq; std::priority_queue,std::greater> right_pq; T min_f; T add_l,add_r; slope_trick():min_f(0),add_l(0),add_r(0){}; //f(x)=min(f(i)) i<=x void left_min(){ right_pq={}; add_r=0; } //f(x)=min(f(i)) i>=x void right_min(){ left_pq={}; add_l=0; } void add_constant_function(T d){ min_f+=d; } //f(x)<- f(x)+max(x-a,0) void add_x_minus_a(T a){ a-=add_l; if(!left_pq.empty()){ min_f+=std::max(left_pq.top()-a,(T)0); } left_pq.push(a); right_pq.push(left_pq.top()+add_l-add_r); left_pq.pop(); } //f(x) <- f(x)+max(a-x,0) void add_a_minus_x(T a){ a-=add_r; if(!right_pq.empty()){ min_f+=std::max(a-right_pq.top(),(T)0); } right_pq.push(a); left_pq.push(right_pq.top()+add_r-add_l); right_pq.pop(); } //f(x) <- f(x) + |x-a| void add_abs_x_minus_a(T a){ add_a_minus_x(a); add_x_minus_a(a); } //f(x) <- f(x-a) void shift(T a){ add_l+=a; add_r+=a; } //f(x) <- min(f(x-i)) i= a~b //need: a<=b void sliding_min(T a,T b){ assert(a<=b); add_l+=a; add_r+=b; } void merge_and_break(slope_trick &S){ min_f+=S.min_f; T tmp; while(!S.left_pq.empty()){ tmp=S.left_pq.top(); S.left_pq.pop(); add_a_minus_x(S.add_l+tmp); } while(!S.right_pq.empty()){ tmp=S.right_pq.top(); S.right_pq.pop(); add_x_minus_a(S.add_r+tmp); } } void merge_and_remain(slope_trick S){ merge_and_break(S); } }; } using po167::slope_trick; void solve(); // oddloop int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t=1; //cin>>t; rep(i,0,t) solve(); } void solve(){ int N; cin>>N; vector A(N); rep(i,0,N) cin>>A[i]; slope_trick S; So(A); rep(i,0,N){ S.left_min(); S.add_abs_x_minus_a(A[i]-i); } cout<