import Foundation
let N=Int(readLine()!)!
var strA=readLine()!.componentsSeparatedByString(" ")
var A=[Int]()
for i in strA{
  A.append(Int(i)!)
}
var b=0
for i in 0..<N{
  b=b+A[i]+i
}
b=b/N
var ans=0
for i in A{
  ans=ans+abs(i-b)
}
print(ans)
