using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace dpc
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_dpcA();
			Console.Out.Flush();
        }

        public static void solve_dpcB()
        {
        }

        /*
        https://atcoder.jp/contests/dp/submissions/3937208
        */
        public static void solve_dpcA()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            long[] h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long[] dp = new long[n];
            //Base case for dp[0] is 0.
            //Because we cannot calculate absolute diff for the first element. 
            //To calculate the absolute diff for the first element we should have first - 1 element
            //and first - 2 element. But that would mean that the first element is not the first!
            //So it is 0. Why zero? Well any other value like int.MaxInt or int.MinInt would
            //lead to the wrong calculation of the next elements.
            dp[0] = 0;
            //we start from the second element as we have availabe min value
            //for the base case which is the first element
            for (int i = 1; i < n; i++)
            {
                /*
                The logic is pretty much the same as for the fibonacci numbers.
                How can we get to the i-th element? Well, there are only TWO options.
                Either from i - 1 element or from i - 2 element (this is analysed 
                from the problem statement). Now, we first calculate the absolute
                diff if we came from the i - 1 element. what does it mean?
                Suppose we already have an absolute minium value if we reached i - 1 element.
                We store it in the dp[i - 1]. Right now we are on the dp[i] element.
                Well, then we can calculate the absolute min diff for the current element. How?
                It is Math.Abs(h[i] - h[i - 1]). Now let's create a temporary variable
                to store this value. Let's call it iminus1. Let't set the absolute min diff
                to this variable. Done. But it is wrong?
                Why? Because by the prbolem statement we should accomulate the absolute minimum diff.
                And if we set it like that then we lose the value that we calculated for the i - 1 element.
                How not to lose it? Well, we already have the calculated value for the i - 1. So we should
                just add it to the iminus1. No we have the correct formula:
                iminus1 = dp[i - 1] + Math.Abs(h[i] - h[i - 1])
                */
                long iminus1 = dp[i - 1] + Math.Abs(h[i] - h[i - 1]);
                /*
                What happens here?
                when we reach the third element (index 2) we can now calculate the accumulated absolute
                minimum diff fo the i - 2 element. Why? Because i is already equl to 2 and 2  - 2 by the 
                formula i - 2 is 0. Which is the correct index for the previous previous element.
                */
                long iminus2 = int.MaxValue;
                if (i >= 2)
                {
                    /*
                    What we do here?
                    Well, we already calculated the correct value for the i - 1 element.
                    Now we need to do the same for the i - 2 element.
                    Let's create a temporary variable that will store this value.
                    You see that the difference in the formula is that in the first example it was
                    i - 1 and in the second it is i - 2.
                    */
                    iminus2 = dp[i - 2] + Math.Abs(h[i] - h[i - 2]);
                    /*
                    Finally, what we should do is to choose the minimum between two. 
                    Ok we calculated the absolute
                    minimum difference for i - 1 and i - 2 and we accumulated it for the
                    previousely calculated values for i - 1 and i - 2, let's see
                    where is the minium and pick it for our current element.
                    */
                }
                dp[i] = Math.Min(iminus1, iminus2);
            }
            /*
            The answer will be the last element. Why because we start from bottomw (the base case)
            to top (the last element) and we accomulated the absolute min diff for all possible
            cases which are if you came from the i - 1 element or from the i - 2 element.
            Among them on every step we make the most optimal value according to the problem's statement
            and it accumulates to the last elements in the array.
            */
            Console.WriteLine(dp[n - 1]);
        }
    }
}


Measured memory_bytes: 19808