
import java.util.Scanner;

/**
 *
 * @author Gaurav
 */
public class ChessBoard {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        
        
        int n=sc.nextInt();
        
        int size=n/2;
        
        int ans=0,next=0;
        for(int i=0;i<(size);i++)
        {
            int temp=sc.nextInt();
            if(next==0)
            {
                next=next+temp;
                next=next+2;

            }
            else{
                if(temp!=next)
                {
                    ans=ans+Math.abs(next-temp);
                }
                next=next+2;
            }
            
//            System.out.println("Next is "+next);
//            System.out.println("ANS "+ans);            
        }
        System.out.println(ans);
        
        

    }
}
