import java.util.Scanner;
public class Main {
  public static void main (String [] args) {
  Scanner sc = new Scanner (System.in);
    int s = sc.nextInt();
    int a [] = new int [s/2];
    for(int i = 0; i < s/2; i++) {
      a[i] = sc.nextInt();
    }
    int c = 0;
    for(int i = 1; i < s/2; i++) {
      
        while (a[i-1]+2 != a[i]){
               c++;
               if(a[i-1]+2 >a[i])a[i]++;
               else a[i]--;
        }
    }
  System.out.println(c);
}
}