unittest
{
	assert( [ "5", "2 2 3 5 5" ].parse.expand.solve == 2 );
	assert( [ "9", "1 2 3 4 5 6 7 8 9" ].parse.expand.solve == 0 );
	assert( [ "6", "6 5 4 3 2 1" ].parse.expand.solve == 18 );
	assert( [ "7", "1 1 1 1 2 3 4" ].parse.expand.solve == 6 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	return tuple( as );
}

auto solve( in long[] as )
{
	// bの後ろの 1 .. N を処理
	auto ais = new long[ as.length ];
	foreach( long i, ref ai; ais )
	{
		ai = as[ i ] - ( i + 1 );		// bが右端に行くように式を変形 a[i]-(b+(i+1)) => a[i]-(i+1)-b
	}
	
	// ソートして中央値を取得
	ais.sort();
	auto b = ais[ $ / 2 ];
	
	// 悲しさを計算
	auto s = 0L;
	foreach( ai; ais )
	{
		s += abs( ai - b );
	}
	
	return s;
}
