package main import ( "bufio" "fmt" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var rdr = bufio.NewReaderSize(os.Stdin, 1000000) func main() { sc.Split(bufio.ScanWords) n := nextInt() ns, sum := make([]int, n), 0 for i := range ns { c := nextInt() sum += c ns[i] = c } h := 0 for i := 1; ; i++ { if i*i > sum { h = i - 1 if h*2-1 > len(ns) { h = n/2 + 1 } break } } excess, shortage := 0, 0 // if h > ns[h-1] { // shortage += h - ns[h-1] // } else { // excess += ns[h-1] - h // } for i := 0; i < h-1; i++ { if i+1 > ns[i] { shortage += i + 1 - ns[i] } else { excess += ns[i] - (i + 1) } if h-i-1 > ns[i+h] { shortage += h - i - 1 - ns[i+h] } else { excess += ns[i+h] - (h - i - 1) } } for i := h*2 - 1; i < len(ns); i++ { excess += ns[i] } count := excess - shortage count += shortage fmt.Println(count) } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i }