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



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

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	foreach( i, ref a; as )
	{
		a -= 1 + i.signed;
	}
	as.sort();
	
	auto ans = 0L;
	auto b = as[ $ / 2 ];
	foreach( ref a; as )
	{
		ans += abs( a - b );
	}
	return ans;
}
