In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero). 

The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.

Input

The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106).

The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109).

Output

Print the maximum possible total sociability of all groups.

Examples

Input

5
1 2 3 1 2


Output

3


Input

3
3 3 3


Output

0

Note

In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.

In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.ArrayDeque;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Kindergarten solver = new Kindergarten();
        solver.solve(1, in, out);
        out.close();
    }

    static class Kindergarten {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
//        N = (int)(1e6);
            ArrayDeque<int[]> max = new ArrayDeque<>();
            ArrayDeque<int[]> min = new ArrayDeque<>();
            SegmentTree seg = new SegmentTree(N + 1);
            max.add(new int[]{Integer.MAX_VALUE, 0, 0});
            min.add(new int[]{Integer.MIN_VALUE, 0, 0});
            for (int i = 1; i <= N; i++) {
                int next = in.nextInt();
//            int next = (int)(Math.random() * 100000);
                int l = i;
                while (max.size() > 0 && max.peekLast()[0] <= next) {
                    int[] v = max.removeLast();
                    l = v[1];
                    seg.add(v[1] - 1, v[2] - 1, next - v[0]);
                }
                max.add(new int[]{next, l, i});
                l = i;
                while (min.size() > 0 && min.peekLast()[0] >= next) {
                    int[] v = min.removeLast();
                    l = v[1];
                    seg.add(v[1] - 1, v[2] - 1, v[0] - next);
                }
                min.add(new int[]{next, l, i});
                seg.add(i, i, seg.max[1]);
            }
            out.println(seg.max[1]);
        }

        public class SegmentTree {
            long[] max;
            long[] lzy;
            int size = 0;

            public SegmentTree(int N) {
                size = N;
                max = new long[4 * N];
                lzy = new long[4 * N];
            }

            void push(int n) {
                max[2 * n] += lzy[n];
                max[2 * n + 1] += lzy[n];
                lzy[2 * n] += lzy[n];
                lzy[2 * n + 1] += lzy[n];
                lzy[n] = 0;
            }

            public void add(int l, int r, long val) {
                //change query, not assignment
                addUtil(1, 0, size - 1, l, r, val);
            }

            public void addUtil(int n, int tl, int tr, int l, int r, long val) {
                if (l > tr || tl > r) {
                    return;
                }
                if (l <= tl && tr <= r) {
                    max[n] += val;
                    lzy[n] += val;
                } else {
                    push(n);
                    int tm = (tl + tr) / 2;
                    addUtil(2 * n, tl, tm, l, r, val);
                    addUtil(2 * n + 1, tm + 1, tr, l, r, val);
                    max[n] = Math.max(max[2 * n], max[2 * n + 1]);
                }
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

