#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}
inline int myrand() { return abs((rand() << 15) ^ rand()); }
inline int rnd(int x) { return myrand() % x; }
const int maxn = (int)1e6 + 10;
int a[maxn];
long long d[maxn + 1];
pair<long long, int> mx[maxn], mn[maxn];
int cntmx, cntmn;
pair<long long, int> sump[maxn], summ[maxn];
int cntp, cntm;
void addVal(pair<long long, int> *st, int &cnt, long long value, int pos) {
  while (cnt && st[cnt - 1].first <= value) --cnt;
  st[cnt++] = make_pair(value, pos);
}
bool solve() {
  int n;
  if (scanf("%d", &n) < 1) return 0;
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  d[0] = 0;
  cntp = cntm = cntmx = cntmn = 0;
  for (int i = 0; i < n; ++i) {
    addVal(summ, cntm, -a[i] + d[i], i);
    addVal(sump, cntp, a[i] + d[i], i);
    long long &cur = d[i + 1];
    cur = d[i];
    {
      if (i && a[i] > a[i - 1]) {
        int l = -1, r = cntmx;
        while (l + 1 < r) {
          int m = (l + r) / 2;
          if (mx[m].first >= a[i])
            l = m;
          else
            r = m;
        }
        int left = (l == -1) ? 0 : (mx[l].second + 1);
        assert(left <= i);
        l = -1, r = cntm;
        while (l + 1 < r) {
          int m = (l + r) / 2;
          if (summ[m].second >= left)
            r = m;
          else
            l = m;
        }
        assert(r < cntm);
        cur = max(cur, summ[r].first + a[i]);
      }
      if (i && a[i] < a[i - 1]) {
        int l = -1, r = cntmn;
        while (l + 1 < r) {
          int m = (l + r) / 2;
          if (-mn[m].first <= a[i])
            l = m;
          else
            r = m;
        }
        int left = (l == -1) ? 0 : (mn[l].second + 1);
        assert(left <= i);
        l = -1, r = cntp;
        while (l + 1 < r) {
          int m = (l + r) / 2;
          if (sump[m].second >= left)
            r = m;
          else
            l = m;
        }
        assert(r < cntp);
        cur = max(cur, sump[r].first - a[i]);
      }
    }
    addVal(mx, cntmx, a[i], i);
    addVal(mn, cntmn, -a[i], i);
  }
  printf(
      "%lld"
      "\n",
      d[n]);
  return 1;
}
int main() {
  srand(rdtsc());
  while (1) {
    if (!solve()) break;
  }
  return 0;
}
