extension Array where Element: Comparable {
    mutating func select(k: Int) -> Element? {
        var k = k
        var l = 0
        var r = self.count-1
        while l <= r {
            let p = self[(l+r)/2]
            var i = l-1
            var j = r+1
            while true {
                while self[++i] < p {}
                while self[--j] > p {}
                if i >= j {
                    break
                }
                self.swapAt(i, j)
            }
            if k == i-l {
                return self[i]
            } else if k < i-l {
                r = i - 1
            } else if k > i-l {
                k -= (i-l+1)
                l = j + 1
            }
        }
        return nil
    }
}
let N = Int(readLine()!)!
var B = readLine()!.characters.split(" ").enumerate().map{Int(String($0.1))!-$0.0+1}
let b = B.select(N/2)!
print(B.reduce(0){$0+abs($1-b)})