#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &x, B y) {     return (x > y) ? (x = y, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &x, B y) {     return (x < y) ? (x = y, 1) : 0;   }   template <class Value_t>   class SegmentTree {    public:     typedef struct segment_st {       Value_t value;       int left, right;     } TreeNode;     vector<TreeNode> tree;     int N;     int tree_size;     vector<int> leaves;     SegmentTree(int n) {       vector<Value_t> v(n);       build_tree(n, v);     }     SegmentTree(int n, vector<Value_t> &v) { build_tree(n, v); }     Value_t query(int ll, int rr) { return query(1, ll, rr); }     void update(int at, Value_t val) { internal_update(at, val); }       private:     void build_tree(int n, vector<Value_t> &v) {       N = n;       int base = 1;       while (base < N) base *= 2;       tree_size = base * 2;       leaves.resize(N + 1);       tree = vector<TreeNode>(tree_size);       init(1, 1, n, v);     }     void init(int at, int ll, int rr, vector<Value_t> &v) {       tree[at].left = ll;       tree[at].right = rr;       if (ll == rr) {         tree[at].value = v[ll - 1];         leaves[ll] = at;       } else {         int mid = (tree[at].left + tree[at].right) / 2;         init(at * 2, tree[at].left, mid, v);         init(at * 2 + 1, mid + 1, tree[at].right, v);         update_up(at);       }     }     Value_t initial_value() { return tuple<int, int>(-1, 0); }     Value_t node_to_value(int at) { return tree[at].value; }     void update_up(int at) {       tuple<int, int> left = node_to_value(at * 2);       tuple<int, int> right = node_to_value(at * 2 + 1);       if (get<0>(left) > get<0>(right)) {         tree[at].value = left;       } else {         tree[at].value = right;       }     }     void update_result(Value_t &res, Value_t val) {       if (get<0>(val) > get<0>(res)) {         res = val;       }     }     void update_leaf_value(int at, Value_t val) { tree[at].value = val; }     Value_t query(int at, int ll, int rr) {       if (tree[at].left == ll && tree[at].right == rr) {         return node_to_value(at);       } else {         int mid = (tree[at].left + tree[at].right) / 2;         Value_t res = initial_value();         if (ll <= mid) update_result(res, query(at * 2, ll, min(rr, mid)));         if (rr > mid) update_result(res, query(at * 2 + 1, max(mid + 1, ll), rr));         return res;       }     }     void internal_update(int at, Value_t val) {       at = leaves[at];       update_leaf_value(at, val);       at /= 2;       while (at) {         update_up(at);         at /= 2;       }     }   };   map<int, long long> ans[(100005)];   int in[(100005)];   int N, Q;   SegmentTree<tuple<int, int> > tree(1);   int solve2(int l, int r, int &x, int &y) {     tuple<int, int> a = tree.query(l, r - 1);     x = get<1>(a);     y = x + 1;     return get<0>(a);   }   long long solve(int l, int r) {     if (l >= r) return 0;     if (ans[l].find(r) != ans[l].end()) {       return ans[l][r];     }     int x = 0, y = 0;     long long L = solve2(l, r, x, y);     if (x > y) swap(x, y);     ans[l][r] = L * (x - l + 1) * (r - y + 1) + solve(l, x) + solve(y, r);     return ans[l][r];   }   int main() {     scanf( %d %d , &N, &Q);     for (int(i) = 0; (i) < (N); ++(i)) {       scanf( %d , &in[i]);     }     tree = SegmentTree<tuple<int, int> >(N - 1);     for (int(i) = 0; (i) < (N - 1); ++(i)) {       tree.update(i + 1, tuple<int, int>(abs(in[i + 1] - in[i]), i + 1));     }     int l, r;     for (int(q) = 0; (q) < (Q); ++(q)) {       scanf( %d %d , &l, &r);       printf( %I64d n , solve(l, r));     }     return 0;   }