const sum = arr => arr.reduce((prev, current) => { return prev + current; }, 0);

function Main (input) {
  const inputs = input.split(/\s/g).filter((num) => num).map(num => parseInt(num)).slice(1);
  const max = Math.max(...inputs);
  const results = new Array(max + 1).fill('').map((value, selected) => {
    const plus = sum(inputs.map((num, index) => Math.abs(num - (selected + (index + 1)))));
    const minus = sum(inputs.map((num, index) => Math.abs(num - ((-1 * selected) + (index + 1)))));
    return Math.min(plus, minus);
  });
  console.log('%s', Math.min(...results));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
