Program sairsodo;
const MAXN=100000;
type elenco = array[1..MaXN] of int64;
var N,i,d, idmediana, idmediana1, mediana:int64;
calcolacosto,calcolacosto1, altezzainiziale, altezzainiziale1, differenza:int64;
costo, costo1, costomin, ricordacostomin:int64;
H, ricordaltezze: elenco;
uscita, invariato:boolean;
ricordaintervallo:char;
Procedure scambia (var a,b: int64);
var x:int64;
begin
x:=a;
a:=b;
b:=x;
end;
Procedure ordinamento (estremoi,estremos:int64; var v : elenco; ordinato:boolean);
var inf, sup, medio:int64;
pivot :int64;
begin
inf:=estremoi;
sup:=estremos;
medio:= (estremoi+estremos) div 2;
pivot:=v[medio];
repeat
if (ordinato) then
begin
while (v[inf]<pivot) do inf:=inf+1;
while (v[sup]>pivot) do sup:=sup-1;
end;
if inf<=sup then
begin
scambia(v[inf],v[sup]);
inf:=inf+1;
sup:=sup-1;
end;
until inf>sup;
if (estremoi<sup) then ordinamento(estremoi,sup,v,ordinato);
if (inf<estremos) then ordinamento(inf,estremos,v,ordinato);
end;
begin
(*assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);*)
readln(N);
for i:=1 to N do begin read(H[i]); ricordaltezze[i]:=H[i]; end;readln;
costo:=0; d:=0; ricordacostomin:=9223372036854775807; uscita:=false;
ordinamento (1,N,H, true);
invariato:=false; ricordaintervallo:=' ';
if N mod 2 <>0 then
begin
idmediana:=(N+1) div 2;
altezzainiziale:=H[idmediana]-(idmediana-1);
if altezzainiziale<0 then altezzainiziale:=0;
for i:=1 to N do
begin
calcolacosto:=(ricordaltezze[i] - (altezzainiziale +i-1));
if calcolacosto<0 then calcolacosto:=-calcolacosto;
costo:= costo + calcolacosto ;
end;
writeln(costo);
end
else
begin
idmediana:= N div 2;
idmediana1:=idmediana+1;
mediana:= (H[idmediana1]+ H[idmediana1 + 1]) div 2; (*altezza che corrisponde alla mediana*)
altezzainiziale:=mediana-idmediana1;
while altezzainiziale<0 do altezzainiziale:=altezzainiziale+1;
if altezzainiziale<=0 then altezzainiziale:=0;
for i:=1 to N do
begin
calcolacosto:=(ricordaltezze[i] - mediana)+i-1;
if calcolacosto<0 then calcolacosto:=-calcolacosto;
costo:=costo+calcolacosto;
end;
end;
writeln(costo );
end.
UHJvZ3JhbSBzYWlyc29kbzsKY29uc3QgTUFYTj0xMDAwMDA7IAp0eXBlIGVsZW5jbyA9IGFycmF5WzEuLk1hWE5dIG9mIGludDY0Owp2YXIgTixpLGQsIGlkbWVkaWFuYSwgaWRtZWRpYW5hMSwgbWVkaWFuYTppbnQ2NDsKICAgIGNhbGNvbGFjb3N0byxjYWxjb2xhY29zdG8xLCBhbHRlenphaW5pemlhbGUsIGFsdGV6emFpbml6aWFsZTEsIGRpZmZlcmVuemE6aW50NjQ7CiAgICBjb3N0bywgY29zdG8xLCBjb3N0b21pbiwgcmljb3JkYWNvc3RvbWluOmludDY0OwogICAgSCwgcmljb3JkYWx0ZXp6ZTogZWxlbmNvOwogICAgdXNjaXRhLCBpbnZhcmlhdG86Ym9vbGVhbjsKICAgIHJpY29yZGFpbnRlcnZhbGxvOmNoYXI7ClByb2NlZHVyZSBzY2FtYmlhICh2YXIgYSxiOiBpbnQ2NCk7CnZhciB4OmludDY0OwpiZWdpbgogICB4Oj1hOwogICBhOj1iOwogICBiOj14OwplbmQ7ICAKUHJvY2VkdXJlIG9yZGluYW1lbnRvIChlc3RyZW1vaSxlc3RyZW1vczppbnQ2NDsgdmFyIHYgOiBlbGVuY287IG9yZGluYXRvOmJvb2xlYW4pOwp2YXIgaW5mLCBzdXAsIG1lZGlvOmludDY0OwogICAgcGl2b3QgOmludDY0OwpiZWdpbgogICAgaW5mOj1lc3RyZW1vaTsKICAgIHN1cDo9ZXN0cmVtb3M7CiAgICBtZWRpbzo9IChlc3RyZW1vaStlc3RyZW1vcykgZGl2IDI7CiAgICBwaXZvdDo9dlttZWRpb107CiAgICByZXBlYXQKICAgICAgaWYgKG9yZGluYXRvKSB0aGVuCiAgICAgICAgIGJlZ2luCiAgICAgICAgICAgIHd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2lkbWVkaWFuYV0tKGlkbWVkaWFuYS0xKTsKCSAgICAgICAgICAgICAgICAgICBpZiBhbHRlenphaW5pemlhbGU8MCB0aGVuIGFsdGV6emFpbml6aWFsZTo9MDsKCSAgICAgICAgICAgICAgICAgICBmb3IgaTo9MSB0byBOIGRvCgkgICAgICAgICAgICAgICAgICAgICAgICAgYmVnaW4gCgkgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNhbGNvbGFjb3N0bzo9KHJpY29yZGFsdGV6emVbaV0gLSAoYWx0ZXp6YWluaXppYWxlICtpLTEpKTsKCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgY2FsY29sYWNvc3RvPDAgdGhlbiBjYWxjb2xhY29zdG86PS1jYWxjb2xhY29zdG87CgkgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvc3RvOj0gY29zdG8gKyBjYWxjb2xhY29zdG8gOwoJICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKCSAgICAgICAgICAgICAgICAgICAgICB3cml0ZWxuKGNvc3RvKTsKCSAgICAgICAgICAgICAgICBlbmQKCSAgICAgICAgICAgICAgZWxzZSAKCSAgICAgICAgICAgICAgIGJlZ2luCgkgICAgICAgICAgICAgICAgaWRtZWRpYW5hOj0gTiBkaXYgMjsKCSAgICAgICAgICAgICAgICBpZG1lZGlhbmExOj1pZG1lZGlhbmErMTsKCSAgICAgICAgICAgICAgICBtZWRpYW5hOj0gKEhbaWRtZWRpYW5hMV0rIEhbaWRtZWRpYW5hMSArIDFdKSBkaXYgMjsgKCphbHRlenphIGNoZSBjb3JyaXNwb25kZSBhbGxhIG1lZGlhbmEqKQoJICAgICAgICAgICAgICAgIGFsdGV6emFpbml6aWFsZTo9bWVkaWFuYS1pZG1lZGlhbmExOwoJICAgICAgICAgICAgICAgIHdoaWxlIGFsdGV6emFpbml6aWFsZTwwIGRvIGFsdGV6emFpbml6aWFsZTo9YWx0ZXp6YWluaXppYWxlKzE7CgkgICAgICAgICAgICAgICAgaWYgYWx0ZXp6YWluaXppYWxlPD0wIHRoZW4gYWx0ZXp6YWluaXppYWxlOj0wOwoJICAgICAgICAgICAgICAgIAoJICAgICAgICAgICAgICAgIGZvciBpOj0xIHRvIE4gZG8KCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYmVnaW4gCgkgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2FsY29sYWNvc3RvOj0ocmljb3JkYWx0ZXp6ZVtpXSAtIG1lZGlhbmEpK2ktMTsKCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiBjYWxjb2xhY29zdG88MCB0aGVuIGNhbGNvbGFjb3N0bzo9LWNhbGNvbGFjb3N0bzsKCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3N0bzo9Y29zdG8rY2FsY29sYWNvc3RvOwoJICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbmQ7CgkgICAgICAgICAgICAgICAgCgkgICAgICAgICAgICAgICAgICAgICAgICAgCgkgICAgICAgICAgICAgICBlbmQ7IAoJICAgICB3cml0ZWxuKGNvc3RvICk7ICAgICAgICAgIAoJIGVuZC4K