Problem: problem

Given a sequence $ A $ of length $ N $. You can swap the $ i $ th and $ j $ th ($ 0 \ leq i, j \ leq N-1 $) elements of a sequence up to $ M $ times.

Find the maximum value of $ \ sum_ {i = 0} ^ {N -1} abs (A_i --i) $ in the sequence created by the operation.



output

Find the maximum value of $ \ sum_ {i = 0} ^ {N --1} abs (A_i --i) $ in the sequence created by the operation. Also, output a line feed at the end.

Example

Input

5 2
0 3 2 1 4


Output

12

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M;
LL A[100001];
vector<LL>v;
typedef pair<LL,LL>P;
priority_queue<P>q;
priority_queue<P,vector<P>,greater<P> >qq;

int main(){
	cin>>N>>M;
	REP(i,N){
		cin>>A[i];
		v.push_back(A[i]);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	int mid=N-1;
	REP(i,N){
		if(v[i]<=i){
			mid=i;
			break;
		}
	}
	REP(i,mid){
		if(A[i]<=mid){
			qq.push(P(max((LL)i,A[i]),i));
		}
	}
	for(int i=mid;i<N;i++){
		if(A[i]>=mid){
			q.push(P(min((LL)i,A[i]),i));
		}
	}
	REP(i,M){
		if(q.empty())break;
		if(qq.empty())break;
		P p=q.top();q.pop();
		P pp=qq.top();qq.pop();
		if(pp.first>p.first)continue;
		//cout<<pp.second<<" "<<p.second<<endl;
		LL temp=A[p.second];
		A[p.second]=A[pp.second];
		A[pp.second]=temp;
	}
	LL ans=0;
	REP(i,N){
		ans+=(LL)abs(i-A[i]);
	}
	
	cout<<ans<<endl;
}